test: update tests large to cater for the bundle changes with differential loading

This commit is contained in:
Alan Agius 2019-04-15 07:45:57 +02:00 committed by Alex Eagle
parent 718ed37684
commit c319cd054e
9 changed files with 28 additions and 35 deletions

View File

@ -8,7 +8,7 @@
import { TestProjectHost } from '@angular-devkit/architect/testing';
import { join } from '@angular-devkit/core';
import { getSystemPath, join } from '@angular-devkit/core';
import { ScriptTarget } from 'typescript';
import { isDifferentialLoadingNeeded } from './differential-loading';
@ -30,7 +30,7 @@ describe('differential loading', () => {
'browserslist': 'IE 9-11',
});
const needed = isDifferentialLoadingNeeded(host.root(), ScriptTarget.ES2015);
const needed = isDifferentialLoadingNeeded(getSystemPath(host.root()), ScriptTarget.ES2015);
expect(needed).toBe(true);
});
@ -39,7 +39,7 @@ describe('differential loading', () => {
'browserslist': 'last 1 chrome version',
});
const needed = isDifferentialLoadingNeeded(host.root(), ScriptTarget.ES2015);
const needed = isDifferentialLoadingNeeded(getSystemPath(host.root()), ScriptTarget.ES2015);
expect(needed).toBe(false);
});
@ -49,7 +49,7 @@ describe('differential loading', () => {
'browserslist': 'last 1 chrome version',
});
const needed = isDifferentialLoadingNeeded(host.root(), ScriptTarget.ES5);
const needed = isDifferentialLoadingNeeded(getSystemPath(host.root()), ScriptTarget.ES5);
expect(needed).toBe(false);
});

View File

@ -30,7 +30,7 @@ describe('Browser Builder allow js', () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
'"target": "es5", "allowJs": true',
);
@ -55,7 +55,7 @@ describe('Browser Builder allow js', () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
'"target": "es5", "allowJs": true',
);
@ -82,7 +82,7 @@ describe('Browser Builder allow js', () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
'"target": "es5", "allowJs": true',
);

View File

@ -10,25 +10,23 @@ import { Architect } from '@angular-devkit/architect/src/index';
import { PathFragment } from '@angular-devkit/core';
import { browserBuild, createArchitect, host } from '../utils';
// This feature is currently hidden behind a flag
xdescribe('Browser Builder with differential loading', () => {
describe('Browser Builder with differential loading', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
// to trigger differential loading we need an non ever green browser
host.writeMultipleFiles({
'browserslist': 'IE 10',
});
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('emits all the neccessary files', async () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
);
const { files } = await browserBuild(architect, host, target);
const expectedOutputs = [
@ -66,15 +64,8 @@ xdescribe('Browser Builder with differential loading', () => {
});
it('emits the right ES formats', async () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
);
const { files } = await browserBuild(architect, host, target, { optimization: true });
expect(await files['main-es5.js']).not.toContain('class');
expect(await files['main-es2015.js']).toContain('class');
});
});

View File

@ -30,7 +30,7 @@ describe('Browser Builder resolve json module', () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es5"',
'"target": "es2015"',
'"target": "es5", "resolveJsonModule": true',
);

View File

@ -291,6 +291,7 @@ describe('Browser Builder styles', () => {
/* normal-comment */
/*! important-comment */
div { flex: 1 }`,
'browserslist': 'IE 10',
});
const overrides = { extractCss: true, optimization: false };
@ -312,7 +313,7 @@ describe('Browser Builder styles', () => {
const overrides = { extractCss: true, optimization: true };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['styles.css']).toContain('/*! important-comment */div{-ms-flex:1;flex:1}');
expect(await files['styles.css']).toContain('/*! important-comment */div{flex:1}');
});
// TODO: consider making this a unit test in the url processing plugins.

View File

@ -119,7 +119,7 @@ describe('Browser Builder Web Worker support', () => {
host.scopedSync().read(join(outputPath, workerBundle)));
expect(workerContent).toContain('hello from worker');
expect(workerContent).toContain('bar');
expect(workerContent).toContain('"hello"===t&&postMessage');
expect(workerContent).toContain('"hello"===e&&postMessage');
// Main bundle should reference hashed worker bundle.
const mainBundle = host.fileMatchExists(outputPath, /main\.[0-9a-f]{20}\.js/) as string;

View File

@ -17,6 +17,7 @@ import { TestProjectHost, TestingArchitectHost } from '@angular-devkit/architect
import {
Path,
experimental,
getSystemPath,
join,
json,
normalize,
@ -42,15 +43,16 @@ export const tslintTargetSpec = { project: 'app', target: 'lint' };
export const protractorTargetSpec = { project: 'app-e2e', target: 'e2e' };
export async function createArchitect(workspaceRoot: string) {
export async function createArchitect(workspaceRoot: Path) {
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const workspaceSysPath = getSystemPath(workspaceRoot);
const workspace = await experimental.workspace.Workspace.fromPath(host, host.root(), registry);
const architectHost = new TestingArchitectHost(
workspaceRoot,
workspaceRoot,
new WorkspaceNodeModulesArchitectHost(workspace, workspaceRoot),
workspaceSysPath,
workspaceSysPath,
new WorkspaceNodeModulesArchitectHost(workspace, workspaceSysPath),
);
const architect = new Architect(architectHost, registry);

View File

@ -1,5 +1,4 @@
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11
# We want to run tests large with ever green browser so that
# we never trigger differential loading as this will slow down the tests.
last 2 Chrome versions

View File

@ -8,7 +8,7 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"target": "es2015",
"module": "esnext",
"typeRoots": [
"node_modules/@types"