/
add-linting.spec.ts
85 lines (73 loc) · 2.5 KB
/
add-linting.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { ProjectConfiguration, Tree } from '@nrwl/devkit';
import {
addProjectConfiguration,
readJson,
readProjectConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
import * as linter from '@nrwl/linter';
import { addLintingGenerator } from './add-linting';
import * as devkit from '@nrwl/devkit';
describe('addLinting generator', () => {
let tree: Tree;
const appProjectName = 'ng-app1';
const appProjectRoot = `apps/${appProjectName}`;
beforeEach(() => {
tree = createTreeWithEmptyV1Workspace();
addProjectConfiguration(tree, appProjectName, {
root: appProjectRoot,
prefix: 'myOrg',
projectType: 'application',
targets: {},
} as ProjectConfiguration);
});
it('should invoke the lintProjectGenerator', async () => {
jest.spyOn(linter, 'lintProjectGenerator');
await addLintingGenerator(tree, {
prefix: 'myOrg',
projectName: appProjectName,
projectRoot: appProjectRoot,
});
expect(linter.lintProjectGenerator).toHaveBeenCalled();
});
it('should add the Angular specific EsLint devDependencies', async () => {
await addLintingGenerator(tree, {
prefix: 'myOrg',
projectName: appProjectName,
projectRoot: appProjectRoot,
});
const { devDependencies } = readJson(tree, 'package.json');
expect(devDependencies['@angular-eslint/eslint-plugin']).toBeDefined();
expect(
devDependencies['@angular-eslint/eslint-plugin-template']
).toBeDefined();
expect(devDependencies['@angular-eslint/template-parser']).toBeDefined();
});
it('should correctly generate the .eslintrc.json file', async () => {
await addLintingGenerator(tree, {
prefix: 'myOrg',
projectName: appProjectName,
projectRoot: appProjectRoot,
});
const eslintConfig = readJson(tree, `${appProjectRoot}/.eslintrc.json`);
expect(eslintConfig).toMatchSnapshot();
});
it('should update the project with the right lint target configuration', async () => {
await addLintingGenerator(tree, {
prefix: 'myOrg',
projectName: appProjectName,
projectRoot: appProjectRoot,
});
const project = readProjectConfiguration(tree, appProjectName);
expect(project.targets.lint).toEqual({
executor: '@nrwl/linter:eslint',
options: {
lintFilePatterns: [
`${appProjectRoot}/**/*.ts`,
`${appProjectRoot}/**/*.html`,
],
},
outputs: ['{options.outputFile}'],
});
});
});