fix(@angular/cli): use headless option in MCP test tool#32878
Open
cexbrayat wants to merge 1 commit intoangular:mainfrom
Open
fix(@angular/cli): use headless option in MCP test tool#32878cexbrayat wants to merge 1 commit intoangular:mainfrom
cexbrayat wants to merge 1 commit intoangular:mainfrom
Conversation
This avoids the following error for projects using Vitest and Browser mode: ``` Unhandled Error: Error: [(chrome)] Browser "chrome" is not supported by the browser provider "playwright". Supported browsers: firefox, webkit, chromium. ```
There was a problem hiding this comment.
Code Review
This pull request updates the test tool to support the --headless option for the @angular/build:unit-test builder, specifically for Vitest-based projects, while preserving ChromeHeadless for Karma. It includes logic to detect the builder type, updated documentation, and new unit tests. Feedback suggests refactoring the added tests into a parameterized format to reduce duplication.
Comment on lines
+97
to
+131
| it('should use the headless option for the unit-test builder when using Vitest', async () => { | ||
| addProjectToWorkspace(mockContext.workspace.projects, 'my-vitest-app', { | ||
| test: { | ||
| builder: '@angular/build:unit-test', | ||
| options: { | ||
| runner: 'vitest', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await runTest({ project: 'my-vitest-app' }, mockContext); | ||
|
|
||
| expect(mockHost.runCommand).toHaveBeenCalledWith( | ||
| 'ng', | ||
| ['test', 'my-vitest-app', '--headless', 'true', '--watch', 'false'], | ||
| { cwd: '/test' }, | ||
| ); | ||
| }); | ||
|
|
||
| it('should use the headless option for the unit-test builder when the runner is omitted', async () => { | ||
| addProjectToWorkspace(mockContext.workspace.projects, 'my-default-vitest-app', { | ||
| test: { | ||
| builder: '@angular/build:unit-test', | ||
| options: {}, | ||
| }, | ||
| }); | ||
|
|
||
| await runTest({ project: 'my-default-vitest-app' }, mockContext); | ||
|
|
||
| expect(mockHost.runCommand).toHaveBeenCalledWith( | ||
| 'ng', | ||
| ['test', 'my-default-vitest-app', '--headless', 'true', '--watch', 'false'], | ||
| { cwd: '/test' }, | ||
| ); | ||
| }); |
There was a problem hiding this comment.
These two new test cases are very similar and contain duplicated logic. To improve maintainability and reduce redundancy, you could consider parameterizing them. This can be done by defining the test cases in an array and iterating over them to create the it blocks dynamically.
const testCases = [
{
description: 'when using Vitest',
projectName: 'my-vitest-app',
options: { runner: 'vitest' },
},
{
description: 'when the runner is omitted',
projectName: 'my-default-vitest-app',
options: {},
},
];
for (const { description, projectName, options } of testCases) {
it('should use the headless option for the unit-test builder ' + description, async () => {
addProjectToWorkspace(mockContext.workspace.projects, projectName, {
test: {
builder: '@angular/build:unit-test',
options,
},
});
await runTest({ project: projectName }, mockContext);
expect(mockHost.runCommand).toHaveBeenCalledWith(
'ng',
['test', projectName, '--headless', 'true', '--watch', 'false'],
{ cwd: '/test' },
);
});
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the new behavior?
This avoids the following error for projects using Vitest and Browser mode:
Does this PR introduce a breaking change?
Other information