Skip to content

Conversation

yjaaidi
Copy link
Contributor

@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
Contributor 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the jit test to make sure jit symbols are there.

...BASE_OPTIONS,
aot: true,
/** Cf. {@link ../builder-mode_spec.ts} */
polyfills: ['zone.js', '@angular/localize/init', 'zone.js/testing'],
Copy link
Contributor 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
Contributor 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
Contributor Author

yjaaidi commented Dec 7, 2024

Thx! No problem at all.

@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jan 9, 2025
@jkrems jkrems self-assigned this Jan 28, 2025
@jkrems
Copy link
Contributor

jkrems commented Feb 4, 2025

Sorry for the delay here. Approved the change but there's a tiny conflict and I don't think I can resolve it without push access to the branch. Can you undo my merge commit (e.g. git reset --hard 48d0a96b53f9464f334248999408aa1c3c597bbf) and then rebase?

@yjaaidi yjaaidi force-pushed the feat/add-aot-option-to-karma branch from 9a723a5 to e46d31e Compare February 12, 2025 17:16
@angular-robot angular-robot bot requested a review from jkrems February 12, 2025 17:17
@jkrems
Copy link
Contributor

jkrems commented Feb 12, 2025

Thanks for the updated test! Can you rebase instead of doing the merge?

Also, given that the base version landed (#29608), I think the commit message could be reworded to be test:.

@yjaaidi yjaaidi force-pushed the feat/add-aot-option-to-karma branch from 83c94a6 to 2322240 Compare February 25, 2025 09:30
@angular-robot angular-robot bot removed the detected: feature PR contains a feature commit label Feb 25, 2025
@yjaaidi yjaaidi changed the title feat: add aot option to karma test: add aot option to karma Feb 25, 2025
@yjaaidi
Copy link
Contributor Author

yjaaidi commented Feb 25, 2025

Thanks for the updated test! Can you rebase instead of doing the merge?

Also, given that the base version landed (#29608), I think the commit message could be reworded to be test:.

Hey @jkrems, sorry for the delay.
I've updated the test, and squash rebased.

'src/aot.spec.ts': `
import { Component } from '@angular/core';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Here and in line 44 is some trailing whitespace.

@jkrems jkrems added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 25, 2025
@jkrems jkrems merged commit 9c1c43b into angular:main Feb 25, 2025
35 checks passed
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular-devkit/build-angular target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants