Skip to content

Commit 626f76e

Browse files
committed
feat(@angular/build): run vitest browser with playwright with OS theme
1 parent ede86e8 commit 626f76e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/angular/build/src/builders/unit-test/runners/vitest/browser-provider.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ export async function setupBrowserConfiguration(
9999
launchOptions: {
100100
executablePath: process.env.CHROME_BIN,
101101
},
102+
contextOptions: {
103+
// Enables `prefer-color-scheme` for Vitest browser instead of `light`
104+
colorScheme: null,
105+
},
106+
});
107+
} else if (providerName === 'playwright') {
108+
provider = providerFactory({
109+
contextOptions: {
110+
// Enables `prefer-color-scheme` for Vitest browser instead of `light`
111+
colorScheme: null,
112+
},
102113
});
103114
} else {
104115
provider = providerFactory();

packages/angular/build/src/builders/unit-test/runners/vitest/browser-provider_spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('setupBrowserConfiguration', () => {
2828
);
2929
await writeFile(
3030
join(playwrightPkgPath, 'index.js'),
31-
'module.exports = { playwright: () => ({ name: "playwright" }) };',
31+
'module.exports = { playwright: (options) => ({ name: "playwright", options }) };',
3232
);
3333
});
3434

@@ -135,6 +135,23 @@ describe('setupBrowserConfiguration', () => {
135135
}
136136
});
137137

138+
// See: https://github.com/angular/angular-cli/issues/32469
139+
it('should pass colorScheme=null to Playwright provider', async () => {
140+
const { browser } = await setupBrowserConfiguration(
141+
['ChromeHeadless'],
142+
undefined,
143+
false,
144+
workspaceRoot,
145+
undefined,
146+
);
147+
148+
expect(browser?.provider?.options).toEqual(jasmine.objectContaining({
149+
contextOptions: jasmine.objectContaining({
150+
colorScheme: null,
151+
}),
152+
}));
153+
});
154+
138155
it('should support Preview provider forcing headless false', async () => {
139156
// Create mock preview package
140157
const previewPkgPath = join(workspaceRoot, 'node_modules/@vitest/browser-preview');

0 commit comments

Comments
 (0)