Skip to content

Commit f924197

Browse files
committed
test: update E2E polyfills test for JIT mode
1 parent 4a1c29e commit f924197

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed
+25-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
import { expectFileToMatch } from '../../utils/fs';
2-
import { ng } from '../../utils/process';
31
import { oneLineTrim } from 'common-tags';
2+
import {
3+
expectFileSizeToBeUnder,
4+
expectFileToExist,
5+
expectFileToMatch,
6+
getFileSize,
7+
} from '../../utils/fs';
8+
import { ng } from '../../utils/process';
9+
import { expectToFail } from '../../utils/utils';
410

5-
export default function () {
6-
// TODO(architect): Delete this test. It is now in devkit/build-angular.
11+
export default async function () {
12+
await ng('build');
13+
// files were created successfully
14+
await expectFileToMatch('dist/test-project/polyfills.js', 'core-js/es7/reflect');
15+
await expectFileToMatch('dist/test-project/polyfills.js', 'zone.js');
16+
expectFileToMatch('dist/test-project/index.html', oneLineTrim`
17+
<script type="text/javascript" src="runtime.js"></script>
18+
<script type="text/javascript" src="polyfills.js"></script>
19+
`);
20+
const jitPolyfillSize = await getFileSize('dist/test-project/polyfills.js');
721

8-
return Promise.resolve()
9-
.then(() => ng('build'))
22+
await ng('build', '--aot');
1023
// files were created successfully
11-
.then(() => expectFileToMatch('dist/test-project/polyfills.js', 'core-js'))
12-
.then(() => expectFileToMatch('dist/test-project/polyfills.js', 'zone.js'))
13-
// index.html lists the right bundles
14-
.then(() => expectFileToMatch('dist/test-project/index.html', oneLineTrim`
24+
await expectFileToExist('dist/test-project/polyfills.js');
25+
await expectFileSizeToBeUnder('dist/test-project/polyfills.js', jitPolyfillSize);
26+
await expectToFail(() => expectFileToMatch('dist/test-project/polyfills.js', 'core-js/es7/reflect'));
27+
await expectFileToMatch('dist/test-project/polyfills.js', 'zone.js');
28+
expectFileToMatch('dist/test-project/index.html', oneLineTrim`
1529
<script type="text/javascript" src="runtime.js"></script>
1630
<script type="text/javascript" src="polyfills.js"></script>
17-
`));
31+
`);
1832
}

tests/legacy-cli/e2e/utils/fs.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,16 @@ export function expectFileToMatch(fileName: string, regEx: RegExp | string) {
192192
});
193193
}
194194

195-
export function expectFileSizeToBeUnder(fileName: string, sizeInBytes: number) {
196-
return readFile(fileName)
197-
.then(content => {
198-
if (content.length > sizeInBytes) {
199-
throw new Error(`File "${fileName}" exceeded file size of "${sizeInBytes}".`);
200-
}
201-
});
195+
export async function getFileSize(fileName: string) {
196+
const stats = await fs.stat(fileName);
197+
198+
return stats.size;
199+
}
200+
201+
export async function expectFileSizeToBeUnder(fileName: string, sizeInBytes: number) {
202+
const fileSize = await getFileSize(fileName);
203+
204+
if (fileSize > sizeInBytes) {
205+
throw new Error(`File "${fileName}" exceeded file size of "${sizeInBytes}".`);
206+
}
202207
}

0 commit comments

Comments
 (0)