fix(@angular/cli): use headless option in MCP test tool#32878
fix(@angular/cli): use headless option in MCP test tool#32878cexbrayat 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.
| 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' },
);
});
}|
@alan-agius4 If this PR is of some interest (I'm consistently running into this issue with the MCP, so I hope so ^^) , should I apply the suggestions of the gemini bot? |
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