color-cleaner
Version:
A CLI tool to clean and consolidate colors in your project files.
82 lines (72 loc) • 2.85 kB
JavaScript
import { expect } from 'chai';
import { getColorLines } from '../lib/colorExtractorService.js';
describe('Color Extractor Service', () => {
const mockFiles = [
{
path: 'test.css',
content: `
.valid-color { color:
.invalid-color { color: notacolor; }
.rgb-color { background: rgb(0, 255, 0); }
.rgba-color { border: 1px solid rgba(0, 0, 255, 0.5); }
`
},
{
path: 'test.js',
content: `
const color = '#00ff00';
const invalid = 'notacolor';
`
},
{
path: 'test.txt',
content: 'This file should be ignored'
}
];
const defaultConfig = {
framework: 'Angular',
version: '19',
skipNodeModules: true,
thresholdSensitivity: 7,
fileTypes: ['.css', '.scss', '.js', '.ts', '.html']
};
it('should extract valid colors from files', async () => {
const result = await getColorLines(mockFiles, defaultConfig);
expect(result).to.be.an('array');
expect(result.length).to.be.greaterThan(0);
const colors = result.map(r => r.color);
expect(colors).to.include('#ff0000');
expect(colors).to.include('#00ff00');
expect(colors).to.include('rgb(0, 255, 0)');
expect(colors).to.include('rgba(0, 0, 255, 0.5)');
});
it('should not extract invalid colors', async () => {
const result = await getColorLines(mockFiles, defaultConfig);
const colors = result.map(r => r.color);
expect(colors).to.not.include('notacolor');
});
it('should ignore files with unsupported extensions', async () => {
const result = await getColorLines(mockFiles, defaultConfig);
const filePaths = [...new Set(result.map(r => r.currentPath))];
expect(filePaths).to.not.include('test.txt');
});
it('should include line numbers in the result', async () => {
const result = await getColorLines(mockFiles, defaultConfig);
expect(result[0]).to.have.property('lineNumber');
expect(result[0].lineNumber).to.be.a('number');
});
it('should handle empty files array', async () => {
const result = await getColorLines([], defaultConfig);
expect(result).to.be.an('array');
expect(result).to.have.lengthOf(0);
});
it('should respect custom file types configuration', async () => {
const customConfig = {
...defaultConfig,
fileTypes: ['.css']
};
const result = await getColorLines(mockFiles, customConfig);
const filePaths = [...new Set(result.map(r => r.currentPath))];
expect(filePaths).to.not.include('test.js');
});
});