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 karma #28854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yjaaidi
Copy link

@yjaaidi yjaaidi commented Nov 13, 2024

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Tests run in JIT only.

What is the new behavior?

Tests can run in AOT, using the new aot option.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Nov 13, 2024
})
class Hello {}

expect((Hello as any).ɵcmp.template.toString()).not.toContain('jit');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fragile and sensitive to any structural changes in JIT. It could easily cause false negatives.
What would be a better way to achieve this detection?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as long as we have a second test case that tests the reverse, it's fine..? That way we can make sure that "jit" appears in one branch and doesn't appear in the other, with aot: true vs aot: false as the only difference. That seems like an okay state to be in for now.

...BASE_OPTIONS,
aot: true,
/** Cf. {@link ../builder-mode_spec.ts} */
polyfills: ['zone.js', '@angular/localize/init', 'zone.js/testing'],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we factorize this in BASE_OPTIONS? or create a BASE_POLYFILLS? or an object mother: optionsMother.base().withPolyfills()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describeKarmaBuilder already runs the builder in both modes automatically. You shouldn't need any override but aot: true in here if everything works as expected. The builder mode spec is special because it explicitly tests that the mode can be changed by explicitly setting this. But it seems wasteful to rerun this test case twice in application builder mode (which I think is what's currently happening with this file).

@yjaaidi yjaaidi mentioned this pull request Nov 13, 2024
13 tasks
@yjaaidi yjaaidi force-pushed the feat/add-aot-option-to-karma branch from 38ac095 to 48d0a96 Compare November 14, 2024 00:42
@clydin clydin added the target: minor This PR is targeted for the next minor release label Nov 15, 2024
@jkrems
Copy link
Contributor

jkrems commented Nov 15, 2024

Sorry for the lack of review so far but I just want to quickly say that I'm really excited to see this option added. aot all the things! 🎉 - goes back to working through final fixes for the rc candidate

@yjaaidi
Copy link
Author

yjaaidi commented Nov 15, 2024

No rush at all!

Copy link
Contributor

@jkrems jkrems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - sorry for the late review!

...BASE_OPTIONS,
aot: true,
/** Cf. {@link ../builder-mode_spec.ts} */
polyfills: ['zone.js', '@angular/localize/init', 'zone.js/testing'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describeKarmaBuilder already runs the builder in both modes automatically. You shouldn't need any override but aot: true in here if everything works as expected. The builder mode spec is special because it explicitly tests that the mode can be changed by explicitly setting this. But it seems wasteful to rerun this test case twice in application builder mode (which I think is what's currently happening with this file).

import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
import { BuilderMode } from '../../schema';

describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to restrict this to application builder mode only, you might need to add the 3rd argument for this callback (isApplicationBuilder) and skip/disable the test if that boolean is false.

})
class Hello {}

expect((Hello as any).ɵcmp.template.toString()).not.toContain('jit');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as long as we have a second test case that tests the reverse, it's fine..? That way we can make sure that "jit" appears in one branch and doesn't appear in the other, with aot: true vs aot: false as the only difference. That seems like an okay state to be in for now.

@yjaaidi
Copy link
Author

yjaaidi commented Dec 7, 2024

Thx! No problem at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular-devkit/build-angular detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants