-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgenerator-init.e2e.test.ts
More file actions
149 lines (133 loc) · 4.21 KB
/
generator-init.e2e.test.ts
File metadata and controls
149 lines (133 loc) · 4.21 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import type { Tree } from '@nx/devkit';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import {
generateWorkspaceAndProject,
materializeTree,
nxTargetProject,
} from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
removeColorCodes,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';
describe('nx-plugin g init', () => {
let tree: Tree;
const project = 'my-lib';
const testFileDir = path.join(
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
'generators-init',
);
beforeEach(async () => {
tree = await generateWorkspaceAndProject(project);
});
afterEach(async () => {
await teardownTestFolder(testFileDir);
});
it('should inform about dry run when used on init generator', async () => {
const cwd = path.join(testFileDir, 'dry-run');
await materializeTree(tree, cwd);
const { stderr } = await executeProcess({
command: 'npx',
args: ['nx', 'g', '@code-pushup/nx-plugin:init', project, '--dryRun'],
cwd,
});
const cleanedStderr = removeColorCodes(stderr);
expect(cleanedStderr).toContain(
'NOTE: The "dryRun" flag means no changes were made.',
);
});
it('should update packages.json and configure nx.json', async () => {
const cwd = path.join(testFileDir, 'nx-update');
await materializeTree(tree, cwd);
const { code, stdout } = await executeProcess({
command: 'npx',
args: [
'nx',
'g',
'@code-pushup/nx-plugin:init',
project,
'--skipInstall',
],
cwd,
});
expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
'NX Generating @code-pushup/nx-plugin:init',
);
expect(cleanedStdout).toMatch(/^UPDATE package.json/m);
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);
const packageJson = await readFile(path.join(cwd, 'package.json'), 'utf8');
const nxJson = await readFile(path.join(cwd, 'nx.json'), 'utf8');
expect(JSON.parse(packageJson)).toStrictEqual(
expect.objectContaining({
devDependencies: expect.objectContaining({
'@code-pushup/cli': expect.any(String),
'@code-pushup/models': expect.any(String),
'@code-pushup/nx-plugin': expect.any(String),
'@code-pushup/utils': expect.any(String),
}),
}),
);
expect(JSON.parse(nxJson)).toStrictEqual(
expect.objectContaining({
targetDefaults: expect.objectContaining({
'code-pushup': {
cache: true,
inputs: ['default', '^production'],
},
}),
}),
);
});
it('should skip packages.json update if --skipPackageJson is given', async () => {
const cwd = path.join(testFileDir, 'skip-packages');
await materializeTree(tree, cwd);
const { code, stdout } = await executeProcess({
command: 'npx',
args: [
'nx',
'g',
'@code-pushup/nx-plugin:init',
project,
'--skipInstall',
'--skipPackageJson',
],
cwd,
});
expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
'NX Generating @code-pushup/nx-plugin:init',
);
expect(cleanedStdout).not.toMatch(/^UPDATE package.json/m);
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);
const packageJson = await readFile(path.join(cwd, 'package.json'), 'utf8');
const nxJson = await readFile(path.join(cwd, 'nx.json'), 'utf8');
expect(JSON.parse(packageJson)).toStrictEqual(
expect.objectContaining({
devDependencies: expect.not.objectContaining({
'@code-pushup/cli': expect.any(String),
'@code-pushup/models': expect.any(String),
'@code-pushup/nx-plugin': expect.any(String),
'@code-pushup/utils': expect.any(String),
}),
}),
);
expect(JSON.parse(nxJson)).toStrictEqual(
expect.objectContaining({
targetDefaults: expect.objectContaining({
'code-pushup': {
cache: true,
inputs: ['default', '^production'],
},
}),
}),
);
});
});