Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(@angular-devkit/build-angular): support karma with application builder #28416

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

Merged
jkrems merged 3 commits into angular:main from jkrems:jk-karma-app-builder
Sep 26, 2024

Conversation

Copy link
Contributor

@jkrems jkrems commented Sep 13, 2024
edited
Loading

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?

ng test for projects that are using Karma has a hard dependency on the webpack builder. Apps can't use application builder features in any files loaded in the tests, really.

Issue Number: N/A

What is the new behavior?

Apps can opt into using the application builder by setting the builderMode for the karma builder to either "application" or "detect". The latter only works if they switched the app to the new builder for their development/production builds. Once they do, we will use the new application builder toolchain to build their tests before running them in Karma.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This PR builds on top of #28479. The "meat" is in the last commit.

  • High level changes
    • Split non-webpack parts of find-tests-plugin.ts into find-tests.ts to ensure we use the same list of test files. The code is otherwise unmodified.
    • Split webpack parts of karma/index.ts into karma/browser_builder.ts. The code is mostly unmodified though moving out the karmaOptions initialization changes the order of operations a bit.
    • To handle custom karma config files, I'm currently force-deleting the old framework plugin from the karma config after loading. An alternative would have been to make the presence of that plugin a hard error instead. The idea was to allow trying it out with --builder-mode=application without changing a project, even in projects that have a karma.config file.
    • For similar reasons I'm currently only warning when transforms.webpackConfiguration is present. This could be made a hard error in the future.
  • The default remains the "browser" builder, at least for now. It may be viable to make "detect" the default in v19 but that seems risky given that this code hasn't seen a whole lot of real life testing.
  • The application builder-based Karma runner supports neither --watch nor --code-coverage. They are likely both necessary to be a full replacement for many teams. I'm planning to implement at least code coverage in a quick-ish follow-up PR.

fh1ch reacted with thumbs up emoji lacolaco and LeonEck reacted with heart emoji
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: build & ci Related the build and CI infrastructure of the project area: @angular-devkit/build-angular labels Sep 13, 2024
@jkrems jkrems force-pushed the jk-karma-app-builder branch 5 times, most recently from ff28211 to 587e845 Compare September 18, 2024 18:15
@jkrems jkrems force-pushed the jk-karma-app-builder branch 5 times, most recently from 9428e8c to c6d1570 Compare September 24, 2024 22:01
@angular-robot angular-robot bot removed the area: build & ci Related the build and CI infrastructure of the project label Sep 24, 2024
@jkrems jkrems force-pushed the jk-karma-app-builder branch 4 times, most recently from 6839c5c to f71e5c8 Compare September 25, 2024 15:08
@jkrems jkrems requested a review from clydin September 25, 2024 15:14
@jkrems jkrems marked this pull request as ready for review September 25, 2024 15:14
@jkrems jkrems added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Sep 25, 2024
In some environments, e.g. containers or in some cases macOS,
headless Chrome may not work with the sandbox enabled. This exposes
an escape hatch to run tests in those environments.
Example use:
```sh
yarn bazel test \
 //packages/angular_devkit/build_angular:build_angular_karma_test \
 --test_env=PUPPETEER_EXECUTABLE_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
 --test_env=CHROME_NO_SANDBOX=1
```
These tests appear to be timing out after 300s somewhat often.
Copy link
Contributor Author

jkrems commented Sep 26, 2024
edited
Loading

(削除) Looks like the test projects hadn't been updated for the polyfill change. Added a commit (c21e889) to explicitly add the localize polyfill to them. (削除ここまで) Turns out that this causes issues with the browser builder. Removing the automatic localize injection will be a follow-up item. Ref: #28245

Adds a new "builderMode" setting for Karma that can be used to switch
between webpack ("browser") and esbuild ("application"). It supports a
third value "detect" that will use the same bundler that's also used for
development builds.
The detect mode is modelled after the logic used for the dev-server builder.
This initial implementation doesn't properly support `--watch` mode or code
coverage.
@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 Sep 26, 2024
@jkrems jkrems merged commit 54594b5 into angular:main Sep 26, 2024
31 checks passed
@jkrems jkrems deleted the jk-karma-app-builder branch September 26, 2024 16:35
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 Oct 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Reviewers

@clydin clydin clydin approved these changes

Assignees
No one assigned
Labels
action: merge The PR is ready for merge by the caretaker 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
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /