Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): add aot option to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed Nov 14, 2024
1 parent f96bb86 commit 7c5253f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default createBuilder(
tsConfig: options.tsConfig,
polyfills: options.polyfills ?? ['zone.js', 'zone.js/testing'],
outputPath: testOut,
aot: false,
aot: options.aot,
index: false,
outputHashing: OutputHashing.None,
outExtension: 'mjs', // Force native ESM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"uniqueItems": true
},
"default": []
},
"aot": {
"type": "boolean",
"description": "Run tests using Ahead of Time compilation.",
"default": false
}
},
"additionalProperties": false,
Expand Down
41 changes: 41 additions & 0 deletions tests/legacy-cli/e2e/tests/jest/aot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { deleteFile, writeFile } from '../../utils/fs';
import { updateJsonFile } from '../../utils/project';
import { applyJestBuilder } from '../../utils/jest';
import { ng } from '../../utils/process';

export default async function (): Promise<void> {
await applyJestBuilder();

{
await updateJsonFile('tsconfig.spec.json', (json) => {
return {
...json,
include: ['src/**/*.spec.ts'],
};
});

await writeFile(
'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');
});
});
`.trim(),
);

const { stderr } = await ng('test', '--aot');

if (!stderr.includes('Ran all test suites.') || stderr.includes('failed')) {
throw new Error(`Components were not transformed using AOT.\STDERR:\n\n${stderr}`);
}
}
}

0 comments on commit 7c5253f

Please sign in to comment.