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

Allow Angular to pass no browsers to Karma #26537

Closed
Nvveen opened this issue Nov 30, 2023 · 5 comments · Fixed by #26611
Closed

Allow Angular to pass no browsers to Karma #26537

Nvveen opened this issue Nov 30, 2023 · 5 comments · Fixed by #26611
Labels
area: @angular-devkit/build-angular devkit/build-angular:karma feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature

Comments

@Nvveen
Copy link

Nvveen commented Nov 30, 2023

Command

test

Description

Karma has a CLI option --no-browsers to allow Karma to open without any connected browsers. This can be achieved in Angular by passing an empty [] array in karma,conf.js. This is useful when running the dev server in a devcontainer, where no display server and instances of browsers are installed. Manually opening a browser with the ports forwarded then runs the tests like normal.
The issue starts when using the built-in Karma config, but passing either "browsers": "", or the CLI flag "--browsers=\"" to ng test. The line at

checks if the browsers option exists, but since the string is empty, the expression is false and the default Karma option of ['Chrome'] is instead used.

Describe the solution you'd like

Changing this line to if (options.browsers != null) and filtering the split array by non-empty strings should solve this particular issue.

Describe alternatives you've considered

No response

@Nvveen
Copy link
Author

Nvveen commented Nov 30, 2023

I am trying to create a PR, but running into issues with building my local fork. yarn build --local fails with TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received an instance of Array and commiting my changes throws an error too, Could not read configuration file at /tmp/angular-cli/.ng-dev/config.mjs., because of a precommit hook.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 30, 2023

@Nvveen, I have seen that error, to build and create an app you can use yarn admin create <app-name>

But in the case we are going to add this feature, the desired implementation would be to allow --no-browser to be passed from the command line, which will not require filtering the array etc...

See:

"index": {
"description": "Configures the generation of the application's HTML index.",
"oneOf": [
{
"type": "string",
"description": "The path of a file to use for the application's HTML index. The filename of the specified path will be used for the generated file and will be created in the root of the application's configured output path."
},
{
"type": "object",
"description": "",
"properties": {
"input": {
"type": "string",
"minLength": 1,
"description": "The path of a file to use for the application's generated HTML index."
},
"output": {
"type": "string",
"minLength": 1,
"default": "index.html",
"description": "The output path of the application's generated HTML index file. The full provided path will be used and will be considered relative to the application's configured output path."
}
},
"required": ["input"]
},
for an example.

@Nvveen
Copy link
Author

Nvveen commented Nov 30, 2023

@Nvveen, I have seen that error, to build and create an app you can use yarn admin create

I can't commit either, because the file in that error's directory is an '.mts' file, haha. Otherwise I'd gladly submit a PR with your approach, if I can manage.

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Dec 1, 2023
Copy link
Contributor

angular-robot bot commented Dec 1, 2023

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Dec 7, 2023
…in karma builder

This commit enables users to disable runnings tests against a browsers. This can be done by using the `--no-browsers` command line flag or setting `browsers` to `false` in the `angular.json`

Closes angular#26537
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Dec 7, 2023
…in karma builder

This commit enables users to disable runnings tests against a browsers. This can be done by using the `--no-browsers` command line flag or setting `browsers` to `false` in the `angular.json`

Closes angular#26537
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Dec 7, 2023
…in karma builder

This commit enables users to disable runnings tests against a browsers. This can be done by using the `--no-browsers` command line flag or setting `browsers` to `false` in the `angular.json`

Closes angular#26537
alan-agius4 added a commit that referenced this issue Dec 7, 2023
…in karma builder

This commit enables users to disable runnings tests against a browsers. This can be done by using the `--no-browsers` command line flag or setting `browsers` to `false` in the `angular.json`

Closes #26537
@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 Jan 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular devkit/build-angular:karma feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature
Projects
None yet
2 participants