Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ describe('Browser Builder lazy modules', () => {
'src/lazy-module.ts': 'export const value = 42;',
'src/main.ts': `import('./lazy-module');`,
});
// Using `import()` in TS require targetting `esnext` modules.
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

runTargetSpec(host, browserTargetSpec).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
Expand All @@ -147,7 +145,6 @@ describe('Browser Builder lazy modules', () => {
import(/*webpackChunkName: '[request]'*/'./lazy-' + lazyFileName);
`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

runTargetSpec(host, browserTargetSpec).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
Expand All @@ -172,7 +169,6 @@ describe('Browser Builder lazy modules', () => {
'src/lazy-module.ts': 'export const value = 42;',
'src/main.ts': `const lazyFileName = 'module'; import('./lazy-' + lazyFileName);`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

const overrides: Partial<BrowserBuilderSchema> = { namedChunks: false };

Expand All @@ -188,7 +184,6 @@ describe('Browser Builder lazy modules', () => {
'src/two.ts': `import * as http from '@angular/http'; console.log(http);`,
'src/main.ts': `import('./one'); import('./two');`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

runTargetSpec(host, browserTargetSpec).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
Expand All @@ -205,7 +200,6 @@ describe('Browser Builder lazy modules', () => {
'src/two.ts': `import * as http from '@angular/http'; console.log(http);`,
'src/main.ts': `import('./one'); import('./two');`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

const overrides: Partial<BrowserBuilderSchema> = { commonChunk: false };

Expand Down Expand Up @@ -237,7 +231,6 @@ describe('Browser Builder lazy modules', () => {
}
}`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

const overrides: Partial<BrowserBuilderSchema> = { lazyModules: ['src/app/lazy/lazy.module'] };

Expand Down Expand Up @@ -268,7 +261,6 @@ describe('Browser Builder lazy modules', () => {
}
}`,
});
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);

const overrides: Partial<BrowserBuilderSchema> = {
lazyModules: ['src/app/lazy/lazy.module'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": []
},
"exclude": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"types": [
"jasmine",
"node"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "esnext",
"typeRoots": [
"node_modules/@types"
],
Expand Down
89 changes: 75 additions & 14 deletions tests/legacy-cli/e2e/tests/experimental/ivy-lazy-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,84 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { readdirSync } from 'fs';
import { prependToFile, replaceInFile } from '../../utils/fs';
import { replaceInFile, writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { createProject } from '../../utils/project';
import { createProject, updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

export default async function() {
await createProject('ivy-project', '--enable-ivy');
export async function ivyLazyLoadSetup(projectName: string) {
// Make Ivy project.
await createProject(projectName, '--enable-ivy', '--routing');

// Add lazy route.
await ng('generate', 'module', 'lazy', '--routing');
await prependToFile('src/app/app.module.ts', `import { RouterModule } from '@angular/router';`);
await replaceInFile('src/app/app.module.ts', 'imports: [', `imports: [
RouterModule.forRoot([{ path: "lazy", loadChildren: "src/app/lazy/lazy.module#LazyModule" }]),
await replaceInFile('src/app/app-routing.module.ts', 'const routes: Routes = [];', `
const routes: Routes = [{ path: 'lazy', loadChildren: LOAD_CHILDREN_MARKER }];
`);
await ng('build', '--named-chunks', '--aot');
const distFiles = await readdirSync('dist/ivy-project');
if (!distFiles.includes('lazy-lazy-module.js')
|| distFiles.includes('lazy-lazy-module-ngfactory.js')) {
throw new Error('The lazy module chunk should not be a ngfactory.');
}
await ng('generate', 'component', 'lazy/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 }];
`);
await writeFile('src/app/app.component.html', '<router-outlet></router-outlet>');

// Add lazy route e2e
await writeFile('e2e/src/app.e2e-spec.ts', `
import { browser, logging, element, by } from 'protractor';

describe('workspace-project App', () => {
it('should display lazy route', () => {
browser.get(browser.baseUrl + '/lazy');
expect(element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
});

afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
}));
});
});
`);

// Set factory shims to false.
await updateJsonFile('src/tsconfig.app.json', json => {
const angularCompilerOptions = json['angularCompilerOptions'];
angularCompilerOptions['allowEmptyCodegenFiles'] = false;
});

// 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 --prod` to test AOT.
await updateJsonFile('angular.json', json => {
const buildTarget = json['projects'][projectName]['architect']['build'];
buildTarget['options']['aot'] = false;
buildTarget['configurations']['production'] = { aot: true };
});
}

export default async function () {
// Test `import()` style lazy load.
await ivyLazyLoadSetup('ivy-lazy-import');
await replaceInFile('src/app/app-routing.module.ts', 'LOAD_CHILDREN_MARKER', `
() => import('./lazy/lazy.module').then(m => m.LazyModule)
`);
await ng('e2e');
await ng('e2e', '--prod');

// Test string import with factory shims.
await ivyLazyLoadSetup('ivy-lazy-string-shims');
await replaceInFile('src/app/app-routing.module.ts', 'LOAD_CHILDREN_MARKER',
`'./lazy/lazy.module#LazyModule'`);
await replaceInFile('src/tsconfig.app.json', `"allowEmptyCodegenFiles": false`,
`"allowEmptyCodegenFiles": true`);
await expectToFail(() => ng('e2e')); // Currently broken.
await ng('e2e', '--prod');

// Test string import without factory shims.
await ivyLazyLoadSetup('ivy-lazy-string-no-shims');
await replaceInFile('src/app/app-routing.module.ts', 'LOAD_CHILDREN_MARKER',
`'./lazy/lazy.module#LazyModule'`);
await expectToFail(() => ng('e2e')); // Not supported.
await expectToFail(() => ng('e2e', '--prod')); // Not supported.
}
11 changes: 6 additions & 5 deletions tests/legacy-cli/e2e_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ allTests = allTests
// NEEDS devkit change
.filter(name => !name.endsWith('/existing-directory.ts'))
// Disabled on rc.0 due to needed sync with devkit for changes.
.filter(name => !name.endsWith('/service-worker.ts'))
// Lazy load support is WIP https://github.com/angular/angular/pull/28685
.filter(name => !name.endsWith('tests/experimental/ivy-lazy-load.ts'));
.filter(name => !name.endsWith('/service-worker.ts'));

if (argv.ivy) {
// These tests are disabled on the Ivy-only CI job because:
Expand All @@ -144,8 +142,6 @@ if (argv.ivy) {
// Ivy doesn't support i18n externally at the moment.
.filter(name => !name.includes('tests/i18n/'))
.filter(name => !name.endsWith('tests/build/aot/aot-i18n.ts'))
// Lazy load support is WIP https://github.com/angular/angular/pull/28685
.filter(name => !name.endsWith('tests/misc/lazy-module.ts'))
// We don't have a library consumption story yet for Ivy.
.filter(name => !name.endsWith('tests/generate/library/library-consumption.ts'));
}
Expand All @@ -171,6 +167,11 @@ const shardedTests = tests
.filter((name, i) => (shardId === null || (i % nbShards) == shardId));
const testsToRun = allSetups.concat(shardedTests);

if (shardedTests.length === 0) {
console.log(`No tests would be ran, aborting.`);
process.exit(1);
}

console.log(testsToRun.join('\n'));
/**
* Load all the files from the e2e, filter and sort them and build a promise of their default
Expand Down