Skip to content

Commit 32101e4

Browse files
alan-agius4filipesilva
authored andcommitted
test: update e2e differential loading tests
These tests will eventually be removed in a seperate PR once differential loading is removed.
1 parent 5986bef commit 32101e4

12 files changed

+84
-87
lines changed

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

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { expectFileToMatch, replaceInFile } from '../../utils/fs';
1+
import { appendToFile, expectFileToMatch } from '../../utils/fs';
22
import { ng } from '../../utils/process';
33

4-
5-
export default async function() {
4+
export default async function () {
65
// Development build
76
await ng('build', '--configuration=development');
87
await expectFileToMatch('dist/test-project/index.html', 'main.js');
@@ -13,11 +12,7 @@ export default async function() {
1312
await ng('build', '--configuration=development', '--no-progress', 'test-project');
1413

1514
// Enable Differential loading to run both size checks
16-
await replaceInFile(
17-
'.browserslistrc',
18-
'not IE 11',
19-
'IE 11',
20-
);
15+
await appendToFile('.browserslistrc', 'IE 11');
2116
// Production build
2217
const { stderr: stderrProgress, stdout } = await ng('build', '--progress');
2318
await expectFileToMatch('dist/test-project/index.html', /main-es5\.[a-zA-Z0-9]{20}\.js/);

tests/legacy-cli/e2e/tests/build/differential-cache.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import * as crypto from 'crypto';
22
import * as fs from 'fs';
3-
import { rimraf, replaceInFile } from '../../utils/fs';
3+
import { rimraf, appendToFile } from '../../utils/fs';
44
import { ng } from '../../utils/process';
55

66
function generateFileHashMap(): Map<string, string> {
77
const hashes = new Map<string, string>();
88

9-
fs.readdirSync('./dist/test-project').forEach(name => {
9+
fs.readdirSync('./dist/test-project').forEach((name) => {
1010
const data = fs.readFileSync('./dist/test-project/' + name);
11-
const hash = crypto
12-
.createHash('sha1')
13-
.update(data)
14-
.digest('hex');
11+
const hash = crypto.createHash('sha1').update(data).digest('hex');
1512

1613
hashes.set(name, hash);
1714
});
@@ -35,7 +32,7 @@ function validateHashes(
3532
});
3633
}
3734

38-
export default async function() {
35+
export default async function () {
3936
// Skip on CI due to large variability of performance
4037
if (process.env['CI']) {
4138
return;
@@ -45,11 +42,7 @@ export default async function() {
4542
let newHashes: Map<string, string>;
4643

4744
// Enable Differential loading to run both size checks
48-
await replaceInFile(
49-
'.browserslistrc',
50-
'not IE 11',
51-
'IE 11',
52-
);
45+
await appendToFile('.browserslistrc', 'IE 11');
5346

5447
// Remove the cache so that an initial build and build with cache can be tested
5548
await rimraf('./node_modules/.cache');
@@ -66,7 +59,7 @@ export default async function() {
6659

6760
validateHashes(oldHashes, newHashes, []);
6861

69-
if (cached > initial * 0.70) {
62+
if (cached > initial * 0.7) {
7063
throw new Error(
7164
`Cached build time [${cached}] should not be greater than 70% of initial build time [${initial}].`,
7265
);
@@ -85,7 +78,7 @@ export default async function() {
8578
cached = Date.now() - start;
8679
newHashes = generateFileHashMap();
8780

88-
if (cached > initial * 0.70) {
81+
if (cached > initial * 0.7) {
8982
throw new Error(
9083
`Cached build time [${cached}] should not be greater than 70% of initial build time [${initial}].`,
9184
);

tests/legacy-cli/e2e/tests/build/differential-loading-sri.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ng } from '../../utils/process';
1111

1212
export default async function () {
1313
// Enable Differential loading
14-
await replaceInFile('.browserslistrc', 'not IE 11', 'IE 11');
14+
await appendToFile('.browserslistrc', 'IE 11');
1515

1616
const appRoutingModulePath = 'src/app/app-routing.module.ts';
1717

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { expectFileToExist, replaceInFile } from '../../utils/fs';
1+
import { appendToFile, expectFileToExist } from '../../utils/fs';
22
import { execAndWaitForOutputToMatch } from '../../utils/process';
33

44
export default async function () {
5-
await replaceInFile(
6-
'.browserslistrc',
7-
'not IE 11',
8-
'IE 11',
9-
);
5+
// Enable Differential loading to run both size checks
6+
await appendToFile('.browserslistrc', 'IE 11');
107

11-
await execAndWaitForOutputToMatch('ng', ['build', '--watch', '--configuration=development'], /Initial Total/i);
8+
await execAndWaitForOutputToMatch(
9+
'ng',
10+
['build', '--watch', '--configuration=development'],
11+
/Initial Total/i,
12+
);
1213
await expectFileToExist('dist/test-project/runtime-es2017.js');
1314
await expectFileToExist('dist/test-project/main-es2017.js');
1415
}

tests/legacy-cli/e2e/tests/build/differential-loading.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
import { oneLineTrim } from 'common-tags';
2-
import { appendToFile, expectFileToMatch, replaceInFile, writeMultipleFiles } from '../../utils/fs';
2+
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
33
import { ng } from '../../utils/process';
44
import { updateJsonFile } from '../../utils/project';
55
import { expectToFail } from '../../utils/utils';
66

77
export default async function () {
88
// Enable Differential loading to run both size checks
9-
await replaceInFile(
10-
'.browserslistrc',
11-
'not IE 11',
12-
'IE 11',
13-
);
9+
await appendToFile('.browserslistrc', 'IE 11');
1410

1511
await writeMultipleFiles({
1612
'src/string-script.js': "console.log('string-script'); var number = 1+1;",
1713
'src/pre-rename-script.js': "console.log('pre-rename-script');",
1814
});
1915

20-
await updateJsonFile('angular.json', configJson => {
16+
await updateJsonFile('angular.json', (configJson) => {
2117
const appArchitect = configJson.projects['test-project'].architect;
2218
appArchitect.build.options.scripts = [
2319
{ input: 'src/string-script.js' },
2420
{ input: 'src/pre-rename-script.js', bundleName: 'renamed-script' },
2521
];
2622
});
2723

28-
await ng('build', '--extract-css', '--vendor-chunk', '--optimization', '--configuration=development');
24+
await ng(
25+
'build',
26+
'--extract-css',
27+
'--vendor-chunk',
28+
'--optimization',
29+
'--configuration=development',
30+
);
2931

3032
// index.html lists the right bundles
3133
await expectFileToMatch(
@@ -45,5 +47,7 @@ export default async function () {
4547
);
4648

4749
await expectFileToMatch('dist/test-project/vendor-es2017.js', /class \w{constructor\(/);
48-
await expectToFail(() => expectFileToMatch('dist/test-project/vendor-es5.js', /class \w{constructor\(/));
50+
await expectToFail(() =>
51+
expectFileToMatch('dist/test-project/vendor-es5.js', /class \w{constructor\(/),
52+
);
4953
}
+19-12
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
import { oneLineTrim } from 'common-tags';
22
import {
3+
appendToFile,
34
expectFileSizeToBeUnder,
45
expectFileToExist,
56
expectFileToMatch,
67
getFileSize,
7-
replaceInFile,
88
} from '../../utils/fs';
99
import { ng } from '../../utils/process';
1010
import { expectToFail } from '../../utils/utils';
1111

1212
export default async function () {
1313
// Enable Differential loading to run both size checks
14-
await replaceInFile(
15-
'.browserslistrc',
16-
'not IE 11',
17-
'IE 11',
18-
);
14+
await appendToFile('.browserslistrc', 'IE 11');
1915

2016
await ng('build', '--aot=false', '--configuration=development');
2117
// files were created successfully
22-
await expectFileToMatch('dist/test-project/polyfills-es5.js', 'core-js/proposals/reflect-metadata');
18+
await expectFileToMatch(
19+
'dist/test-project/polyfills-es5.js',
20+
'core-js/proposals/reflect-metadata',
21+
);
2322
await expectFileToMatch('dist/test-project/polyfills-es5.js', 'zone.js');
2423

25-
await expectFileToMatch('dist/test-project/index.html', oneLineTrim`
24+
await expectFileToMatch(
25+
'dist/test-project/index.html',
26+
oneLineTrim`
2627
<script src="polyfills-es5.js" nomodule defer></script>
2728
<script src="polyfills-es2017.js" type="module">
28-
`);
29+
`,
30+
);
2931

3032
const jitPolyfillSize = await getFileSize('dist/test-project/polyfills-es5.js');
3133

3234
await ng('build', '--aot=true', '--configuration=development');
3335
// files were created successfully
3436
await expectFileToExist('dist/test-project/polyfills-es5.js');
3537
await expectFileSizeToBeUnder('dist/test-project/polyfills-es5.js', jitPolyfillSize);
36-
await expectToFail(() => expectFileToMatch('dist/test-project/polyfills-es5.js', 'core-js/proposals/reflect-metadata'));
38+
await expectToFail(() =>
39+
expectFileToMatch('dist/test-project/polyfills-es5.js', 'core-js/proposals/reflect-metadata'),
40+
);
3741
await expectFileToMatch('dist/test-project/polyfills-es5.js', 'zone.js');
3842

39-
await expectFileToMatch('dist/test-project/index.html', oneLineTrim`
43+
await expectFileToMatch(
44+
'dist/test-project/index.html',
45+
oneLineTrim`
4046
<script src="polyfills-es5.js" nomodule defer></script>
4147
<script src="polyfills-es2017.js" type="module">
42-
`);
48+
`,
49+
);
4350
}

tests/legacy-cli/e2e/tests/build/prod-build.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { statSync } from 'fs';
22
import { join } from 'path';
3-
import { expectFileToExist, expectFileToMatch, readFile, replaceInFile } from '../../utils/fs';
3+
import { appendToFile, expectFileToExist, expectFileToMatch, readFile } from '../../utils/fs';
44
import { ng } from '../../utils/process';
55
import { expectToFail } from '../../utils/utils';
66

7-
87
function verifySize(bundle: string, baselineBytes: number) {
98
const size = statSync(`dist/test-project/${bundle}`).size;
10-
const percentageBaseline = baselineBytes * 10 / 100;
9+
const percentageBaseline = (baselineBytes * 10) / 100;
1110
const maxSize = baselineBytes + percentageBaseline;
1211
const minSize = baselineBytes - percentageBaseline;
1312

@@ -32,11 +31,7 @@ export default async function () {
3231
const bootstrapRegExp = /bootstrapModule\(.?[a-zA-Z]+\)\./;
3332

3433
// Enable Differential loading to run both size checks
35-
await replaceInFile(
36-
'.browserslistrc',
37-
'not IE 11',
38-
'IE 11',
39-
);
34+
await appendToFile('.browserslistrc', 'IE 11');
4035

4136
await ng('build');
4237
await expectFileToExist(join(process.cwd(), 'dist'));

tests/legacy-cli/e2e/tests/build/sourcemap.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import * as fs from 'fs';
2-
import { expectFileToExist, replaceInFile } from '../../utils/fs';
2+
import { appendToFile, expectFileToExist } from '../../utils/fs';
33
import { ng } from '../../utils/process';
44

55
export default async function () {
66
// Enable Differential loading to run both size checks
7-
await replaceInFile(
8-
'.browserslistrc',
9-
'not IE 11',
10-
'IE 11',
11-
);
7+
await appendToFile('.browserslistrc', 'IE 11');
128

139
// The below is needed to cache bundles and verify that sourcemaps are generated
1410
// corretly when output-hashing is disabled.
@@ -21,7 +17,7 @@ export default async function () {
2117
await testForSourceMaps(8);
2218
}
2319

24-
async function testForSourceMaps(expectedNumberOfFiles: number): Promise <void> {
20+
async function testForSourceMaps(expectedNumberOfFiles: number): Promise<void> {
2521
await expectFileToExist('dist/test-project/main-es5.js.map');
2622
await expectFileToExist('dist/test-project/main-es2017.js.map');
2723

@@ -48,6 +44,8 @@ async function testForSourceMaps(expectedNumberOfFiles: number): Promise <void>
4844
}
4945

5046
if (count < expectedNumberOfFiles) {
51-
throw new Error(`Javascript file count is low. Expected ${expectedNumberOfFiles} but found ${count}`);
47+
throw new Error(
48+
`Javascript file count is low. Expected ${expectedNumberOfFiles} but found ${count}`,
49+
);
5250
}
5351
}

tests/legacy-cli/e2e/tests/build/styles/preset-env.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectFileToMatch, replaceInFile, writeMultipleFiles } from '../../../utils/fs';
1+
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
22
import { ng } from '../../../utils/process';
33

44
export default async function () {
@@ -9,11 +9,7 @@ export default async function () {
99
});
1010

1111
// Enable IE 11 support
12-
await replaceInFile(
13-
'.browserslistrc',
14-
'not IE 11',
15-
'IE 11',
16-
);
12+
await appendToFile('.browserslistrc', 'IE 11');
1713

1814
await ng('build', '--configuration=development');
1915
await expectFileToMatch('dist/test-project/styles.css', 'z-index: auto');

tests/legacy-cli/e2e/tests/build/worker.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
*/
88

99
import { join } from 'path';
10-
import { expectFileToExist, expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
10+
import {
11+
appendToFile,
12+
expectFileToExist,
13+
expectFileToMatch,
14+
replaceInFile,
15+
writeFile,
16+
} from '../../utils/fs';
1117
import { ng } from '../../utils/process';
1218

1319
export default async function () {
@@ -17,7 +23,7 @@ export default async function () {
1723
const workerTsConfig = 'tsconfig.worker.json';
1824

1925
// Enable Differential loading to run both size checks
20-
await replaceInFile('.browserslistrc', 'not IE 11', 'IE 11');
26+
await appendToFile('.browserslistrc', 'IE 11');
2127

2228
await ng('generate', 'web-worker', 'app');
2329
await expectFileToExist(workerPath);

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xliff2.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { appendToFile, expectFileToMatch, replaceInFile } from '../../utils/fs';
1+
import { appendToFile, expectFileToMatch } from '../../utils/fs';
22
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
44
import { expectToFail } from '../../utils/utils';
55
import { baseDir, externalServer, langTranslations, setupI18nConfig } from './setup';
66

7-
export default async function() {
7+
export default async function () {
88
// Setup i18n tests and config.
99
await setupI18nConfig('xlf2');
1010

@@ -14,13 +14,9 @@ export default async function() {
1414

1515
export async function executeTest() {
1616
// Ensure a DL build is used.
17-
await replaceInFile(
18-
'.browserslistrc',
19-
'not IE 11',
20-
'IE 11',
21-
);
17+
await appendToFile('.browserslistrc', 'IE 11');
2218

23-
await updateJsonFile('tsconfig.json', config => {
19+
await updateJsonFile('tsconfig.json', (config) => {
2420
config.compilerOptions.target = 'es2017';
2521
if (!config.angularCompilerOptions) {
2622
config.angularCompilerOptions = {};
@@ -56,10 +52,16 @@ export async function executeTest() {
5652

5753
// Verify locale data comments are removed in production
5854
await expectToFail(() =>
59-
expectFileToMatch(`${outputPath}/vendor-es5.js`, '// See angular/tools/gulp-tasks/cldr/extract.js'),
55+
expectFileToMatch(
56+
`${outputPath}/vendor-es5.js`,
57+
'// See angular/tools/gulp-tasks/cldr/extract.js',
58+
),
6059
);
6160
await expectToFail(() =>
62-
expectFileToMatch(`${outputPath}/vendor-es2017.js`, '// See angular/tools/gulp-tasks/cldr/extract.js'),
61+
expectFileToMatch(
62+
`${outputPath}/vendor-es2017.js`,
63+
'// See angular/tools/gulp-tasks/cldr/extract.js',
64+
),
6365
);
6466

6567
// Execute Application E2E tests with dev server

0 commit comments

Comments
 (0)