From a8b033716f850420b70083d4a1d622a0f0028a27 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 16 Apr 2019 09:34:26 +0200 Subject: [PATCH] test: fix e2e to rely on the bootstrapping call instead of the method to be present in the bundle --- .../legacy-cli/e2e/tests/build/prod-build.ts | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/tests/legacy-cli/e2e/tests/build/prod-build.ts b/tests/legacy-cli/e2e/tests/build/prod-build.ts index a99c8c88b3da..24bc1f39dcff 100644 --- a/tests/legacy-cli/e2e/tests/build/prod-build.ts +++ b/tests/legacy-cli/e2e/tests/build/prod-build.ts @@ -1,30 +1,37 @@ -import {join} from 'path'; -import {readdirSync} from 'fs'; -import {expectFileToExist, expectFileToMatch} from '../../utils/fs'; -import {ng} from '../../utils/process'; -import {expectGitToBeClean} from '../../utils/git'; +import { readdirSync } from 'fs'; +import { join } from 'path'; +import { getGlobalVariable } from '../../utils/env'; +import { expectFileToExist, expectFileToMatch } from '../../utils/fs'; +import { expectGitToBeClean } from '../../utils/git'; +import { ng } from '../../utils/process'; -export default function() { +export default async function () { // TODO(architect): Delete this test. It is now in devkit/build-angular. // Can't use the `ng` helper because somewhere the environment gets // stuck to the first build done - return ng('build', '--prod') - .then(() => expectFileToExist(join(process.cwd(), 'dist'))) - // Check for cache busting hash script src - .then(() => expectFileToMatch('dist/test-project/index.html', /main-es5\.[0-9a-f]{20}\.js/)) - .then(() => expectFileToMatch('dist/test-project/index.html', /main-es2015\.[0-9a-f]{20}\.js/)) - .then(() => expectFileToMatch('dist/test-project/index.html', /styles\.[0-9a-f]{20}\.css/)) - .then(() => expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/)) - // Defaults to AoT - .then(() => { - const mainES5 = readdirSync('./dist/test-project').find(name => !!name.match(/main-es5.[a-z0-9]+\.js/)); - expectFileToMatch(`dist/test-project/${mainES5}`, /bootstrapModuleFactory\(/); + const argv = getGlobalVariable('argv'); + const ivyProject = argv['ivy']; + const bootstrapRegExp = ivyProject + ? /bootstrapModule\([a-zA-Z]+\)\./ + : /bootstrapModuleFactory\([a-zA-Z]+\)\./; - const mainES2015 = readdirSync('./dist/test-project').find(name => !!name.match(/main-es2015.[a-z0-9]+\.js/)); - expectFileToMatch(`dist/test-project/${mainES5}`, /bootstrapModuleFactory\(/); - }) - // Check that the process didn't change local files. - .then(() => expectGitToBeClean()); + await ng('build', '--prod'); + await expectFileToExist(join(process.cwd(), 'dist')); + // Check for cache busting hash script src + await expectFileToMatch('dist/test-project/index.html', /main-es5\.[0-9a-f]{20}\.js/); + await expectFileToMatch('dist/test-project/index.html', /main-es2015\.[0-9a-f]{20}\.js/); + await expectFileToMatch('dist/test-project/index.html', /styles\.[0-9a-f]{20}\.css/); + await expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/); + + const dirContents = readdirSync('./dist/test-project'); + const mainES5 = dirContents.find(name => /main-es5.[a-z0-9]+\.js/.test(name)); + await expectFileToMatch(`dist/test-project/${mainES5}`, bootstrapRegExp); + + const mainES2015 = dirContents.find(name => /main-es2015.[a-z0-9]+\.js/.test(name)); + await expectFileToMatch(`dist/test-project/${mainES2015}`, bootstrapRegExp); + + // Check that the process didn't change local files. + await expectGitToBeClean(); }