Skip to content

Commit

Permalink
test: fix e2e to rely on the bootstrapping call instead of the method…
Browse files Browse the repository at this point in the history
… to be present in the bundle
  • Loading branch information
Alan Agius authored and alexeagle committed Apr 16, 2019
1 parent 8219380 commit a8b0337
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions tests/legacy-cli/e2e/tests/build/prod-build.ts
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit a8b0337

Please sign in to comment.