Skip to content

Commit 4efdc34

Browse files
committed
feat(core): Add critial e2e tests file
fix(react): add missing testing dependency for libraries update
1 parent 7db44a8 commit 4efdc34

25 files changed

+1930
-967
lines changed
+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* GOLDEN TEST SUITE — CRITICAL HEALTH CHECK
3+
*
4+
* This file contains the “essential” (aka golden) tests for the
5+
* angular package. It tests the core public API.
6+
*
7+
* FAILURE POLICY
8+
* - If any test here fails, the package is considered broken.
9+
* - Fix the underlying issue immediately, do not merge or release until green.
10+
* - Do not update snapshots here without an accompanying, intentional code change.
11+
*
12+
* GUIDELINES
13+
* - Keep tests small and focused on fundamental behavior.
14+
* - No edge-cases we should only test the critical paths.
15+
* - CI pipelines must block on failures in this file (no skips or timeouts).
16+
*
17+
* MAINTENANCE
18+
* - Whenever you change core behavior, update this file first to cover the new expectations.
19+
* - Add new “essential” tests here only if they test core functionality.
20+
* ──────────────────────────────────────────────────────────────────────────────
21+
*/
22+
import {
23+
checkFilesExist,
24+
cleanupProject,
25+
newProject,
26+
readFile,
27+
runCLI,
28+
uniq,
29+
updateFile,
30+
} from '@nx/e2e/utils';
31+
import { join } from 'node:path';
32+
33+
describe('Angular essential tests', () => {
34+
beforeAll(() => {
35+
newProject({ packages: ['@nx/angular', '@nx/eslint', '@nx/jest'] });
36+
});
37+
38+
afterAll(() => cleanupProject());
39+
40+
describe('Webpack', () => {
41+
it('should be able to generate, build, test and lint an application', async () => {
42+
const appName = uniq('app');
43+
44+
runCLI(
45+
`generate @nx/angular:app apps/${appName} --linter=eslint --bundler=webpack`
46+
);
47+
48+
checkFilesExist(`apps/${appName}/src/app/app.component.ts`);
49+
checkFilesExist(`apps/${appName}/src/app/app.config.ts`);
50+
51+
const buildResult = runCLI(`build ${appName}`);
52+
const lintResult = runCLI(`lint ${appName}`);
53+
const testResult = runCLI(`test ${appName}`);
54+
55+
expect(buildResult).toContain(
56+
`Successfully ran target build for project ${appName}`
57+
);
58+
expect(testResult).toContain(
59+
`Successfully ran target test for project ${appName}`
60+
);
61+
expect(lintResult).toContain(
62+
`Successfully ran target lint for project ${appName}`
63+
);
64+
}, 200_000);
65+
});
66+
67+
describe('Rspack', () => {
68+
it('should be able to generate, build, test and lint an application', async () => {
69+
const appName = uniq('app');
70+
71+
runCLI(
72+
`generate @nx/angular:app apps/${appName} --linter=eslint --bundler=rspack`
73+
);
74+
75+
const rspackConfigFileContents = readFile(
76+
join('apps', appName, 'rspack.config.ts')
77+
);
78+
const updatedConfigFileContents = rspackConfigFileContents.replace(
79+
`maximumError: '1mb'`,
80+
`maximumError: '3mb'`
81+
);
82+
updateFile(
83+
join('apps', appName, 'rspack.config.ts'),
84+
updatedConfigFileContents
85+
);
86+
87+
checkFilesExist(`apps/${appName}/src/app/app.component.ts`);
88+
checkFilesExist(`apps/${appName}/src/app/app.config.ts`);
89+
checkFilesExist(`apps/${appName}/rspack.config.ts`);
90+
91+
const buildResult = runCLI(`build ${appName}`);
92+
const lintResult = runCLI(`lint ${appName}`);
93+
const testResult = runCLI(`test ${appName}`);
94+
95+
expect(buildResult).toContain(
96+
`Successfully ran target build for project ${appName}`
97+
);
98+
expect(testResult).toContain(
99+
`Successfully ran target test for project ${appName}`
100+
);
101+
expect(lintResult).toContain(
102+
`Successfully ran target lint for project ${appName}`
103+
);
104+
}, 200_000);
105+
});
106+
107+
describe('Esbuild (default)', () => {
108+
it('should be able to generate, build, test and lint an application', async () => {
109+
const appName = uniq('app');
110+
111+
runCLI(`generate @nx/angular:app apps/${appName} --linter=eslint`);
112+
113+
checkFilesExist(`apps/${appName}/src/app/app.component.ts`);
114+
checkFilesExist(`apps/${appName}/src/app/app.config.ts`);
115+
116+
const buildResult = runCLI(`build ${appName}`);
117+
const lintResult = runCLI(`lint ${appName}`);
118+
const testResult = runCLI(`test ${appName}`);
119+
120+
expect(buildResult).toContain(
121+
`Successfully ran target build for project ${appName}`
122+
);
123+
expect(testResult).toContain(
124+
`Successfully ran target test for project ${appName}`
125+
);
126+
expect(lintResult).toContain(
127+
`Successfully ran target lint for project ${appName}`
128+
);
129+
}, 200_000);
130+
131+
it('should be able to generate, build, test and lint a library', async () => {
132+
const libName = uniq('lib');
133+
134+
runCLI(
135+
`generate @nx/angular:lib libs/${libName} --linter=eslint --buildable=true`
136+
);
137+
138+
checkFilesExist(`libs/${libName}/src/index.ts`);
139+
checkFilesExist(
140+
`libs/${libName}/src/lib/${libName}/${libName}.component.ts`
141+
);
142+
143+
const buildResult = runCLI(`build ${libName}`);
144+
const lintResult = runCLI(`lint ${libName}`);
145+
const testResult = runCLI(`test ${libName}`);
146+
147+
expect(buildResult).toContain(
148+
`Successfully ran target build for project ${libName}`
149+
);
150+
expect(testResult).toContain(
151+
`Successfully ran target test for project ${libName}`
152+
);
153+
expect(lintResult).toContain(
154+
`Successfully ran target lint for project ${libName}`
155+
);
156+
}, 200_000);
157+
});
158+
});
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* GOLDEN TEST SUITE — CRITICAL HEALTH CHECK
3+
*
4+
* This file contains the “essential” (aka golden) tests for the
5+
* cypress package. It tests the core public API.
6+
*
7+
* FAILURE POLICY
8+
* - If any test here fails, the package is considered broken.
9+
* - Fix the underlying issue immediately, do not merge or release until green.
10+
* - Do not update snapshots here without an accompanying, intentional code change.
11+
*
12+
* GUIDELINES
13+
* - Keep tests small and focused on fundamental behavior.
14+
* - No edge-cases we should only test the critical paths.
15+
* - CI pipelines must block on failures in this file (no skips or timeouts).
16+
*
17+
* MAINTENANCE
18+
* - Whenever you change core behavior, update this file first to cover the new expectations.
19+
* - Add new “essential” tests here only if they test core functionality.
20+
* ──────────────────────────────────────────────────────────────────────────────
21+
*/
22+
23+
import {
24+
checkFilesExist,
25+
cleanupProject,
26+
newProject,
27+
runCLI,
28+
runE2ETests,
29+
uniq,
30+
} from '@nx/e2e/utils';
31+
32+
describe('Cypress essential tests', () => {
33+
beforeAll(() => {
34+
newProject({ packages: ['@nx/react', '@nx/angular', '@nx/cypress'] });
35+
});
36+
37+
afterAll(() => cleanupProject());
38+
39+
describe('React', () => {
40+
const myapp = uniq('myapp');
41+
it('should generate and run a react app with the Cypress as e2e test runner', () => {
42+
runCLI(
43+
`generate @nx/react:app apps/${myapp} --e2eTestRunner=cypress --linter=none`
44+
);
45+
46+
// Making sure the cypress folders & files are created
47+
checkFilesExist(`apps/${myapp}-e2e/cypress.config.ts`);
48+
checkFilesExist(`apps/${myapp}-e2e/tsconfig.json`);
49+
50+
checkFilesExist(`apps/${myapp}-e2e/src/fixtures/example.json`);
51+
checkFilesExist(`apps/${myapp}-e2e/src/e2e/app.cy.ts`);
52+
checkFilesExist(`apps/${myapp}-e2e/src/support/app.po.ts`);
53+
checkFilesExist(`apps/${myapp}-e2e/src/support/e2e.ts`);
54+
checkFilesExist(`apps/${myapp}-e2e/src/support/commands.ts`);
55+
56+
if (runE2ETests('cypress')) {
57+
const result = runCLI(`e2e ${myapp}-e2e`);
58+
expect(result).toContain('All specs passed!');
59+
}
60+
}, 600_000);
61+
});
62+
63+
describe('Angular', () => {
64+
const myapp = uniq('myapp');
65+
it('should generate and run an angular app with the Cypress as e2e test runner', () => {
66+
runCLI(
67+
`generate @nx/angular:app apps/${myapp} --e2eTestRunner=cypress --linter=none`
68+
);
69+
70+
// Making sure the cypress folders & files are created
71+
checkFilesExist(`apps/${myapp}-e2e/cypress.config.ts`);
72+
checkFilesExist(`apps/${myapp}-e2e/tsconfig.json`);
73+
74+
checkFilesExist(`apps/${myapp}-e2e/src/fixtures/example.json`);
75+
checkFilesExist(`apps/${myapp}-e2e/src/e2e/app.cy.ts`);
76+
checkFilesExist(`apps/${myapp}-e2e/src/support/app.po.ts`);
77+
checkFilesExist(`apps/${myapp}-e2e/src/support/e2e.ts`);
78+
checkFilesExist(`apps/${myapp}-e2e/src/support/commands.ts`);
79+
80+
if (runE2ETests('cypress')) {
81+
const result = runCLI(`e2e ${myapp}-e2e`);
82+
expect(result).toContain('All specs passed!');
83+
}
84+
}, 600_000);
85+
});
86+
});

0 commit comments

Comments
 (0)