-
-
Notifications
You must be signed in to change notification settings - Fork 930
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
--ext
CLI flag and extensions
Node.js API option
- Loading branch information
Showing
20 changed files
with
189 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,133 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const { existsSync } = require('fs'); | ||
const standalone = require('../standalone'); | ||
const fixturesPath = path.join(__dirname, 'fixtures'); | ||
|
||
it('extensions array', async () => { | ||
const inputFiles = [ | ||
path.join(fixturesPath, 'no-empty-source.html'), | ||
path.join(fixturesPath, 'extensions'), | ||
]; | ||
const { results } = await standalone({ | ||
files: inputFiles, | ||
customSyntax: 'postcss-scss', | ||
extensions: ['css', 'scss'], | ||
config: { | ||
rules: { 'color-named': 'never' }, | ||
}, | ||
}); | ||
|
||
expect(results).toHaveLength(3); | ||
expect(results[0].source.endsWith('no-empty-source.html')).toBe(true); | ||
expect(results[1].source.endsWith(path.join('extensions', 'bar.scss'))).toBe(true); | ||
expect(results[2].source.endsWith(path.join('extensions', 'folder', 'qux.css'))).toBe(true); | ||
const safeChdir = require('../testUtils/safeChdir'); | ||
const fixturePath = require('../testUtils/fixturePath'); | ||
const configColorNamed = require('./fixtures/config-color-named.json'); | ||
|
||
const fixture = fixturePath.bind(null, __dirname); | ||
const cwd = fixture('extensions'); | ||
|
||
describe('extensions', () => { | ||
test('array', async () => { | ||
const inputFiles = [fixture('no-empty-source.html'), cwd]; | ||
const { results } = await standalone({ | ||
files: inputFiles, | ||
customSyntax: 'postcss-scss', | ||
extensions: ['css', 'scss'], | ||
config: { | ||
rules: { 'color-named': 'never' }, | ||
}, | ||
}); | ||
|
||
expect(results).toHaveLength(3); | ||
expect(existsSync(fixture('extensions', 'foo.json'))).toBe(true); | ||
expect(results[0].source).toBe(fixture('no-empty-source.html')); | ||
expect(results[1].source).toBe(fixture('extensions', 'bar.scss')); | ||
expect(results[2].source).toBe(fixture('extensions', 'folder', 'qux.css')); | ||
}); | ||
|
||
test('default', async () => { | ||
const { results } = await standalone({ | ||
files: [cwd], | ||
config: { rules: { 'color-named': 'never' } }, | ||
}); | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].source).toBe(fixture('extensions', 'folder', 'qux.css')); | ||
}); | ||
|
||
test('dot prefix', async () => { | ||
const { results } = await standalone({ | ||
files: [cwd], | ||
config: { rules: { 'color-named': 'never' } }, | ||
extensions: ['.scss'], | ||
customSyntax: 'postcss-scss', | ||
}); | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].source).toContain('bar.scss'); | ||
}); | ||
|
||
test('no match', () => { | ||
return expect( | ||
standalone({ | ||
files: [cwd], | ||
config: configColorNamed, | ||
extensions: ['js'], | ||
cwd, | ||
}), | ||
).rejects.toThrow('All input files were ignored'); | ||
}); | ||
}); | ||
|
||
it('extensions default', async () => { | ||
const { results } = await standalone({ | ||
files: [path.join(fixturesPath, 'extensions')], | ||
config: { rules: { 'color-named': 'never' } }, | ||
describe('inputs', () => { | ||
safeChdir(cwd); | ||
|
||
test('.', async () => { | ||
const { results } = await standalone({ | ||
files: ['.'], | ||
config: configColorNamed, | ||
extensions: ['css', 'scss'], | ||
customSyntax: 'postcss-scss', | ||
cwd, | ||
}); | ||
|
||
expect(results).toHaveLength(2); | ||
expect(existsSync('foo.json')).toBe(true); | ||
expect(existsSync('folder/baz.json')).toBe(true); | ||
expect(results[0].source).toContain('bar.scss'); | ||
expect(results[1].source).toContain(path.normalize('folder/qux.css')); | ||
}); | ||
|
||
test('false positive', async () => { | ||
const inputFiles = [cwd, fixture('config-color-named.json')]; | ||
const { results } = await standalone({ | ||
files: inputFiles, | ||
config: configColorNamed, | ||
extensions: ['css', 'scss'], | ||
customSyntax: 'postcss-scss', | ||
cwd, | ||
}); | ||
|
||
expect(results).toHaveLength(3); | ||
expect(results[0].source).toContain('bar.scss'); | ||
expect(results[1].source).toContain(path.normalize('folder/qux.css')); | ||
expect(results[2].source).toContain(path.normalize('fixtures/config-color-named.json')); | ||
}); | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].source.endsWith(path.join('extensions', 'folder', 'qux.css'))).toBe(true); | ||
test('common prefix', async () => { | ||
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
const inputFiles = [path.join(cwd, 'folder'), path.join(cwd, 'folder-slash', 'file.json')]; | ||
const { results } = await standalone({ | ||
files: inputFiles, | ||
config: configColorNamed, | ||
extensions: ['css'], | ||
cwd, | ||
}); | ||
|
||
expect(results).toHaveLength(2); | ||
expect(results[0].source).toContain(path.normalize('folder/qux.css')); | ||
expect(results[1].source).toContain(path.normalize('folder-slash/file.json')); | ||
warn.mockRestore(); | ||
}); | ||
|
||
test('**', async () => { | ||
const { results } = await standalone({ | ||
files: ['**'], | ||
config: configColorNamed, | ||
extensions: ['css', 'scss'], | ||
customSyntax: 'postcss-scss', | ||
cwd, | ||
}); | ||
|
||
expect(results).toHaveLength(5); | ||
expect(results[0].source).toContain('bar.scss'); | ||
expect(results[1].source).toContain('foo.json'); | ||
expect(results[2].source).toContain(path.normalize('folder/baz.json')); | ||
expect(results[3].source).toContain(path.normalize('folder/qux.css')); | ||
expect(results[4].source).toContain(path.normalize('folder-slash/file.json')); | ||
}); | ||
}); |
Oops, something went wrong.