Skip to content

Commit 2b7c8c4

Browse files
committed
test: update E2E tests to test against standalone apps
This commits updates E2E tests to reflect standalone by default.
1 parent ac0db66 commit 2b7c8c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+385
-889
lines changed

tests/legacy-cli/e2e/tests/basic/aot.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@ import { ng } from '../../utils/process';
33

44
export default async function () {
55
await ng('build', '--aot=true', '--configuration=development');
6-
await expectFileToMatch(
7-
'dist/test-project/main.js',
8-
/platformBrowser.*bootstrapModule.*AppModule/,
9-
);
6+
await expectFileToMatch('dist/test-project/main.js', 'AppComponent_Factory');
107
}

tests/legacy-cli/e2e/tests/basic/rebuild.ts

Lines changed: 21 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import fetch from 'node-fetch';
22
import { getGlobalVariable } from '../../utils/env';
3-
import { writeFile, writeMultipleFiles } from '../../utils/fs';
3+
import { appendToFile, replaceInFile, writeMultipleFiles } from '../../utils/fs';
44
import { silentNg, waitForAnyProcessOutputToMatch } from '../../utils/process';
55
import { ngServe } from '../../utils/project';
66

77
export default async function () {
88
const esbuild = getGlobalVariable('argv')['esbuild'];
99
const validBundleRegEx = esbuild ? /complete\./ : /Compiled successfully\./;
10-
const lazyBundleRegEx = esbuild ? /chunk-/ : /lazy_module_ts\.js/;
10+
const lazyBundleRegEx = esbuild ? /chunk-/ : /src_app_lazy_lazy_component_ts\.js/;
1111

1212
const port = await ngServe();
13-
// Add a lazy module.
14-
await silentNg('generate', 'module', 'lazy', '--routing');
13+
// Add a lazy route.
14+
await silentNg('generate', 'component', 'lazy');
1515

1616
// Should trigger a rebuild with a new bundle.
1717
// 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 () {
2020
// Verify that a new chunk was created.
2121
await Promise.all([
2222
waitForAnyProcessOutputToMatch(lazyBundleRegEx),
23-
writeFile(
24-
'src/app/app.module.ts',
25-
`
26-
import { BrowserModule } from '@angular/platform-browser';
27-
import { NgModule } from '@angular/core';
28-
import { FormsModule } from '@angular/forms';
29-
import { HttpClientModule } from '@angular/common/http';
30-
31-
import { AppComponent } from './app.component';
32-
import { RouterModule } from '@angular/router';
33-
34-
@NgModule({
35-
declarations: [
36-
AppComponent
37-
],
38-
imports: [
39-
BrowserModule,
40-
FormsModule,
41-
HttpClientModule,
42-
RouterModule.forRoot([
43-
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
44-
])
45-
],
46-
providers: [],
47-
bootstrap: [AppComponent]
48-
})
49-
export class AppModule { }
50-
`,
23+
replaceInFile(
24+
'src/app/app.routes.ts',
25+
'routes: Routes = [];',
26+
`routes: Routes = [{path: 'lazy', loadComponent: () => import('./lazy/lazy.component').then(c => c.LazyComponent)}];`,
5127
),
5228
]);
5329

5430
// Change multiple files and check that all of them are invalidated and recompiled.
5531
await Promise.all([
5632
waitForAnyProcessOutputToMatch(validBundleRegEx),
57-
writeMultipleFiles({
58-
'src/app/app.module.ts': `
59-
import { BrowserModule } from '@angular/platform-browser';
60-
import { NgModule } from '@angular/core';
61-
import { RouterModule } from '@angular/router';
62-
63-
import { AppComponent } from './app.component';
64-
65-
@NgModule({
66-
declarations: [
67-
AppComponent
68-
],
69-
imports: [
70-
RouterModule,
71-
BrowserModule
72-
],
73-
providers: [],
74-
bootstrap: [AppComponent]
75-
})
76-
export class AppModule { }
77-
33+
appendToFile(
34+
'src/app/app.routes.ts',
35+
`
7836
console.log('$$_E2E_GOLDEN_VALUE_1');
7937
export let X = '$$_E2E_GOLDEN_VALUE_2';
80-
`,
81-
'src/main.ts': `
82-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
83-
import { AppModule } from './app/app.module';
84-
85-
platformBrowserDynamic().bootstrapModule(AppModule);
86-
87-
import * as m from './app/app.module';
38+
`,
39+
),
40+
appendToFile(
41+
'src/main.ts',
42+
`
43+
import * as m from './app/app.routes';
8844
console.log(m.X);
8945
console.log('$$_E2E_GOLDEN_VALUE_3');
9046
`,
91-
}),
47+
),
9248
]);
9349

9450
await Promise.all([
9551
waitForAnyProcessOutputToMatch(validBundleRegEx),
9652
writeMultipleFiles({
97-
'src/app/app.module.ts': `
98-
import { BrowserModule } from '@angular/platform-browser';
99-
import { NgModule } from '@angular/core';
100-
import { RouterModule } from '@angular/router';
101-
import { AppComponent } from './app.component';
53+
'src/app/app.routes.ts': `
54+
import { Routes } from '@angular/router';
10255
103-
@NgModule({
104-
declarations: [
105-
AppComponent
106-
],
107-
imports: [
108-
RouterModule,
109-
BrowserModule
110-
],
111-
providers: [],
112-
bootstrap: [AppComponent]
113-
})
114-
export class AppModule { }
56+
export const routes: Routes = [];
11557
11658
console.log('$$_E2E_GOLDEN_VALUE_1');
11759
export let X = '$$_E2E_GOLDEN_VALUE_2';

tests/legacy-cli/e2e/tests/build/app-shell/app-shell-standalone.ts renamed to tests/legacy-cli/e2e/tests/build/app-shell/app-shell-ngmodule.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { updateJsonFile } from '../../../utils/project';
77
const snapshots = require('../../../ng-snapshot/package.json');
88

99
export default async function () {
10-
await ng('generate', 'app', 'test-project-two', '--routing', '--standalone', '--skip-install');
10+
await ng('generate', 'app', 'test-project-two', '--routing', '--no-standalone', '--skip-install');
1111

1212
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
1313

@@ -26,11 +26,7 @@ export default async function () {
2626
...build.configurations.development,
2727
vendorChunk: true,
2828
namedChunks: true,
29-
buildOptimizer: false,
3029
};
31-
} else {
32-
// TODO(alanagius): enable once esbuild supports standalone route extraction.
33-
build.configurations.production.prerender = false;
3430
}
3531
});
3632

tests/legacy-cli/e2e/tests/build/barrel-file.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { getGlobalVariable } from '../../utils/env';
2+
import { ng } from '../../utils/process';
3+
import { updateJsonFile, useCIChrome, useCIDefaults } from '../../utils/project';
4+
5+
export default async function () {
6+
await ng('generate', 'app', 'test-project-two', '--no-standalone', '--skip-install');
7+
await ng('generate', 'e2e', '--related-app-name=test-project-two');
8+
9+
// Setup testing to use CI Chrome.
10+
await useCIChrome('test-project-two', './projects/test-project-two/e2e');
11+
await useCIDefaults('test-project-two');
12+
13+
// Make prod use JIT.
14+
15+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
16+
// Setup webpack builder if esbuild is not requested on the commandline
17+
await updateJsonFile('angular.json', (json) => {
18+
const build = json['projects']['test-project-two']['architect']['build'];
19+
if (useWebpackBuilder) {
20+
build.builder = '@angular-devkit/build-angular:browser';
21+
build.options = {
22+
...build.options,
23+
main: build.options.browser,
24+
browser: undefined,
25+
buildOptimizer: false,
26+
};
27+
28+
build.configurations.development = {
29+
...build.configurations.development,
30+
vendorChunk: true,
31+
namedChunks: true,
32+
};
33+
}
34+
35+
build.options.aot = false;
36+
});
37+
// Test it works
38+
await ng('e2e', 'test-project-two', '--configuration=production');
39+
await ng('e2e', 'test-project-two', '--configuration=development');
40+
}

tests/legacy-cli/e2e/tests/build/jit-standalone.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,20 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { readFile, replaceInFile, writeFile } from '../../utils/fs';
9+
import { replaceInFile, writeFile } from '../../utils/fs';
1010
import { ng } from '../../utils/process';
1111
import { updateJsonFile } from '../../utils/project';
1212

1313
export default async function () {
14-
const projectName = 'test-project';
15-
const appRoutingModulePath = 'src/app/app-routing.module.ts';
16-
17-
const originalAppRoutingModule = await readFile(appRoutingModulePath);
18-
// helper to replace loadChildren
19-
const replaceLoadChildren = async (route: string) => {
20-
const content = originalAppRoutingModule.replace(
21-
'const routes: Routes = [];',
22-
`
23-
const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }];
24-
`,
25-
);
26-
27-
return writeFile(appRoutingModulePath, content);
28-
};
29-
3014
// Add lazy route.
31-
await ng('generate', 'module', 'lazy', '--routing');
32-
await ng('generate', 'component', 'lazy/lazy-comp');
15+
await ng('generate', 'component', 'lazy-comp');
3316
await replaceInFile(
34-
'src/app/lazy/lazy-routing.module.ts',
35-
'const routes: Routes = [];',
36-
`
37-
import { LazyCompComponent } from './lazy-comp/lazy-comp.component';
38-
const routes: Routes = [{ path: '', component: LazyCompComponent }];
39-
`,
17+
'src/app/app.routes.ts',
18+
'routes: Routes = [];',
19+
`routes: Routes = [{
20+
path: 'lazy',
21+
loadComponent: () => import('./lazy-comp/lazy-comp.component').then(c => c.LazyCompComponent),
22+
}];`,
4023
);
4124

4225
// Add lazy route e2e
@@ -65,15 +48,11 @@ export default async function () {
6548
// Convert the default config to use JIT and prod to just do AOT.
6649
// This way we can use `ng e2e` to test JIT and `ng e2e --configuration=production` to test AOT.
6750
await updateJsonFile('angular.json', (json) => {
68-
const buildTarget = json['projects'][projectName]['architect']['build'];
51+
const buildTarget = json['projects']['test-project']['architect']['build'];
6952
buildTarget['options']['aot'] = true;
7053
buildTarget['configurations']['development']['aot'] = false;
7154
});
7255

73-
// Test `import()` style lazy load.
74-
// Both Ivy and View Engine should support it.
75-
await replaceLoadChildren(`() => import('./lazy/lazy.module').then(m => m.LazyModule)`);
76-
7756
await ng('e2e');
7857
await ng('e2e', '--configuration=production');
7958
}

tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,31 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { createDir, writeFile } from '../../utils/fs';
9+
import { appendToFile, createDir, writeFile } from '../../utils/fs';
1010
import { ng } from '../../utils/process';
1111
import { updateJsonFile } from '../../utils/project';
1212

1313
export default async function () {
1414
await ng('generate', 'library', 'mylib');
15-
await createLibraryEntryPoint('secondary', 'SecondaryModule', 'index.ts');
16-
await createLibraryEntryPoint('another', 'AnotherModule', 'index.ts');
15+
await createLibraryEntryPoint('secondary');
16+
await createLibraryEntryPoint('another');
1717

1818
// Scenario #1 where we use wildcard path mappings for secondary entry-points.
1919
await updateJsonFile('tsconfig.json', (json) => {
2020
json.compilerOptions.paths = { 'mylib': ['dist/mylib'], 'mylib/*': ['dist/mylib/*'] };
2121
});
2222

23-
await writeFile(
24-
'src/app/app.module.ts',
23+
await appendToFile(
24+
'src/app/app.config.ts',
2525
`
26-
import {NgModule} from '@angular/core';
27-
import {BrowserModule} from '@angular/platform-browser';
28-
import {RouterModule} from '@angular/router';
29-
import {SecondaryModule} from 'mylib/secondary';
30-
import {AnotherModule} from 'mylib/another';
31-
32-
import {AppComponent} from './app.component';
33-
34-
@NgModule({
35-
declarations: [
36-
AppComponent
37-
],
38-
imports: [
39-
RouterModule,
40-
SecondaryModule,
41-
AnotherModule,
42-
BrowserModule
43-
],
44-
providers: [],
45-
bootstrap: [AppComponent]
46-
})
47-
export class AppModule { }
48-
`,
26+
import * as secondary from 'mylib/secondary';
27+
import * as another from 'mylib/another';
28+
29+
console.log({
30+
secondary,
31+
another
32+
});
33+
`,
4934
);
5035

5136
await ng('build', 'mylib');
@@ -63,23 +48,15 @@ export default async function () {
6348
await ng('build');
6449
}
6550

66-
async function createLibraryEntryPoint(name: string, moduleName: string, entryFileName: string) {
51+
async function createLibraryEntryPoint(name: string): Promise<void> {
6752
await createDir(`projects/mylib/${name}`);
68-
await writeFile(
69-
`projects/mylib/${name}/${entryFileName}`,
70-
`
71-
import {NgModule} from '@angular/core';
72-
73-
@NgModule({})
74-
export class ${moduleName} {}
75-
`,
76-
);
53+
await writeFile(`projects/mylib/${name}/index.ts`, `export const foo = 'foo';`);
7754

7855
await writeFile(
7956
`projects/mylib/${name}/ng-package.json`,
8057
JSON.stringify({
8158
lib: {
82-
entryFile: entryFileName,
59+
entryFile: 'index.ts',
8360
},
8461
}),
8562
);

0 commit comments

Comments
 (0)