Skip to content

Commit 38ac095

Browse files
committed
feat: add aot option to karma
1 parent 8ffe8e5 commit 38ac095

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/angular_devkit/build_angular/src/builders/karma/application_builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async function initializeApplication(
338338
entryPoints,
339339
tsConfig: options.tsConfig,
340340
outputPath,
341-
aot: false,
341+
aot: options.aot,
342342
index: false,
343343
outputHashing: OutputHashing.None,
344344
optimization: false,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@
276276
"webWorkerTsConfig": {
277277
"type": "string",
278278
"description": "TypeScript configuration for Web Worker modules."
279+
},
280+
"aot": {
281+
"type": "boolean",
282+
"description": "Run tests using Ahead of Time compilation.",
283+
"default": false
279284
}
280285
},
281286
"additionalProperties": false,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { execute } from '../../index';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
11+
import { BuilderMode } from '../../schema';
12+
13+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
14+
describe('Option: "aot"', () => {
15+
it('enables aot', async () => {
16+
await setupTarget(harness);
17+
18+
await harness.writeFiles({
19+
'src/aot.spec.ts': `
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+
`,
33+
});
34+
35+
harness.useTarget('test', {
36+
...BASE_OPTIONS,
37+
aot: true,
38+
/** Cf. {@link ../builder-mode_spec.ts} */
39+
polyfills: ['zone.js', '@angular/localize/init', 'zone.js/testing'],
40+
builderMode: BuilderMode.Application,
41+
});
42+
43+
const { result } = await harness.executeOnce();
44+
expect(result?.success).toBeTrue();
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)