|
| 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 | +}); |
0 commit comments