77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import {
|
|
baseEsLintConfigFile,
|
|
eslintConfigFileWhitelist,
|
|
findEslintFile,
|
|
lintConfigHasOverride,
|
|
} from './eslint-file';
|
|
|
|
import { Tree } from '@nx/devkit';
|
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
|
|
describe('@nx/linter:eslint-file', () => {
|
|
let tree: Tree;
|
|
|
|
beforeEach(() => {
|
|
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
});
|
|
|
|
describe('findEslintFile', () => {
|
|
it('should return null when calling findEslintFile when no eslint is found', () => {
|
|
expect(findEslintFile(tree)).toBe(null);
|
|
});
|
|
|
|
test.each(eslintConfigFileWhitelist)(
|
|
'should return %p when calling findEslintFile',
|
|
(eslintFileName) => {
|
|
tree.write(eslintFileName, '{}');
|
|
expect(findEslintFile(tree)).toBe(eslintFileName);
|
|
}
|
|
);
|
|
|
|
test.each(eslintConfigFileWhitelist)(
|
|
'should return base file instead %p when calling findEslintFile',
|
|
(eslintFileName) => {
|
|
tree.write(baseEsLintConfigFile, '{}');
|
|
tree.write(eslintFileName, '{}');
|
|
expect(findEslintFile(tree)).toBe(baseEsLintConfigFile);
|
|
}
|
|
);
|
|
});
|
|
|
|
describe('lintConfigHasOverride', () => {
|
|
it('should return true when override exists in eslintrc format', () => {
|
|
tree.write(
|
|
'.eslintrc.json',
|
|
'{"overrides": [{ "files": ["*.ts"], "rules": {} }]}'
|
|
);
|
|
expect(
|
|
lintConfigHasOverride(
|
|
tree,
|
|
'.',
|
|
(o) => {
|
|
return o.files?.includes('*.ts');
|
|
},
|
|
false
|
|
)
|
|
).toBe(true);
|
|
});
|
|
|
|
it('should return false when eslintrc is not in JSON format', () => {
|
|
tree.write(
|
|
'.eslintrc.js',
|
|
'module.exports = {overrides: [{ files: ["*.ts"], rules: {} }]};'
|
|
);
|
|
expect(
|
|
lintConfigHasOverride(
|
|
tree,
|
|
'.',
|
|
(o) => {
|
|
return o.files?.includes('*.ts');
|
|
},
|
|
false
|
|
)
|
|
).toBe(false);
|
|
});
|
|
});
|
|
});
|