Skip to content

Commit

Permalink
feat: add aot option to karma
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed Nov 13, 2024
1 parent 8ffe8e5 commit 38ac095
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async function initializeApplication(
entryPoints,
tsConfig: options.tsConfig,
outputPath,
aot: false,
aot: options.aot,
index: false,
outputHashing: OutputHashing.None,
optimization: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@
"webWorkerTsConfig": {
"type": "string",
"description": "TypeScript configuration for Web Worker modules."
},
"aot": {
"type": "boolean",
"description": "Run tests using Ahead of Time compilation.",
"default": false
}
},
"additionalProperties": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

0 comments on commit 38ac095

Please sign in to comment.