Skip to content

feat(@angular/build): support custom Playwright connectOptions for browser unit tests#33655

Open
d3n1el1 wants to merge 1 commit into
angular:mainfrom
d3n1el1:feat/unit-test-playwright-connect-options
Open

feat(@angular/build): support custom Playwright connectOptions for browser unit tests#33655
d3n1el1 wants to merge 1 commit into
angular:mainfrom
d3n1el1:feat/unit-test-playwright-connect-options

Conversation

@d3n1el1

@d3n1el1 d3n1el1 commented Jul 24, 2026

Copy link
Copy Markdown

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

When the browsers option is used, the Vitest unit-test builder constructs its own Playwright browser provider. This overrode any connectOptions (such as a custom wsEndpoint) defined in a user's Vitest configuration file, making it impossible to run browser-based unit tests against a remote or shared Playwright browser server.

Issue Number: #33115

What is the new behavior?

A new connectOptions builder option is now forwarded to the Playwright provider's connectOptions, allowing a custom wsEndpoint (and other Playwright connection settings) to be configured directly from angular.json. The option is ignored, with an informational message, when no browsers are configured, or a non-Playwright provider is used.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

…owser unit tests

When the `browsers` option is used, the Vitest unit-test builder
constructs its own Playwright browser provider. This overrode any
`connectOptions` (such as a custom `wsEndpoint`) defined in a user's
Vitest configuration file, making it impossible to run browser-based
unit tests against a remote or shared Playwright browser server.

A new `connectOptions` builder option is now forwarded to the Playwright
provider's `connectOptions`, allowing a custom `wsEndpoint` (and other
Playwright connection settings) to be configured directly from
`angular.json`. The option is ignored, with an informational message,
when no browsers are configured or a non-Playwright provider is used.

Closes angular#33115
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: @angular/build labels Jul 24, 2026

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

Copy link
Copy Markdown

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 introduces a new connectOptions configuration option to the Angular build unit-test builder, allowing Vitest browser-based tests to connect to a remote or preconfigured Playwright browser server. The changes include schema updates, option normalization, and forwarding these options to the Vitest browser provider, along with comprehensive unit tests. The feedback suggests adding a validation check to ensure connectOptions is only used with the Vitest runner, and resolving a conceptual conflict where both executablePath and connectOptions are configured simultaneously, as they are mutually exclusive in Playwright.

outputFile: options.outputFile,
browsers: browsers?.length ? browsers : undefined,
browserViewport: width && height ? { width, height } : undefined,
connectOptions: options.connectOptions,

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

Similar to the ui and isolate options, connectOptions is only supported when using the Vitest runner (since Karma does not use the Playwright browser provider configured by this builder).

Consider adding a validation check in normalizeOptions to throw an error if connectOptions is provided with a non-Vitest runner:

if (options.connectOptions && runner !== Runner.Vitest) {
  throw new Error('The connectOptions option is only available for the vitest runner.');
}

Comment on lines +363 to +383
it('should forward connectOptions alongside executablePath on per-instance providers', async () => {
const connectOptions = { wsEndpoint: 'ws://localhost:1234/playwright' };
const { browser } = await setupBrowserConfiguration(
['ChromeHeadless'],
undefined,
false,
workspaceRoot,
undefined,
connectOptions,
);

// The per-instance provider should carry both the connect options and the executable path.
expect(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(browser?.instances?.[0]?.provider as any)?.options?.connectOptions,
).toEqual(connectOptions);
expect(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(browser?.instances?.[0]?.provider as any)?.options?.launchOptions?.executablePath,
).toBe('/custom/path/to/chrome');
});

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

This test asserts that executablePath is forwarded alongside connectOptions on per-instance providers. However, since executablePath is a local launch option and connectOptions is for remote connections, they are conceptually mutually exclusive. Playwright ignores launchOptions (including executablePath) when connecting to a remote browser via connectOptions.

To avoid passing redundant/ignored configuration and to simplify the setup, consider disabling the executablePath override in browser-provider.ts when connectOptions is active (e.g., if (executablePath && !connectOptions)), and update this test to assert that executablePath is not applied.

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

Labels

area: @angular/build detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant