feat(@angular-devkit/build-angular): add aot option to karma

This commit is contained in:
Younes Jaaidi 2024-11-13 17:38:43 +01:00 committed by Jan Olaf Martin
parent 8faaf51d61
commit 523d539c66
4 changed files with 54 additions and 1 deletions

View File

@ -206,6 +206,7 @@ export type FileReplacement = {
// @public // @public
export type KarmaBuilderOptions = { export type KarmaBuilderOptions = {
aot?: boolean;
assets?: AssetPattern_2[]; assets?: AssetPattern_2[];
browsers?: Browsers; browsers?: Browsers;
builderMode?: BuilderMode; builderMode?: BuilderMode;

View File

@ -396,7 +396,7 @@ async function initializeApplication(
entryPoints, entryPoints,
tsConfig: options.tsConfig, tsConfig: options.tsConfig,
outputPath, outputPath,
aot: false, aot: options.aot,
index: false, index: false,
outputHashing: OutputHashing.None, outputHashing: OutputHashing.None,
optimization: false, optimization: false,

View File

@ -276,6 +276,11 @@
"webWorkerTsConfig": { "webWorkerTsConfig": {
"type": "string", "type": "string",
"description": "TypeScript configuration for Web Worker modules." "description": "TypeScript configuration for Web Worker modules."
},
"aot": {
"type": "boolean",
"description": "Run tests using Ahead of Time compilation.",
"default": false
} }
}, },
"additionalProperties": false, "additionalProperties": false,

View File

@ -0,0 +1,47 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { execute } from '../../index';
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
import { BuilderMode } from '../../schema';
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
describe('Option: "aot"', () => {
it('enables aot', async () => {
await setupTarget(harness);
await harness.writeFiles({
'src/aot.spec.ts': `
import { Component } from '@angular/core';
describe('Hello', () => {
it('should *not* contain jit instructions', () => {
@Component({
template: 'Hello',
})
class Hello {}
expect((Hello as any).ɵcmp.template.toString()).not.toContain('jit');
});
});
`,
});
harness.useTarget('test', {
...BASE_OPTIONS,
aot: true,
/** Cf. {@link ../builder-mode_spec.ts} */
polyfills: ['zone.js', '@angular/localize/init', 'zone.js/testing'],
builderMode: BuilderMode.Application,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
});
});
});