Skip to content

Commit 523d539

Browse files
yjaaidijkrems
authored andcommitted
feat(@angular-devkit/build-angular): add aot option to karma
1 parent 8faaf51 commit 523d539

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

goldens/public-api/angular_devkit/build_angular/index.api.md

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export type FileReplacement = {
206206

207207
// @public
208208
export type KarmaBuilderOptions = {
209+
aot?: boolean;
209210
assets?: AssetPattern_2[];
210211
browsers?: Browsers;
211212
builderMode?: BuilderMode;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ async function initializeApplication(
396396
entryPoints,
397397
tsConfig: options.tsConfig,
398398
outputPath,
399-
aot: false,
399+
aot: options.aot,
400400
index: false,
401401
outputHashing: OutputHashing.None,
402402
optimization: false,

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

+5
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,
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)