fix tests

This commit is contained in:
Joe Danziger
2025-05-11 14:06:03 -04:00
parent a9fdfc3458
commit a401412562

View File

@@ -6,7 +6,10 @@ import { spawnSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import * as windsurfProfile from '../../scripts/profiles/windsurf.js';
import { convertAllRulesToBrandRules, removeBrandRules } from '../../scripts/modules/rule-transformer.js';
import {
convertAllRulesToBrandRules,
removeBrandRules
} from '../../scripts/modules/rule-transformer.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
@@ -27,7 +30,10 @@ function setupCursorRules() {
if (!fs.existsSync(testProfilesDir)) {
fs.mkdirSync(testProfilesDir, { recursive: true });
}
const realProfilePath = path.join(__dirname, '../../scripts/profiles/windsurf.js');
const realProfilePath = path.join(
__dirname,
'../../scripts/profiles/windsurf.js'
);
const testProfilePath = path.join(testProfilesDir, 'windsurf.js');
fs.copyFileSync(realProfilePath, testProfilePath);
}
@@ -47,7 +53,11 @@ describe('rules CLI command', () => {
// Act
const result = convertAllRulesToBrandRules(projectDir, windsurfProfile);
// Assert
const brandRulePath = path.join(projectDir, windsurfProfile.rulesDir, 'sample-rule.mdc');
const brandRulePath = path.join(
projectDir,
windsurfProfile.rulesDir,
'sample-rule.mdc'
);
expect(result.success).toBeGreaterThan(0);
expect(fs.existsSync(brandRulePath)).toBe(true);
const content = fs.readFileSync(brandRulePath, 'utf8');
@@ -58,8 +68,10 @@ describe('rules CLI command', () => {
it('should remove windsurf brand rules', () => {
convertAllRulesToBrandRules(projectDir, windsurfProfile);
const removed = removeBrandRules(projectDir, windsurfProfile);
expect(removed).toBe(true);
expect(fs.existsSync(path.join(projectDir, windsurfProfile.rulesDir))).toBe(false);
expect(removed && removed.success).toBe(true);
expect(
fs.existsSync(path.join(projectDir, windsurfProfile.rulesDir))
).toBe(false);
});
});
@@ -69,30 +81,43 @@ describe('rules CLI command', () => {
it('should add windsurf rules via CLI', () => {
const result = spawnSync('node', [cliPath, 'rules', 'add', 'windsurf'], {
cwd: projectDir,
encoding: 'utf8',
encoding: 'utf8'
});
console.log('CLI STDOUT:', result.stdout);
console.log('CLI STDERR:', result.stderr);
expect(result.status).toBe(0);
const brandRulePath = path.join(projectDir, windsurfProfile.rulesDir, 'sample-rule.mdc');
const brandRulePath = path.join(
projectDir,
windsurfProfile.rulesDir,
'sample-rule.mdc'
);
expect(fs.existsSync(brandRulePath)).toBe(true);
});
it('should remove windsurf rules via CLI', () => {
// First add, then remove
spawnSync('node', [cliPath, 'rules', 'add', 'windsurf'], { cwd: projectDir, encoding: 'utf8' });
const result = spawnSync('node', [cliPath, 'rules', 'remove', 'windsurf'], {
spawnSync('node', [cliPath, 'rules', 'add', 'windsurf'], {
cwd: projectDir,
encoding: 'utf8',
encoding: 'utf8'
});
const result = spawnSync(
'node',
[cliPath, 'rules', 'remove', 'windsurf'],
{
cwd: projectDir,
encoding: 'utf8'
}
);
expect(result.status).toBe(0);
expect(fs.existsSync(path.join(projectDir, windsurfProfile.rulesDir))).toBe(false);
expect(
fs.existsSync(path.join(projectDir, windsurfProfile.rulesDir))
).toBe(false);
});
it('should error if brand is missing', () => {
const result = spawnSync('node', [cliPath, 'rules', 'add'], {
cwd: projectDir,
encoding: 'utf8',
encoding: 'utf8'
});
expect(result.status).not.toBe(0);
expect(result.stderr).toContain('Please specify at least one brand');