-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathbuild.ts
More file actions
33 lines (28 loc) · 1.41 KB
/
build.ts
File metadata and controls
33 lines (28 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { getGlobalVariable } from '../../utils/env';
import { ng } from '../../utils/process';
const OUTPUT_INDEX_PATH = 'dist/test-project/browser/index.html';
export default async function () {
// Development build
const { stdout: stdoutDev } = await ng('build', '--configuration=development');
// Console output should not contain estimated transfer size information
assert.doesNotMatch(stdoutDev, /Estimated transfer size/);
// Output index HTML file should reference main JS file
const devIndexContent = await readFile(OUTPUT_INDEX_PATH, 'utf-8');
assert.match(devIndexContent, /main\.js/);
const usingApplicationBuilder = getGlobalVariable('argv')['esbuild'];
// Production build
const { stdout: stdoutProd } = await ng('build');
// Console output should contain estimated transfer size information
assert.match(stdoutProd, /Estimated transfer size/);
// Output index HTML file should reference main JS file with hashing
const prodIndexContent = await readFile(OUTPUT_INDEX_PATH, 'utf-8');
if (usingApplicationBuilder) {
// application builder uses an 8 character hash and a dash as a separator
assert.match(prodIndexContent, /main-[a-zA-Z0-9]{8}\.js/);
} else {
// browser builder uses a 16 character hash and a period as a separator
assert.match(prodIndexContent, /main\.[a-zA-Z0-9]{16}\.js/);
}
}