Skip to content

fix(@angular/cli): use headless option in MCP test tool#32878

Open
cexbrayat wants to merge 1 commit intoangular:mainfrom
cexbrayat:fix/text-mcp
Open

fix(@angular/cli): use headless option in MCP test tool#32878
cexbrayat wants to merge 1 commit intoangular:mainfrom
cexbrayat:fix/text-mcp

Conversation

@cexbrayat
Copy link
Copy Markdown
Member

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 new behavior?

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.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

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.
```
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' },
);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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' },
      );
    });
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant