Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aot option to jest #28855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}
}
}