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(@schematics/angular): add configuration files generation schematic #24458

Merged
merged 2 commits into from Jan 3, 2023

Conversation

alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Dec 20, 2022

This commits add a schematic to generate Karma and Browserlist files which since version 15 are no longer generated by default. This schematic should be used to generate these files when further customisation is needed.

Usage

ng generate config karma
ng generate config browserlist

Closes #24294

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Dec 20, 2022
@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Dec 20, 2022
@nicojs
Copy link
Contributor

nicojs commented Dec 20, 2022

As far as I can see, this doesn't close #24294. Tools like the IntelliJ karma plugin and StrykerJS are still unable to auto-discover the config. 🤷‍♀️

@alan-agius4
Copy link
Collaborator Author

As far as I can see, this doesn't close #24294. Tools like the IntelliJ karma plugin and StrykerJS are still unable to auto-discover the config. 🤷‍♀️

How would these plugins auto discover the config if present in node_modules? You would still need to create a karma.conf.js in the project.

@nicojs
Copy link
Contributor

nicojs commented Dec 20, 2022

With my change, a tool could use require('@angular-devkit/build-angular/src/builders/karma/karma.conf.js') to import the karma config and use that to configure karma from their own config file.

@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Dec 21, 2022
@alan-agius4 alan-agius4 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 Dec 21, 2022
@alan-agius4 alan-agius4 force-pushed the ng-config-schematic branch 2 times, most recently from d243f52 to 431eeb0 Compare December 21, 2022 14:51
This commits add a schematic to generate Karma and Browserlist files which since version 15 are no longer generated by default. This schematic should be used to generate these files when further customisation is needed.

Usage
```
ng generate config karma
ng generate config browserlist
```

Closes angular#24294
…m built-in karma config

Remove options that match the Karma defaults from the built-in karma config
@nicojs
Copy link
Contributor

nicojs commented Dec 21, 2022

Could we at least export a factory method for configuring karma?

@alan-agius4
Copy link
Collaborator Author

Could we at least export a factory method for configuring karma?

You can use the builder API to transform the built in option

karmaOptions?: (options: KarmaConfigOptions) => KarmaConfigOptions;

A karma config on its own without the builder is not that useful as karma requires the output of the webpack builder which is done when running ng test in addition some of the karma plugins requires to run with an Angular CLI context.

@nicojs
Copy link
Contributor

nicojs commented Dec 22, 2022

Ah, I understand the confusion. Please let me elaborate.

StrykerJS (and the IntelliJ plugin) discover whether the current project is an Angular or a regular Karma project. If it is an Angular project, it uses ng test --karma-config=/path/to/stryker/karma.conf.js to start karma. This makes sure that webpack and such are correctly started.

The karma config file ("/path/to/stryker/karma.conf.js") provided is a custom karma config file crafted in StrykerJS. From that config file, we load your local karma.conf.js. Since Angular 15, this file is no longer generated; thus, we need a new way to load the angular karma config. I was hoping something like this: #24458 (comment)

This is the part of the StrykerJS code that uses ng test:
https://github.com/stryker-mutator/stryker-js/blob/8bf885f490de6625466a011dc79cf04d53aeb698/packages/karma-runner/src/starters/angular-starter.ts#L30-L51

@angular-robot angular-robot bot merged commit 67773bd into angular:main Jan 3, 2023
@alan-agius4 alan-agius4 deleted the ng-config-schematic branch January 4, 2023 11:09
@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 Feb 4, 2023
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 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.

Expose the built-in karma config.
3 participants