diff --git a/tests/legacy-cli/e2e/tests/basic/aot.ts b/tests/legacy-cli/e2e/tests/basic/aot.ts index ad77a0e78999..786111d3bbfc 100644 --- a/tests/legacy-cli/e2e/tests/basic/aot.ts +++ b/tests/legacy-cli/e2e/tests/basic/aot.ts @@ -3,8 +3,5 @@ import { ng } from '../../utils/process'; export default async function () { await ng('build', '--aot=true', '--configuration=development'); - await expectFileToMatch( - 'dist/test-project/main.js', - /platformBrowser.*bootstrapModule.*AppModule/, - ); + await expectFileToMatch('dist/test-project/main.js', 'AppComponent_Factory'); } diff --git a/tests/legacy-cli/e2e/tests/basic/rebuild.ts b/tests/legacy-cli/e2e/tests/basic/rebuild.ts index 36c182817f17..e3bc9ec2384a 100644 --- a/tests/legacy-cli/e2e/tests/basic/rebuild.ts +++ b/tests/legacy-cli/e2e/tests/basic/rebuild.ts @@ -1,17 +1,17 @@ import fetch from 'node-fetch'; import { getGlobalVariable } from '../../utils/env'; -import { writeFile, writeMultipleFiles } from '../../utils/fs'; +import { appendToFile, replaceInFile, writeMultipleFiles } from '../../utils/fs'; import { silentNg, waitForAnyProcessOutputToMatch } from '../../utils/process'; import { ngServe } from '../../utils/project'; export default async function () { const esbuild = getGlobalVariable('argv')['esbuild']; const validBundleRegEx = esbuild ? /complete\./ : /Compiled successfully\./; - const lazyBundleRegEx = esbuild ? /chunk-/ : /lazy_module_ts\.js/; + const lazyBundleRegEx = esbuild ? /chunk-/ : /src_app_lazy_lazy_component_ts\.js/; const port = await ngServe(); - // Add a lazy module. - await silentNg('generate', 'module', 'lazy', '--routing'); + // Add a lazy route. + await silentNg('generate', 'component', 'lazy'); // Should trigger a rebuild with a new bundle. // We need to use Promise.all to ensure we are waiting for the rebuild just before we write @@ -20,98 +20,40 @@ export default async function () { // Verify that a new chunk was created. await Promise.all([ waitForAnyProcessOutputToMatch(lazyBundleRegEx), - writeFile( - 'src/app/app.module.ts', - ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { FormsModule } from '@angular/forms'; - import { HttpClientModule } from '@angular/common/http'; - - import { AppComponent } from './app.component'; - import { RouterModule } from '@angular/router'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - FormsModule, - HttpClientModule, - RouterModule.forRoot([ - { path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) } - ]) - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - `, + replaceInFile( + 'src/app/app.routes.ts', + 'routes: Routes = [];', + `routes: Routes = [{path: 'lazy', loadComponent: () => import('./lazy/lazy.component').then(c => c.LazyComponent)}];`, ), ]); // Change multiple files and check that all of them are invalidated and recompiled. await Promise.all([ waitForAnyProcessOutputToMatch(validBundleRegEx), - writeMultipleFiles({ - 'src/app/app.module.ts': ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { RouterModule } from '@angular/router'; - - import { AppComponent } from './app.component'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - RouterModule, - BrowserModule - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - + appendToFile( + 'src/app/app.routes.ts', + ` console.log('$$_E2E_GOLDEN_VALUE_1'); export let X = '$$_E2E_GOLDEN_VALUE_2'; - `, - 'src/main.ts': ` - import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - import { AppModule } from './app/app.module'; - - platformBrowserDynamic().bootstrapModule(AppModule); - - import * as m from './app/app.module'; + `, + ), + appendToFile( + 'src/main.ts', + ` + import * as m from './app/app.routes'; console.log(m.X); console.log('$$_E2E_GOLDEN_VALUE_3'); `, - }), + ), ]); await Promise.all([ waitForAnyProcessOutputToMatch(validBundleRegEx), writeMultipleFiles({ - 'src/app/app.module.ts': ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { RouterModule } from '@angular/router'; - import { AppComponent } from './app.component'; + 'src/app/app.routes.ts': ` + import { Routes } from '@angular/router'; - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - RouterModule, - BrowserModule - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } + export const routes: Routes = []; console.log('$$_E2E_GOLDEN_VALUE_1'); export let X = '$$_E2E_GOLDEN_VALUE_2'; diff --git a/tests/legacy-cli/e2e/tests/build/app-shell/app-shell-standalone.ts b/tests/legacy-cli/e2e/tests/build/app-shell/app-shell-ngmodule.ts similarity index 91% rename from tests/legacy-cli/e2e/tests/build/app-shell/app-shell-standalone.ts rename to tests/legacy-cli/e2e/tests/build/app-shell/app-shell-ngmodule.ts index bcd66d828508..ac1887cc9207 100644 --- a/tests/legacy-cli/e2e/tests/build/app-shell/app-shell-standalone.ts +++ b/tests/legacy-cli/e2e/tests/build/app-shell/app-shell-ngmodule.ts @@ -7,7 +7,7 @@ import { updateJsonFile } from '../../../utils/project'; const snapshots = require('../../../ng-snapshot/package.json'); export default async function () { - await ng('generate', 'app', 'test-project-two', '--routing', '--standalone', '--skip-install'); + await ng('generate', 'app', 'test-project-two', '--routing', '--no-standalone', '--skip-install'); const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; @@ -26,11 +26,7 @@ export default async function () { ...build.configurations.development, vendorChunk: true, namedChunks: true, - buildOptimizer: false, }; - } else { - // TODO(alanagius): enable once esbuild supports standalone route extraction. - build.configurations.production.prerender = false; } }); diff --git a/tests/legacy-cli/e2e/tests/build/barrel-file.ts b/tests/legacy-cli/e2e/tests/build/barrel-file.ts deleted file mode 100644 index a06302dbe696..000000000000 --- a/tests/legacy-cli/e2e/tests/build/barrel-file.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { replaceInFile, writeFile } from '../../utils/fs'; -import { ng } from '../../utils/process'; - -export default async function () { - await writeFile('src/app/index.ts', `export { AppModule } from './app.module';`); - await replaceInFile('src/main.ts', './app/app.module', './app'); - await ng('build', '--configuration=development'); -} diff --git a/tests/legacy-cli/e2e/tests/build/jit-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/jit-ngmodule.ts new file mode 100644 index 000000000000..2c13255bb17f --- /dev/null +++ b/tests/legacy-cli/e2e/tests/build/jit-ngmodule.ts @@ -0,0 +1,40 @@ +import { getGlobalVariable } from '../../utils/env'; +import { ng } from '../../utils/process'; +import { updateJsonFile, useCIChrome, useCIDefaults } from '../../utils/project'; + +export default async function () { + await ng('generate', 'app', 'test-project-two', '--no-standalone', '--skip-install'); + await ng('generate', 'e2e', '--related-app-name=test-project-two'); + + // Setup testing to use CI Chrome. + await useCIChrome('test-project-two', './projects/test-project-two/e2e'); + await useCIDefaults('test-project-two'); + + // Make prod use JIT. + + const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; + // Setup webpack builder if esbuild is not requested on the commandline + await updateJsonFile('angular.json', (json) => { + const build = json['projects']['test-project-two']['architect']['build']; + if (useWebpackBuilder) { + build.builder = '@angular-devkit/build-angular:browser'; + build.options = { + ...build.options, + main: build.options.browser, + browser: undefined, + buildOptimizer: false, + }; + + build.configurations.development = { + ...build.configurations.development, + vendorChunk: true, + namedChunks: true, + }; + } + + build.options.aot = false; + }); + // Test it works + await ng('e2e', 'test-project-two', '--configuration=production'); + await ng('e2e', 'test-project-two', '--configuration=development'); +} diff --git a/tests/legacy-cli/e2e/tests/build/jit-standalone.ts b/tests/legacy-cli/e2e/tests/build/jit-standalone.ts deleted file mode 100644 index 952f23c6612c..000000000000 --- a/tests/legacy-cli/e2e/tests/build/jit-standalone.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ng } from '../../utils/process'; -import { updateJsonFile, useCIChrome, useCIDefaults } from '../../utils/project'; - -export default async function () { - await ng('generate', 'app', 'test-project-two', '--standalone', '--skip-install'); - - // Make prod use JIT. - await updateJsonFile('angular.json', (configJson) => { - const appArchitect = configJson.projects['test-project-two'].architect; - const config = appArchitect.build.configurations; - config['production'].aot = false; - config['production'].buildOptimizer = false; - config['development'].aot = false; - }); - - // Setup testing to use CI Chrome. - await useCIChrome('test-project-two', './e2e/'); - await useCIDefaults('test-project-two'); - - // Test it works - await ng('e2e', '--configuration=production'); - await ng('e2e', '--configuration=development'); -} diff --git a/tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts b/tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts index e80f54f74ad0..c6e3f74a6bdd 100644 --- a/tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts +++ b/tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts @@ -6,37 +6,20 @@ * found in the LICENSE file at https://angular.io/license */ -import { readFile, replaceInFile, writeFile } from '../../utils/fs'; +import { replaceInFile, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { - const projectName = 'test-project'; - const appRoutingModulePath = 'src/app/app-routing.module.ts'; - - const originalAppRoutingModule = await readFile(appRoutingModulePath); - // helper to replace loadChildren - const replaceLoadChildren = async (route: string) => { - const content = originalAppRoutingModule.replace( - 'const routes: Routes = [];', - ` - const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }]; - `, - ); - - return writeFile(appRoutingModulePath, content); - }; - // Add lazy route. - await ng('generate', 'module', 'lazy', '--routing'); - await ng('generate', 'component', 'lazy/lazy-comp'); + await ng('generate', 'component', 'lazy-comp'); await replaceInFile( - 'src/app/lazy/lazy-routing.module.ts', - 'const routes: Routes = [];', - ` - import { LazyCompComponent } from './lazy-comp/lazy-comp.component'; - const routes: Routes = [{ path: '', component: LazyCompComponent }]; - `, + 'src/app/app.routes.ts', + 'routes: Routes = [];', + `routes: Routes = [{ + path: 'lazy', + loadComponent: () => import('./lazy-comp/lazy-comp.component').then(c => c.LazyCompComponent), + }];`, ); // Add lazy route e2e @@ -65,15 +48,11 @@ export default async function () { // Convert the default config to use JIT and prod to just do AOT. // This way we can use `ng e2e` to test JIT and `ng e2e --configuration=production` to test AOT. await updateJsonFile('angular.json', (json) => { - const buildTarget = json['projects'][projectName]['architect']['build']; + const buildTarget = json['projects']['test-project']['architect']['build']; buildTarget['options']['aot'] = true; buildTarget['configurations']['development']['aot'] = false; }); - // Test `import()` style lazy load. - // Both Ivy and View Engine should support it. - await replaceLoadChildren(`() => import('./lazy/lazy.module').then(m => m.LazyModule)`); - await ng('e2e'); await ng('e2e', '--configuration=production'); } diff --git a/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts b/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts index 1225795fa903..672a8044e3ea 100644 --- a/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts +++ b/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts @@ -6,46 +6,31 @@ * found in the LICENSE file at https://angular.io/license */ -import { createDir, writeFile } from '../../utils/fs'; +import { appendToFile, createDir, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { await ng('generate', 'library', 'mylib'); - await createLibraryEntryPoint('secondary', 'SecondaryModule', 'index.ts'); - await createLibraryEntryPoint('another', 'AnotherModule', 'index.ts'); + await createLibraryEntryPoint('secondary'); + await createLibraryEntryPoint('another'); // Scenario #1 where we use wildcard path mappings for secondary entry-points. await updateJsonFile('tsconfig.json', (json) => { json.compilerOptions.paths = { 'mylib': ['dist/mylib'], 'mylib/*': ['dist/mylib/*'] }; }); - await writeFile( - 'src/app/app.module.ts', + await appendToFile( + 'src/app/app.config.ts', ` - import {NgModule} from '@angular/core'; - import {BrowserModule} from '@angular/platform-browser'; - import {RouterModule} from '@angular/router'; - import {SecondaryModule} from 'mylib/secondary'; - import {AnotherModule} from 'mylib/another'; - - import {AppComponent} from './app.component'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - RouterModule, - SecondaryModule, - AnotherModule, - BrowserModule - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - `, + import * as secondary from 'mylib/secondary'; + import * as another from 'mylib/another'; + + console.log({ + secondary, + another + }); + `, ); await ng('build', 'mylib'); @@ -63,23 +48,15 @@ export default async function () { await ng('build'); } -async function createLibraryEntryPoint(name: string, moduleName: string, entryFileName: string) { +async function createLibraryEntryPoint(name: string): Promise { await createDir(`projects/mylib/${name}`); - await writeFile( - `projects/mylib/${name}/${entryFileName}`, - ` - import {NgModule} from '@angular/core'; - - @NgModule({}) - export class ${moduleName} {} - `, - ); + await writeFile(`projects/mylib/${name}/index.ts`, `export const foo = 'foo';`); await writeFile( `projects/mylib/${name}/ng-package.json`, JSON.stringify({ lib: { - entryFile: entryFileName, + entryFile: 'index.ts', }, }), ); diff --git a/tests/legacy-cli/e2e/tests/build/library/setup.ts b/tests/legacy-cli/e2e/tests/build/library/setup.ts index 98bc6e816944..f9372a7b6b6b 100644 --- a/tests/legacy-cli/e2e/tests/build/library/setup.ts +++ b/tests/legacy-cli/e2e/tests/build/library/setup.ts @@ -10,37 +10,20 @@ export async function libraryConsumptionSetup(): Promise { 'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core'; @Component({ + standalone: true, selector: 'lib-my-lib', templateUrl: './my-lib.component.html', }) export class MyLibComponent {}`, - './src/app/app.module.ts': ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { MyLibModule } from 'my-lib'; - - import { AppComponent } from './app.component'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - MyLibModule, - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - `, './src/app/app.component.ts': ` import { Component } from '@angular/core'; - import { MyLibService } from 'my-lib'; + import { MyLibService, MyLibComponent } from 'my-lib'; @Component({ + standalone: true, selector: 'app-root', - template: '' + template: '', + imports: [MyLibComponent], }) export class AppComponent { title = 'test-project'; diff --git a/tests/legacy-cli/e2e/tests/build/no-entry-module.ts b/tests/legacy-cli/e2e/tests/build/no-entry-module.ts deleted file mode 100644 index 11f7111fdb17..000000000000 --- a/tests/legacy-cli/e2e/tests/build/no-entry-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { readFile, writeFile } from '../../utils/fs'; -import { ng } from '../../utils/process'; - -export default async function () { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - - const mainTs = await readFile('src/main.ts'); - - const newMainTs = - mainTs.replace(/platformBrowserDynamic.*?bootstrapModule.*?;/, '') + 'console.log(AppModule);'; // Use AppModule to make sure it's imported properly. - - await writeFile('src/main.ts', newMainTs); - await ng('build', '--configuration=development'); -} diff --git a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts index 6b99415289bf..de6eab726210 100644 --- a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts +++ b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts @@ -3,18 +3,46 @@ import { getGlobalVariable } from '../../../utils/env'; import { expectFileToMatch, rimraf, writeFile } from '../../../utils/fs'; import { installWorkspacePackages } from '../../../utils/packages'; import { ng } from '../../../utils/process'; -import { useSha } from '../../../utils/project'; +import { updateJsonFile, useSha } from '../../../utils/project'; export default async function () { + const projectName = 'test-project-two'; + await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); + const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; if (useWebpackBuilder) { // Forcibly remove in case another test doesn't clean itself up. await rimraf('node_modules/@angular/ssr'); + // Setup webpack builder if esbuild is not requested on the commandline + await updateJsonFile('angular.json', (json) => { + const build = json['projects'][projectName]['architect']['build']; + build.builder = '@angular-devkit/build-angular:browser'; + build.options = { + ...build.options, + main: build.options.browser, + browser: undefined, + }; + + build.configurations.development = { + ...build.configurations.development, + vendorChunk: true, + namedChunks: true, + buildOptimizer: false, + }; + }); + // Angular SSR is not needed to do prerendering but it is the easiest way to enable when usign webpack based builders. - await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install'); + await ng( + 'add', + '@angular/ssr', + '--project', + projectName, + '--skip-confirmation', + '--skip-install', + ); } else { - await ng('generate', 'server', '--skip-install'); + await ng('generate', 'server', '--project', projectName, '--skip-install'); } await useSha(); @@ -22,7 +50,7 @@ export default async function () { // Add routes await writeFile( - 'src/app/app-routing.module.ts', + `projects/${projectName}/src/app/app-routing.module.ts`, ` import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; @@ -59,36 +87,46 @@ export default async function () { ); // Generate components for the above routes - await ng('generate', 'component', 'one'); - await ng('generate', 'component', 'two-child-one'); - await ng('generate', 'component', 'two-child-two'); + const componentNames: string[] = ['one', 'two-child-one', 'two-child-two']; + + for (const componentName of componentNames) { + await ng('generate', 'component', componentName, '--project', projectName); + } // Generate lazy routes - await ng('generate', 'module', 'lazy-one', '--route', 'lazy-one', '--module', 'app.module'); - await ng( - 'generate', - 'module', - 'lazy-one-child', - '--route', - 'lazy-one-child', - '--module', - 'lazy-one/lazy-one.module', - ); - await ng('generate', 'module', 'lazy-two', '--route', 'lazy-two', '--module', 'app.module'); + const lazyModules: [route: string, moduleName: string][] = [ + ['lazy-one', 'app.module'], + ['lazy-one-child', 'lazy-one/lazy-one.module'], + ['lazy-two', 'app.module'], + ]; + + for (const [route, moduleName] of lazyModules) { + await ng( + 'generate', + 'module', + route, + '--route', + route, + '--module', + moduleName, + '--project', + projectName, + ); + } // Prerender pages if (useWebpackBuilder) { - await ng('run', 'test-project:prerender:production'); + await ng('run', `${projectName}:prerender:production`); await runExpects(); return; } - await ng('build', '--configuration=production', '--prerender'); + await ng('build', projectName, '--configuration=production', '--prerender'); await runExpects(); // Test also JIT mode. - await ng('build', '--configuration=development', '--prerender', '--no-aot'); + await ng('build', projectName, '--configuration=development', '--prerender', '--no-aot'); await runExpects(); async function runExpects(): Promise { @@ -102,7 +140,7 @@ export default async function () { 'lazy-two/index.html': 'lazy-two works!', }; - let distPath = 'dist/test-project'; + let distPath = 'dist/' + projectName; if (useWebpackBuilder) { distPath += '/browser'; } diff --git a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-standalone.ts b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-standalone.ts index cf7c99180af0..64f79185ff00 100644 --- a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-standalone.ts +++ b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-standalone.ts @@ -3,46 +3,18 @@ import { getGlobalVariable } from '../../../utils/env'; import { expectFileToMatch, rimraf, writeFile } from '../../../utils/fs'; import { installWorkspacePackages } from '../../../utils/packages'; import { ng } from '../../../utils/process'; -import { updateJsonFile, useSha } from '../../../utils/project'; +import { useSha } from '../../../utils/project'; export default async function () { - const projectName = 'test-project-two'; - await ng('generate', 'application', projectName, '--standalone', '--skip-install'); - const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; if (useWebpackBuilder) { // Forcibly remove in case another test doesn't clean itself up. await rimraf('node_modules/@angular/ssr'); - // Setup webpack builder if esbuild is not requested on the commandline - await updateJsonFile('angular.json', (json) => { - const build = json['projects'][projectName]['architect']['build']; - build.builder = '@angular-devkit/build-angular:browser'; - build.options = { - ...build.options, - main: build.options.browser, - browser: undefined, - }; - - build.configurations.development = { - ...build.configurations.development, - vendorChunk: true, - namedChunks: true, - buildOptimizer: false, - }; - }); - // Angular SSR is not needed to do prerendering but it is the easiest way to enable when usign webpack based builders. - await ng( - 'add', - '@angular/ssr', - '--project', - projectName, - '--skip-confirmation', - '--skip-install', - ); + await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install'); } else { - await ng('generate', 'server', '--project', projectName, '--skip-install'); + await ng('generate', 'server', '--skip-install'); } await useSha(); @@ -50,7 +22,7 @@ export default async function () { // Add routes await writeFile( - `projects/${projectName}/src/app/app.routes.ts`, + 'src/app/app.routes.ts', ` import { Routes } from '@angular/router'; import { OneComponent } from './one/one.component'; @@ -107,22 +79,22 @@ export default async function () { ]; for (const componentName of componentNames) { - await ng('generate', 'component', componentName, '--project', projectName); + await ng('generate', 'component', componentName); } // Prerender pages if (useWebpackBuilder) { - await ng('run', projectName + ':prerender:production'); + await ng('run', 'test-project:prerender:production'); await runExpects(); return; } - await ng('build', projectName, '--configuration=production', '--prerender'); + await ng('build', '--configuration=production', '--prerender'); await runExpects(); // Test also JIT mode. - await ng('build', projectName, '--configuration=development', '--prerender', '--no-aot'); + await ng('build', '--configuration=development', '--prerender', '--no-aot'); await runExpects(); async function runExpects(): Promise { @@ -136,7 +108,7 @@ export default async function () { 'lazy-two/index.html': 'lazy-two works!', }; - let distPath = 'dist/' + projectName; + let distPath = 'dist/test-project'; if (useWebpackBuilder) { distPath += '/browser'; } diff --git a/tests/legacy-cli/e2e/tests/build/prod-build.ts b/tests/legacy-cli/e2e/tests/build/prod-build.ts index de709e205433..679dce98ea2f 100644 --- a/tests/legacy-cli/e2e/tests/build/prod-build.ts +++ b/tests/legacy-cli/e2e/tests/build/prod-build.ts @@ -24,10 +24,6 @@ function verifySize(bundle: string, baselineBytes: number) { } export default async function () { - // Can't use the `ng` helper because somewhere the environment gets - // stuck to the first build done - const bootstrapRegExp = /bootstrapModule\([\$_a-zA-Z]+[0-9]*\)\./; - await noSilentNg('build'); await expectFileToExist(join(process.cwd(), 'dist')); // Check for cache busting hash script src @@ -47,9 +43,6 @@ export default async function () { : /src="(main\.[0-9a-zA-Z]{16}\.js)"/; const mainPath = indexContent.match(mainSrcRegExp)![1]; - // Content checks - await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp); - // Size checks in bytes verifySize(mainPath, 210000); } diff --git a/tests/legacy-cli/e2e/tests/build/rebuild-deps-type-check.ts b/tests/legacy-cli/e2e/tests/build/rebuild-deps-type-check.ts index fc29895abbb4..ba52d3653317 100644 --- a/tests/legacy-cli/e2e/tests/build/rebuild-deps-type-check.ts +++ b/tests/legacy-cli/e2e/tests/build/rebuild-deps-type-check.ts @@ -81,7 +81,7 @@ export default function () { Promise.all([ waitForAnyProcessOutputToMatch(errorRe, 20000), appendToFile( - 'src/app/app.module.ts', + 'src/app/app.config.ts', ` function anything(): number { return 1; } `, diff --git a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-csp-nonce.ts b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-csp-nonce.ts index 685f3c50d3cc..b84a2af49f05 100644 --- a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-csp-nonce.ts +++ b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-csp-nonce.ts @@ -25,16 +25,14 @@ export default async function () { await writeMultipleFiles({ 'src/styles.css': `* { color: #000 }`, - 'src/main.ts': ` - import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - import { AppModule } from './app/app.module'; + 'src/main.ts': `import { bootstrapApplication } from '@angular/platform-browser'; + import { AppComponent } from './app/app.component'; + import { appConfig } from './app/app.config'; (window as any)['doBootstrap'] = () => { - platformBrowserDynamic() - .bootstrapModule(AppModule) - .catch((err) => console.error(err)); + bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)); }; - `, + `, 'src/index.html': ` diff --git a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-ngmodule.ts index ae266888d06c..f07f3697c977 100644 --- a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-ngmodule.ts +++ b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-ngmodule.ts @@ -3,14 +3,47 @@ import { rimraf, writeMultipleFiles } from '../../../utils/fs'; import { findFreePort } from '../../../utils/network'; import { installWorkspacePackages } from '../../../utils/packages'; import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../../utils/process'; -import { updateJsonFile, useSha } from '../../../utils/project'; +import { updateJsonFile, useCIChrome, useCIDefaults, useSha } from '../../../utils/project'; export default async function () { - const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; - // forcibly remove in case another test doesn't clean itself up await rimraf('node_modules/@angular/ssr'); - await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install'); + + await ng('generate', 'app', 'test-project-two', '--no-standalone', '--skip-install'); + await ng('generate', 'e2e', '--related-app-name=test-project-two'); + + // Setup testing to use CI Chrome. + await useCIChrome('test-project-two', 'projects/test-project-two/e2e/'); + await useCIDefaults('test-project-two'); + + const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; + + if (useWebpackBuilder) { + await updateJsonFile('angular.json', (json) => { + const build = json['projects']['test-project-two']['architect']['build']; + build.builder = '@angular-devkit/build-angular:browser'; + build.options = { + ...build.options, + main: build.options.browser, + browser: undefined, + }; + + build.configurations.development = { + ...build.configurations.development, + vendorChunk: true, + namedChunks: true, + buildOptimizer: false, + }; + }); + } + + await ng( + 'add', + '@angular/ssr', + '--skip-confirmation', + '--skip-install', + '--project=test-project-two', + ); await useSha(); await installWorkspacePackages(); @@ -18,14 +51,14 @@ export default async function () { if (!useWebpackBuilder) { // Disable prerendering await updateJsonFile('angular.json', (json) => { - const build = json['projects']['test-project']['architect']['build']; + const build = json['projects']['test-project-two']['architect']['build']; build.configurations.production.prerender = false; }); } await writeMultipleFiles({ - 'src/styles.css': `* { color: #000 }`, - 'src/main.ts': ` + 'projects/test-project-two/src/styles.css': `* { color: #000 }`, + 'projects/test-project-two/src/main.ts': ` import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module'; @@ -35,7 +68,7 @@ export default async function () { .catch((err) => console.error(err)); }; `, - 'e2e/src/app.e2e-spec.ts': + 'projects/test-project-two/e2e/src/app.e2e-spec.ts': ` import { browser, by, element } from 'protractor'; import * as webdriver from 'selenium-webdriver'; @@ -115,7 +148,7 @@ export default async function () { 'ng', [ 'run', - `test-project:${useWebpackBuilder ? 'serve-ssr' : 'serve'}:production`, + `test-project-two:${useWebpackBuilder ? 'serve-ssr' : 'serve'}:production`, '--port', String(port), ], @@ -127,7 +160,12 @@ export default async function () { try { const port = await ngDevSsr(); - await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target='); + await ng( + 'e2e', + 'test-project-two', + `--base-url=http://localhost:${port}`, + '--dev-server-target=', + ); } finally { await killAllProcesses(); } diff --git a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-standalone.ts b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-standalone.ts index 07a58c7ba216..2bdcafa3e34f 100644 --- a/tests/legacy-cli/e2e/tests/build/ssr/express-engine-standalone.ts +++ b/tests/legacy-cli/e2e/tests/build/ssr/express-engine-standalone.ts @@ -3,52 +3,19 @@ import { rimraf, writeMultipleFiles } from '../../../utils/fs'; import { findFreePort } from '../../../utils/network'; import { installWorkspacePackages } from '../../../utils/packages'; import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../../utils/process'; -import { updateJsonFile, useCIChrome, useCIDefaults, useSha } from '../../../utils/project'; +import { updateJsonFile, useSha } from '../../../utils/project'; export default async function () { // forcibly remove in case another test doesn't clean itself up await rimraf('node_modules/@angular/ssr'); - await ng('generate', 'app', 'test-project-two', '--standalone', '--skip-install'); - await ng('generate', 'e2e', '--related-app-name=test-project-two'); - - // Setup testing to use CI Chrome. - await useCIChrome('test-project-two', 'projects/test-project-two/e2e/'); - await useCIDefaults('test-project-two'); + await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install'); const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; - - if (useWebpackBuilder) { - await updateJsonFile('angular.json', (json) => { - const build = json['projects']['test-project-two']['architect']['build']; - build.builder = '@angular-devkit/build-angular:browser'; - build.options = { - ...build.options, - main: build.options.browser, - browser: undefined, - }; - - build.configurations.development = { - ...build.configurations.development, - vendorChunk: true, - namedChunks: true, - buildOptimizer: false, - }; - }); - } - - await ng( - 'add', - '@angular/ssr', - '--skip-confirmation', - '--project=test-project-two', - '--skip-install', - ); - if (!useWebpackBuilder) { // Disable prerendering await updateJsonFile('angular.json', (json) => { - const build = json['projects']['test-project-two']['architect']['build']; + const build = json['projects']['test-project']['architect']['build']; build.configurations.production.prerender = false; }); } @@ -57,8 +24,8 @@ export default async function () { await installWorkspacePackages(); await writeMultipleFiles({ - 'projects/test-project-two/src/styles.css': `* { color: #000 }`, - 'projects/test-project-two/src/main.ts': `import { bootstrapApplication } from '@angular/platform-browser'; + 'src/styles.css': `* { color: #000 }`, + 'src/main.ts': `import { bootstrapApplication } from '@angular/platform-browser'; import { AppComponent } from './app/app.component'; import { appConfig } from './app/app.config'; @@ -66,7 +33,7 @@ export default async function () { bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)); }; `, - 'projects/test-project-two/e2e/src/app.e2e-spec.ts': + 'e2e/src/app.e2e-spec.ts': ` import { browser, by, element } from 'protractor'; import * as webdriver from 'selenium-webdriver'; @@ -146,7 +113,7 @@ export default async function () { 'ng', [ 'run', - `test-project-two:${useWebpackBuilder ? 'serve-ssr' : 'serve'}:production`, + `test-project:${useWebpackBuilder ? 'serve-ssr' : 'serve'}:production`, '--port', String(port), ], @@ -158,12 +125,7 @@ export default async function () { try { const port = await ngDevSsr(); - await ng( - 'e2e', - 'test-project-two', - `--base-url=http://localhost:${port}`, - '--dev-server-target=', - ); + await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target='); } finally { await killAllProcesses(); } diff --git a/tests/legacy-cli/e2e/tests/build/ts-paths.ts b/tests/legacy-cli/e2e/tests/build/ts-paths.ts index 8af73d148817..61aa8324ce4b 100644 --- a/tests/legacy-cli/e2e/tests/build/ts-paths.ts +++ b/tests/legacy-cli/e2e/tests/build/ts-paths.ts @@ -19,7 +19,7 @@ export default async function () { 'src/app/shared/index.ts': `export * from './meaning'`, }); - await replaceInFile('src/app/app.module.ts', './app.component', '@root/app/app.component'); + await replaceInFile('src/main.ts', './app/app.component', '@root/app/app.component'); await ng('build', '--configuration=development'); await updateTsConfig((json) => { diff --git a/tests/legacy-cli/e2e/tests/generate/application/application-standalone-routing.ts b/tests/legacy-cli/e2e/tests/generate/application/application-standalone-routing.ts deleted file mode 100644 index 3506f39092aa..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/application/application-standalone-routing.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expectFileNotToExist, expectFileToMatch } from '../../../utils/fs'; -import { ng } from '../../../utils/process'; -import { useCIChrome } from '../../../utils/project'; - -export default async function () { - await ng('generate', 'application', 'app2', '--standalone', '--routing'); - await expectFileToMatch('angular.json', /\"app2\":/); - await expectFileToMatch('projects/app2/src/main.ts', /bootstrapApplication/); - await expectFileNotToExist('projects/app2/src/app/app.module.ts'); - await expectFileToMatch('projects/app2/src/app/app.routes.ts', /export const routes: Routes/); - await useCIChrome('app2', 'projects/app2'); - return ng('test', 'app2', '--watch=false'); -} diff --git a/tests/legacy-cli/e2e/tests/generate/application/application-standalone.ts b/tests/legacy-cli/e2e/tests/generate/application/application-standalone.ts deleted file mode 100644 index 9ed1fc24501e..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/application/application-standalone.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectFileNotToExist, expectFileToMatch } from '../../../utils/fs'; -import { ng } from '../../../utils/process'; -import { useCIChrome } from '../../../utils/project'; - -export default async function () { - await ng('generate', 'application', 'app2', '--standalone'); - await expectFileToMatch('angular.json', /\"app2\":/); - await expectFileToMatch('projects/app2/src/main.ts', /bootstrapApplication/); - await expectFileNotToExist('projects/app2/src/app/app.module.ts'); - await useCIChrome('app2', 'projects/app2'); - return ng('test', 'app2', '--watch=false'); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts b/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts index 66b226282027..5ded9eeb6f15 100644 --- a/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts +++ b/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts @@ -1,12 +1,11 @@ import { join } from 'path'; import { ng } from '../../../utils/process'; -import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; +import { expectFileToExist } from '../../../utils/fs'; export default function () { const projectDir = join('src', 'app'); const componentDir = join(projectDir, 'test-component'); - const importCheck = `import { TestComponentComponent } from './test-component/test-component.component';`; return ( ng('generate', 'component', 'test-component') .then(() => expectFileToExist(componentDir)) @@ -14,7 +13,6 @@ export default function () { .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) - .then(() => expectFileToMatch(join(projectDir, 'app.module.ts'), importCheck)) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-duplicate.ts b/tests/legacy-cli/e2e/tests/generate/component/component-duplicate.ts deleted file mode 100644 index c00e573df793..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-duplicate.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { appendToFile } from '../../../utils/fs'; -import { ng } from '../../../utils/process'; -import { expectToFail } from '../../../utils/utils'; - -export default function () { - return ng('generate', 'component', 'test-component') - .then((output) => { - if (!output.stdout.match(/UPDATE src[\\|\/]app[\\|\/]app.module.ts/)) { - throw new Error(`Expected to match "UPDATE src/app.module.ts" in ${output.stdout}.`); - } - }) - .then(() => - appendToFile('src/app/test-component/test-component.component.ts', '\n// new content'), - ) - .then(() => expectToFail(() => ng('generate', 'component', 'test-component'))); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-in-existing-module-dir.ts b/tests/legacy-cli/e2e/tests/generate/component/component-in-existing-module-dir.ts deleted file mode 100644 index bb98447bb4a1..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-in-existing-module-dir.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'foo', 'foo.module.ts'); - - return Promise.resolve() - .then(() => ng('generate', 'module', 'foo')) - .then(() => ng('generate', 'component', 'foo')) - .then(() => expectFileToMatch(modulePath, /import { FooComponent } from '.\/foo.component'/)); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-module-2.ts b/tests/legacy-cli/e2e/tests/generate/component/component-module-2.ts deleted file mode 100644 index 18c95587c35d..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-module-2.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const root = process.cwd(); - const modulePath = join(root, 'src', 'app', 'admin', 'module', 'module.module.ts'); - - return ( - Promise.resolve() - .then(() => ng('generate', 'module', 'admin/module')) - .then(() => ng('generate', 'component', 'other/test-component', '--module', 'admin/module')) - .then(() => - expectFileToMatch( - modulePath, - new RegExp( - /import { TestComponentComponent } /.source + - /from '..\/..\/other\/test-component\/test-component.component'/.source, - ), - ), - ) - - // Try to run the unit tests. - .then(() => ng('build', '--configuration=development')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-module-export.ts b/tests/legacy-cli/e2e/tests/generate/component/component-module-export.ts deleted file mode 100644 index 64340915a095..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-module-export.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'component', 'test-component', '--export') - .then(() => - expectFileToMatch(modulePath, /exports: \[\r?\n(\s*) TestComponentComponent\r?\n\1\]/), - ) - - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-module-fail.ts b/tests/legacy-cli/e2e/tests/generate/component/component-module-fail.ts deleted file mode 100644 index fe116fcac3d2..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-module-fail.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ng } from '../../../utils/process'; -import { expectToFail } from '../../../utils/utils'; - -export default function () { - return Promise.resolve().then(() => - expectToFail(() => - ng('generate', 'component', 'test-component', '--module', 'app.moduleXXX.ts'), - ), - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/component/component-module.ts b/tests/legacy-cli/e2e/tests/generate/component/component-module.ts deleted file mode 100644 index 46f7d29d11ba..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/component/component-module.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const root = process.cwd(); - // projects/ test-project/ src/ app.module.ts - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'component', 'test-component', '--module', 'app.module.ts') - .then(() => - expectFileToMatch( - modulePath, - /import { TestComponentComponent } from '.\/test-component\/test-component.component'/, - ), - ) - - .then(() => process.chdir(join(root, 'src', 'app'))) - .then(() => ng('generate', 'component', 'test-component2', '--module', 'app.module.ts')) - .then(() => process.chdir('../..')) - .then(() => - expectFileToMatch( - modulePath, - /import { TestComponent2Component } from '.\/test-component2\/test-component2.component'/, - ), - ) - - // Try to run the unit tests. - .then(() => ng('build', '--configuration=development')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/directive/directive-in-existing-module-dir.ts b/tests/legacy-cli/e2e/tests/generate/directive/directive-in-existing-module-dir.ts deleted file mode 100644 index 7dd270fe81a1..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/directive/directive-in-existing-module-dir.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'foo', 'foo.module.ts'); - - return Promise.resolve() - .then(() => ng('generate', 'module', 'foo')) - .then(() => ng('generate', 'directive', 'foo', '--no-flat')) - .then(() => expectFileToMatch(modulePath, /import { FooDirective } from '.\/foo.directive'/)); -} diff --git a/tests/legacy-cli/e2e/tests/generate/directive/directive-module-export.ts b/tests/legacy-cli/e2e/tests/generate/directive/directive-module-export.ts deleted file mode 100644 index 6a0c7f7a8aa6..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/directive/directive-module-export.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'directive', 'test-directive', '--export') - .then(() => - expectFileToMatch(modulePath, /exports: \[\r?\n(\s*) TestDirectiveDirective\r?\n\1\]/), - ) - - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/directive/directive-module-fail.ts b/tests/legacy-cli/e2e/tests/generate/directive/directive-module-fail.ts deleted file mode 100644 index c32d8a28df97..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/directive/directive-module-fail.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ng } from '../../../utils/process'; -import { expectToFail } from '../../../utils/utils'; - -export default function () { - return Promise.resolve().then(() => - expectToFail(() => - ng('generate', 'directive', 'test-directive', '--module', 'app.moduleXXX.ts'), - ), - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/directive/directive-module.ts b/tests/legacy-cli/e2e/tests/generate/directive/directive-module.ts deleted file mode 100644 index 25bc0f701faa..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/directive/directive-module.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'directive', 'test-directive', '--module', 'app.module.ts') - .then(() => - expectFileToMatch( - modulePath, - /import { TestDirectiveDirective } from '.\/test-directive.directive'/, - ), - ) - - .then(() => process.chdir(join('src', 'app'))) - .then(() => ng('generate', 'directive', 'test-directive2', '--module', 'app.module.ts')) - .then(() => process.chdir('../..')) - .then(() => - expectFileToMatch( - modulePath, - /import { TestDirective2Directive } from '.\/test-directive2.directive'/, - ), - ) - - // Try to run the unit tests. - .then(() => ng('build', '--configuration=development')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts b/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts index 2326f2f282f3..89b2afc5527f 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts @@ -2,19 +2,22 @@ import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; import { expectToFail } from '../../../utils/utils'; +import { useCIChrome, useCIDefaults } from '../../../utils/project'; -export default function () { - const moduleDir = join('src', 'app', 'test'); +export default async function () { + const projectName = 'test-project-two'; + const moduleDir = `projects/${projectName}/src/app/test`; + await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); + await useCIDefaults(projectName); + await useCIChrome(projectName, 'projects/test-project-two'); - return ( - ng('generate', 'module', 'test') - .then(() => expectFileToExist(moduleDir)) - .then(() => expectFileToExist(join(moduleDir, 'test.module.ts'))) - .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts')))) - .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts')))) - .then(() => expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule')) + await ng('generate', 'module', 'test', '--project', projectName); + await expectFileToExist(moduleDir); + await expectFileToExist(join(moduleDir, 'test.module.ts')); + await expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))); + await expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))); + await expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'); - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')) - ); + // Try to run the unit tests. + await ng('test', projectName, '--watch=false'); } diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-import.ts b/tests/legacy-cli/e2e/tests/generate/module/module-import.ts index 82824d1af09f..d8388584ec9e 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-import.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-import.ts @@ -2,65 +2,58 @@ import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToMatch } from '../../../utils/fs'; -export default function () { - const root = process.cwd(); - const modulePath = join(root, 'src', 'app', 'app.module.ts'); - const subModulePath = join('src', 'app', 'sub', 'sub.module.ts'); - const deepSubModulePath = join('src', 'app', 'sub', 'deep', 'deep.module.ts'); - - return Promise.resolve() - .then(() => ng('generate', 'module', 'sub')) - .then(() => ng('generate', 'module', 'sub/deep')) - - .then(() => ng('generate', 'module', 'test1', '--module', 'app.module.ts')) - .then(() => expectFileToMatch(modulePath, `import { Test1Module } from './test1/test1.module'`)) - .then(() => expectFileToMatch(modulePath, /imports: \[.*?Test1Module.*?\]/s)) - - .then(() => ng('generate', 'module', 'test2', '--module', 'app.module')) - .then(() => expectFileToMatch(modulePath, `import { Test2Module } from './test2/test2.module'`)) - .then(() => expectFileToMatch(modulePath, /imports: \[.*?Test2Module.*?\]/s)) - - .then(() => ng('generate', 'module', 'test3', '--module', 'app')) - .then(() => expectFileToMatch(modulePath, `import { Test3Module } from './test3/test3.module'`)) - .then(() => expectFileToMatch(modulePath, /imports: \[.*?Test3Module.*?\]/s)) - - .then(() => ng('generate', 'module', 'test4', '--routing', '--module', 'app')) - .then(() => expectFileToMatch(modulePath, /imports: \[.*?Test4Module.*?\]/s)) - .then(() => - expectFileToMatch( - join('src', 'app', 'test4', 'test4.module.ts'), - `import { Test4RoutingModule } from './test4-routing.module'`, - ), - ) - .then(() => - expectFileToMatch( - join('src', 'app', 'test4', 'test4.module.ts'), - /imports: \[.*?Test4RoutingModule.*?\]/s, - ), - ) - - .then(() => ng('generate', 'module', 'test5', '--module', 'sub')) - .then(() => - expectFileToMatch(subModulePath, `import { Test5Module } from '../test5/test5.module'`), - ) - .then(() => expectFileToMatch(subModulePath, /imports: \[.*?Test5Module.*?\]/s)) - - .then(() => - ng('generate', 'module', 'test6', '--module', join('sub', 'deep')) - .then(() => - expectFileToMatch( - deepSubModulePath, - `import { Test6Module } from '../../test6/test6.module'`, - ), - ) - .then(() => expectFileToMatch(deepSubModulePath, /imports: \[.*?Test6Module.*?\]/s)), - ); +export default async function () { + const projectName = 'test-project-two'; + await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); + await ng('generate', 'module', 'sub', '--project', projectName); + await ng('generate', 'module', 'sub/deep', '--project', projectName); + + const projectAppDir = `projects/${projectName}/src/app`; + const modulePath = join(projectAppDir, 'app.module.ts'); + const subModulePath = join(projectAppDir, 'sub/sub.module.ts'); + const deepSubModulePath = join(projectAppDir, 'sub/deep/deep.module.ts'); + + await ng('generate', 'module', 'test1', '--module', 'app.module.ts', '--project', projectName); + await expectFileToMatch(modulePath, `import { Test1Module } from './test1/test1.module'`); + await expectFileToMatch(modulePath, /imports: \[.*?Test1Module.*?\]/s); + + await ng('generate', 'module', 'test2', '--module', 'app.module', '--project', projectName); + await expectFileToMatch(modulePath, `import { Test2Module } from './test2/test2.module'`); + await expectFileToMatch(modulePath, /imports: \[.*?Test2Module.*?\]/s); + + await ng('generate', 'module', 'test3', '--module', 'app', '--project', projectName); + await expectFileToMatch(modulePath, `import { Test3Module } from './test3/test3.module'`); + await expectFileToMatch(modulePath, /imports: \[.*?Test3Module.*?\]/s); + + await ng('generate', 'module', 'test4', '--routing', '--module', 'app', '--project', projectName); + await expectFileToMatch(modulePath, /imports: \[.*?Test4Module.*?\]/s); + await expectFileToMatch( + join(projectAppDir, 'test4/test4.module.ts'), + `import { Test4RoutingModule } from './test4-routing.module'`, + ); + await expectFileToMatch( + join(projectAppDir, 'test4/test4.module.ts'), + /imports: \[.*?Test4RoutingModule.*?\]/s, + ); + + await ng('generate', 'module', 'test5', '--module', 'sub', '--project', projectName); + await expectFileToMatch(subModulePath, `import { Test5Module } from '../test5/test5.module'`); + + await expectFileToMatch(subModulePath, /imports: \[.*?Test5Module.*?\]/s); + + await ng('generate', 'module', 'test6', '--module', 'sub/deep', '--project', projectName); + + await expectFileToMatch( + deepSubModulePath, + `import { Test6Module } from '../../test6/test6.module'`, + ); + await expectFileToMatch(deepSubModulePath, /imports: \[.*?Test6Module.*?\]/s); // E2E_DISABLE: temporarily disable pending investigation - // .then(() => process.chdir(join(root, 'src', 'app'))) - // .then(() => ng('generate', 'module', 'test7', '--module', 'app.module.ts')) - // .then(() => process.chdir('..')) - // .then(() => expectFileToMatch(modulePath, + // await process.chdir(join(root, 'src', 'app'))) + // await ng('generate', 'module', 'test7', '--module', 'app.module.ts')) + // await process.chdir('..')) + // await expectFileToMatch(modulePath, // /import { Test7Module } from '.\/test7\/test7.module'/)) - // .then(() => expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m)); + // await expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m)); } diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-route.ts b/tests/legacy-cli/e2e/tests/generate/module/module-route.ts deleted file mode 100644 index 5dafaa581660..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/module/module-route.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectFileToExist } from '../../../utils/fs'; -import { ng } from '../../../utils/process'; - -export default async function () { - await ng('config', 'schematics.@schematics/angular.component.style', 'scss'); - - await ng('generate', 'module', 'test', '--routing'); - - await ng('generate', 'module', 'home', '-m', 'test', '--route', 'home', '--routing'); - - await expectFileToExist('src/app/home/home.component.scss'); -} diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts b/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts index 0d7b431aa4c7..c3262d77ac04 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts @@ -2,22 +2,23 @@ import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; import { expectToFail } from '../../../utils/utils'; +import { useCIChrome, useCIDefaults } from '../../../utils/project'; -export default function () { - const root = process.cwd(); - const testPath = join(root, 'src', 'app'); +export default async function () { + const projectName = 'test-project-two'; + await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); + await useCIDefaults(projectName); + await useCIChrome(projectName, 'projects/test-project-two'); + const testPath = join(process.cwd(), `projects/${projectName}/src/app`); process.chdir(testPath); - return Promise.resolve().then(() => - ng('generate', 'module', 'sub-dir/child', '--routing') - .then(() => expectFileToExist(join(testPath, 'sub-dir/child'))) - .then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts'))) - .then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts'))) - .then(() => - expectToFail(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))), - ) - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')), - ); + await ng('generate', 'module', 'sub-dir/child', '--routing'); + await expectFileToExist(join(testPath, 'sub-dir/child')); + await expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts')); + await expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts')); + await expectToFail(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))); + + // Try to run the unit tests. + await ng('test', projectName, '--watch=false'); } diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-routing.ts b/tests/legacy-cli/e2e/tests/generate/module/module-routing.ts deleted file mode 100644 index dbeaf843ec51..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/module/module-routing.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToExist } from '../../../utils/fs'; -import { expectToFail } from '../../../utils/utils'; - -export default function () { - const moduleDir = join('src', 'app', 'test'); - - return ( - ng('generate', 'module', 'test', '--routing') - .then(() => expectFileToExist(moduleDir)) - .then(() => expectFileToExist(join(moduleDir, 'test.module.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))) - .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts')))) - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-in-existing-module-dir.ts b/tests/legacy-cli/e2e/tests/generate/pipe/pipe-in-existing-module-dir.ts deleted file mode 100644 index 2055643a1b5b..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-in-existing-module-dir.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'foo', 'foo.module.ts'); - - return Promise.resolve() - .then(() => ng('generate', 'module', 'foo')) - .then(() => ng('generate', 'pipe', 'foo', '--no-flat')) - .then(() => expectFileToMatch(modulePath, /import { FooPipe } from '.\/foo.pipe'/)); -} diff --git a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-export.ts b/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-export.ts deleted file mode 100644 index 7f6f1bda0c06..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-export.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'pipe', 'test-pipe', '--export') - .then(() => expectFileToMatch(modulePath, /exports: \[\r?\n(\s*) TestPipePipe\r?\n\1\]/)) - - // Try to run the unit tests. - .then(() => ng('test', '--watch=false')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-fail.ts b/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-fail.ts deleted file mode 100644 index 14939a8002a5..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module-fail.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ng } from '../../../utils/process'; -import { expectToFail } from '../../../utils/utils'; - -export default function () { - return Promise.resolve().then(() => - expectToFail(() => ng('generate', 'pipe', 'test-pipe', '--module', 'app.moduleXXX.ts')), - ); -} diff --git a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module.ts b/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module.ts deleted file mode 100644 index 79d8c542d8a2..000000000000 --- a/tests/legacy-cli/e2e/tests/generate/pipe/pipe-module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../../utils/process'; -import { expectFileToMatch } from '../../../utils/fs'; - -export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); - - return ( - ng('generate', 'pipe', 'test-pipe', '--module', 'app.module.ts') - .then(() => expectFileToMatch(modulePath, /import { TestPipePipe } from '.\/test-pipe.pipe'/)) - - .then(() => process.chdir(join('src', 'app'))) - .then(() => ng('generate', 'pipe', 'test-pipe2', '--module', 'app.module.ts')) - .then(() => process.chdir('../..')) - .then(() => - expectFileToMatch(modulePath, /import { TestPipe2Pipe } from '.\/test-pipe2.pipe'/), - ) - - // Try to run the unit tests. - .then(() => ng('build', '--configuration=development')) - ); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-disk-cache.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-disk-cache.ts index ad4535539cce..1c2aeea31675 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-disk-cache.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-disk-cache.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { getGlobalVariable } from '../../utils/env'; -import { appendToFile, expectFileToMatch, rimraf, writeFile } from '../../utils/fs'; +import { expectFileToMatch, rimraf, writeFile } from '../../utils/fs'; import { installPackage, uninstallPackage } from '../../utils/packages'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; @@ -16,8 +16,22 @@ export default async function () { // Setup an i18n enabled component await ng('generate', 'component', 'i18n-test'); await writeFile(join('src/app/i18n-test', 'i18n-test.component.html'), '

Hello world

'); - // Actually use the generated component to ensure it is present in the application output - await appendToFile('src/app/app.component.html', ''); + + await writeFile( + 'src/app/app.component.ts', + ` + import { Component } from '@angular/core'; + import { I18nTestComponent } from './i18n-test/i18n-test.component'; + + @Component({ + standalone: true, + selector: 'app-root', + imports: [I18nTestComponent], + template: '' + }) + export class AppComponent {} + `, + ); // Install correct version let localizeVersion = '@angular/localize@' + readNgVersion(); diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts index a4ffa601056d..f7e4ac19f6e7 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts @@ -1,5 +1,5 @@ import { getGlobalVariable } from '../../utils/env'; -import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs'; +import { expectFileToMatch, prependToFile, replaceInFile, writeFile } from '../../utils/fs'; import { installPackage, uninstallPackage } from '../../utils/packages'; import { ng } from '../../utils/process'; import { readNgVersion } from '../../utils/version'; @@ -17,27 +17,10 @@ export default async function () { await ng('build', 'i18n-lib-test', '--configuration=development'); // Consume library in application - await writeFile( - 'src/app/app.module.ts', - ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { AppComponent } from './app.component'; - import { I18nLibTestModule } from 'i18n-lib-test'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - I18nLibTestModule, - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - `, + await replaceInFile('src/app/app.component.ts', 'imports: [', 'imports: [I18nLibTestComponent,'); + await prependToFile( + 'src/app/app.component.ts', + `import { I18nLibTestComponent } from 'i18n-lib-test';`, ); await writeFile( diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts index bb82c8f1e8d7..6ffcd32dd7ef 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { getGlobalVariable } from '../../utils/env'; -import { appendToFile, expectFileToMatch, writeFile } from '../../utils/fs'; +import { expectFileToMatch, writeFile } from '../../utils/fs'; import { installPackage, uninstallPackage } from '../../utils/packages'; import { ng } from '../../utils/process'; import { expectToFail } from '../../utils/utils'; @@ -11,7 +11,21 @@ export default async function () { await ng('generate', 'component', 'i18n-test'); await writeFile(join('src/app/i18n-test', 'i18n-test.component.html'), '

Hello world

'); // Actually use the generated component to ensure it is present in the application output - await appendToFile('src/app/app.component.html', ''); + await writeFile( + 'src/app/app.component.ts', + ` + import { Component } from '@angular/core'; + import { I18nTestComponent } from './i18n-test/i18n-test.component'; + + @Component({ + standalone: true, + selector: 'app-root', + imports: [I18nTestComponent], + template: '' + }) + export class AppComponent {} + `, + ); // Should fail if `@angular/localize` is missing const { message: message1 } = await expectToFail(() => ng('extract-i18n')); diff --git a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref-absolute.ts b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref-absolute.ts index 640686fee1e4..982c483c1982 100644 --- a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref-absolute.ts +++ b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref-absolute.ts @@ -9,7 +9,7 @@ import { expectFileToMatch } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; -import { externalServer, langTranslations, setupI18nConfig } from './setup'; +import { langTranslations, setupI18nConfig } from './setup'; const baseHrefs: { [l: string]: string } = { 'en-US': '/en/', diff --git a/tests/legacy-cli/e2e/tests/i18n/setup.ts b/tests/legacy-cli/e2e/tests/i18n/setup.ts index 215bfe3c9259..169527cd8d4f 100644 --- a/tests/legacy-cli/e2e/tests/i18n/setup.ts +++ b/tests/legacy-cli/e2e/tests/i18n/setup.ts @@ -101,8 +101,12 @@ export async function setupI18nConfig() { 'src/app/app.component.ts', ` import { Component, Inject, LOCALE_ID } from '@angular/core'; + import { DatePipe } from '@angular/common'; + @Component({ selector: 'app-root', + imports: [DatePipe], + standalone: true, templateUrl: './app.component.html' }) export class AppComponent { diff --git a/tests/legacy-cli/e2e/tests/misc/lazy-module.ts b/tests/legacy-cli/e2e/tests/misc/lazy-module.ts deleted file mode 100644 index 366f93aa4b45..000000000000 --- a/tests/legacy-cli/e2e/tests/misc/lazy-module.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { readdirSync } from 'fs'; -import { installPackage } from '../../utils/packages'; -import { ng } from '../../utils/process'; -import { appendToFile, writeFile, prependToFile, replaceInFile } from '../../utils/fs'; - -export default function () { - let oldNumberOfFiles = 0; - return ( - Promise.resolve() - .then(() => ng('build', '--configuration=development')) - .then(() => (oldNumberOfFiles = readdirSync('dist').length)) - .then(() => ng('generate', 'module', 'lazy', '--routing')) - .then(() => ng('generate', 'module', 'too/lazy', '--routing')) - .then(() => - prependToFile( - 'src/app/app.module.ts', - ` - import { RouterModule } from '@angular/router'; - `, - ), - ) - .then(() => - replaceInFile( - 'src/app/app.module.ts', - 'imports: [', - `imports: [ - RouterModule.forRoot([{ path: "lazy", loadChildren: () => import('src/app/lazy/lazy.module').then(m => m.LazyModule) }]), - RouterModule.forRoot([{ path: "lazy1", loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }]), - RouterModule.forRoot([{ path: "lazy2", loadChildren: () => import('./too/lazy/lazy.module').then(m => m.LazyModule) }]), - `, - ), - ) - .then(() => ng('build', '--named-chunks', '--configuration=development')) - .then(() => readdirSync('dist/test-project')) - .then((distFiles) => { - const currentNumberOfDistFiles = distFiles.length; - if (oldNumberOfFiles >= currentNumberOfDistFiles) { - throw new Error('A bundle for the lazy module was not created.'); - } - oldNumberOfFiles = currentNumberOfDistFiles; - - if (!distFiles.includes('src_app_too_lazy_lazy_module_ts.js')) { - throw new Error('The lazy module chunk did not use a unique name.'); - } - }) - // verify 'import *' syntax doesn't break lazy modules - .then(() => installPackage('moment')) - .then(() => - appendToFile( - 'src/app/app.component.ts', - ` - import * as moment from 'moment'; - console.log(moment); - `, - ), - ) - .then(() => ng('build', '--configuration=development')) - .then(() => readdirSync('dist/test-project').length) - .then((currentNumberOfDistFiles) => { - if (oldNumberOfFiles != currentNumberOfDistFiles) { - throw new Error("Bundles were not created after adding 'import *'."); - } - }) - .then(() => ng('build', '--no-named-chunks', '--configuration=development')) - .then(() => readdirSync('dist/test-project')) - .then((distFiles) => { - if ( - distFiles.includes('lazy-lazy-module.js') || - distFiles.includes('too-lazy-lazy-module.js') - ) { - throw new Error("Lazy chunks shouldn't have a name but did."); - } - }) - // Check for AoT and lazy routes. - .then(() => ng('build', '--aot', '--configuration=development')) - .then(() => readdirSync('dist/test-project').length) - .then((currentNumberOfDistFiles) => { - if (oldNumberOfFiles != currentNumberOfDistFiles) { - throw new Error('AoT build contains a different number of files.'); - } - }) - ); -} diff --git a/tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts b/tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts index 8aac6af53eb4..c95f6408fdca 100644 --- a/tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts +++ b/tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts @@ -52,6 +52,7 @@ export default async function () { `, './src/app/app.component.ts': ` import { Component } from '@angular/core'; + import { CommonModule } from '@angular/common'; import { Store, select } from '@ngrx/store'; import { Observable } from 'rxjs'; import { INCREMENT, DECREMENT, RESET } from './counter.reducer'; @@ -61,7 +62,9 @@ export default async function () { } @Component({ + standalone: true, selector: 'app-root', + imports: [CommonModule], template: \`
Current Count: {{ count$ | async }}
@@ -91,26 +94,26 @@ export default async function () { } `, './src/app/app.effects.ts': ` - import { Injectable } from '@angular/core'; - import { Actions, Effect } from '@ngrx/effects'; - import { filter, map, tap } from 'rxjs/operators'; + import { Injectable } from '@angular/core'; + import { Actions, Effect } from '@ngrx/effects'; + import { filter, map, tap } from 'rxjs/operators'; - @Injectable() - export class AppEffects { + @Injectable() + export class AppEffects { - @Effect() - mapper$ = this.actions$.pipe(map(() => ({ type: 'ANOTHER'})), filter(() => false)); + @Effect() + mapper$ = this.actions$.pipe(map(() => ({ type: 'ANOTHER'})), filter(() => false)); - @Effect({ dispatch: false }) - logger$ = this.actions$.pipe(tap(console.log)); + @Effect({ dispatch: false }) + logger$ = this.actions$.pipe(tap(console.log)); - constructor(private actions$: Actions) {} - } + constructor(private actions$: Actions) {} + } `, - './src/app/app.module.ts': ` - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - + './src/app/app.config.ts': ` + import { ApplicationConfig, importProvidersFrom } from '@angular/core'; + import { provideRouter } from '@angular/router'; + import { provideProtractorTestingSupport } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { StoreModule } from '@ngrx/store'; import { StoreDevtoolsModule } from '@ngrx/store-devtools'; @@ -118,20 +121,17 @@ export default async function () { import { AppEffects } from './app.effects'; import { counterReducer } from './counter.reducer'; - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - StoreModule.forRoot({ count: counterReducer }), - StoreDevtoolsModule.instrument(), - EffectsModule.forRoot([AppEffects]) - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } + import { routes } from './app.routes'; + + export const appConfig: ApplicationConfig = { + providers: [ + provideProtractorTestingSupport(), + provideRouter(routes), + importProvidersFrom(StoreModule.forRoot({ count: counterReducer })), + importProvidersFrom(StoreDevtoolsModule.instrument()), + importProvidersFrom(EffectsModule.forRoot([AppEffects])), + ] + }; `, './src/app/counter.reducer.ts': ` import { Action } from '@ngrx/store'; diff --git a/tests/legacy-cli/e2e/tests/misc/trusted-types.ts b/tests/legacy-cli/e2e/tests/misc/trusted-types.ts index 4efb8b9f70e3..b520aa514621 100644 --- a/tests/legacy-cli/e2e/tests/misc/trusted-types.ts +++ b/tests/legacy-cli/e2e/tests/misc/trusted-types.ts @@ -11,18 +11,13 @@ import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { - // Add app routing. - // This is done automatically on a new app with --routing. - await prependToFile('src/app/app.module.ts', `import { RouterModule } from '@angular/router';`); + // Add lazy route. + await ng('generate', 'component', 'lazy'); await replaceInFile( - 'src/app/app.module.ts', - `imports: [`, - `imports: [ RouterModule.forRoot([]),`, + 'src/app/app.routes.ts', + 'routes: Routes = [];', + `routes: Routes = [{path: 'lazy', loadComponent: () => import('./lazy/lazy.component').then(c => c.LazyComponent)}];`, ); - await appendToFile('src/app/app.component.html', ''); - - // Add lazy route. - await ng('generate', 'module', 'lazy', '--route', 'lazy', '--module', 'app.module'); // Add lazy route e2e await writeFile( diff --git a/tests/legacy-cli/e2e/tests/test/test-jasmine-clock.ts b/tests/legacy-cli/e2e/tests/test/test-jasmine-clock.ts index a5f0ca4cfd8a..f676b324a2c6 100644 --- a/tests/legacy-cli/e2e/tests/test/test-jasmine-clock.ts +++ b/tests/legacy-cli/e2e/tests/test/test-jasmine-clock.ts @@ -6,7 +6,6 @@ export default async function () { 'src/app/app.component.spec.ts', ` import { TestBed } from '@angular/core/testing'; - import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { @@ -19,8 +18,7 @@ export default async function () { }); beforeEach(() => TestBed.configureTestingModule({ - imports: [RouterTestingModule], - declarations: [AppComponent], + imports: [AppComponent] })); it('should create the app', () => {