diff --git a/packages/vitest/src/integrations/browser/server.ts b/packages/vitest/src/integrations/browser/server.ts index 0de1069eab1d..3c6d8dba33da 100644 --- a/packages/vitest/src/integrations/browser/server.ts +++ b/packages/vitest/src/integrations/browser/server.ts @@ -14,6 +14,7 @@ export async function createBrowserServer(project: WorkspaceProject, configFile: const configPath = typeof configFile === 'string' ? configFile : false const server = await createServer({ + ...project.options, // spread project config inlined in root workspace config logLevel: 'error', mode: project.config.mode, configFile: configPath, @@ -25,6 +26,7 @@ export async function createBrowserServer(project: WorkspaceProject, configFile: }, }, plugins: [ + ...project.options?.plugins || [], (await import('@vitest/browser')).default(project, '/'), CoverageTransform(project.ctx), { diff --git a/packages/vitest/src/node/workspace.ts b/packages/vitest/src/node/workspace.ts index 8a1a110e1b86..74a18282b5c6 100644 --- a/packages/vitest/src/node/workspace.ts +++ b/packages/vitest/src/node/workspace.ts @@ -25,7 +25,7 @@ interface InitializeProjectOptions extends UserWorkspaceConfig { } export async function initializeProject(workspacePath: string | number, ctx: Vitest, options: InitializeProjectOptions) { - const project = new WorkspaceProject(workspacePath, ctx) + const project = new WorkspaceProject(workspacePath, ctx, options) const configFile = options.extends ? resolve(dirname(options.workspaceConfigPath), options.extends) @@ -78,6 +78,7 @@ export class WorkspaceProject { constructor( public path: string | number, public ctx: Vitest, + public options?: InitializeProjectOptions, ) { } getName(): string { diff --git a/test/workspaces-browser/globalTest.ts b/test/workspaces-browser/globalTest.ts index 960543608678..babae74c9f4e 100644 --- a/test/workspaces-browser/globalTest.ts +++ b/test/workspaces-browser/globalTest.ts @@ -6,9 +6,9 @@ export async function teardown() { try { assert.ok(results.success) - assert.equal(results.numTotalTestSuites, 3) - assert.equal(results.numTotalTests, 3) - assert.equal(results.numPassedTests, 3) + assert.equal(results.numTotalTestSuites, 4) + assert.equal(results.numTotalTests, 5) + assert.equal(results.numPassedTests, 5) } catch (err) { console.error(err) diff --git a/test/workspaces-browser/space_browser_inline/test-alias-to.ts b/test/workspaces-browser/space_browser_inline/test-alias-to.ts new file mode 100644 index 000000000000..c05f09558dda --- /dev/null +++ b/test/workspaces-browser/space_browser_inline/test-alias-to.ts @@ -0,0 +1 @@ +export default 'hello' diff --git a/test/workspaces-browser/space_browser_inline/test/basic.test.ts b/test/workspaces-browser/space_browser_inline/test/basic.test.ts new file mode 100644 index 000000000000..d86a61e2cc16 --- /dev/null +++ b/test/workspaces-browser/space_browser_inline/test/basic.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from 'vitest' + +// @ts-expect-error alias +import testAliasVite from 'test-alias-from-vite' + +// @ts-expect-error alias +import testAliasVitest from 'test-alias-from-vitest' + +test('window is defined', () => { + expect(typeof window).toBe('object') +}) + +test('alias from workspace inline config', () => { + expect(testAliasVite).toBe('hello') + expect(testAliasVitest).toBe('hello') +}) diff --git a/test/workspaces-browser/vitest.workspace.ts b/test/workspaces-browser/vitest.workspace.ts index f6ba42b0e886..1bbb3f765f51 100644 --- a/test/workspaces-browser/vitest.workspace.ts +++ b/test/workspaces-browser/vitest.workspace.ts @@ -2,4 +2,24 @@ import { defineWorkspace } from 'vitest/config' export default defineWorkspace([ './space_*/*.config.ts', + { + test: { + name: 'space_browser_inline', + root: './space_browser_inline', + browser: { + enabled: true, + name: process.env.BROWSER || 'chrome', + headless: true, + provider: process.env.PROVIDER || 'webdriverio', + }, + alias: { + 'test-alias-from-vitest': new URL('./space_browser_inline/test-alias-to.ts', import.meta.url).pathname, + }, + }, + resolve: { + alias: { + 'test-alias-from-vite': new URL('./space_browser_inline/test-alias-to.ts', import.meta.url).pathname, + }, + }, + }, ])