Skip to content

Commit ef7ea53

Browse files
yjaaidijkrems
authored andcommitted
feat(@angular-devkit/build-angular): add aot option to jest
1 parent 5123ff4 commit ef7ea53

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

packages/angular_devkit/build_angular/src/builders/jest/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default createBuilder(
8585
tsConfig: options.tsConfig,
8686
polyfills: options.polyfills ?? ['zone.js', 'zone.js/testing'],
8787
outputPath: testOut,
88-
aot: false,
88+
aot: options.aot,
8989
index: false,
9090
outputHashing: OutputHashing.None,
9191
outExtension: 'mjs', // Force native ESM.

packages/angular_devkit/build_angular/src/builders/jest/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"uniqueItems": true
3333
},
3434
"default": []
35+
},
36+
"aot": {
37+
"type": "boolean",
38+
"description": "Run tests using Ahead of Time compilation.",
39+
"default": false
3540
}
3641
},
3742
"additionalProperties": false,
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { deleteFile, writeFile } from '../../utils/fs';
2+
import { updateJsonFile } from '../../utils/project';
3+
import { applyJestBuilder } from '../../utils/jest';
4+
import { ng } from '../../utils/process';
5+
6+
export default async function (): Promise<void> {
7+
await applyJestBuilder();
8+
9+
{
10+
await updateJsonFile('tsconfig.spec.json', (json) => {
11+
return {
12+
...json,
13+
include: ['src/**/*.spec.ts'],
14+
};
15+
});
16+
17+
await writeFile(
18+
'src/aot.spec.ts',
19+
`
20+
import { Component } from '@angular/core';
21+
22+
describe('Hello', () => {
23+
it('should *not* contain jit instructions', () => {
24+
@Component({
25+
template: 'Hello',
26+
})
27+
class Hello {}
28+
29+
expect((Hello as any).ɵcmp.template.toString()).not.toContain('jit');
30+
});
31+
});
32+
`.trim(),
33+
);
34+
35+
const { stderr } = await ng('test', '--aot');
36+
37+
if (!stderr.includes('Ran all test suites.') || stderr.includes('failed')) {
38+
throw new Error(`Components were not transformed using AOT.\STDERR:\n\n${stderr}`);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)