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