Skip to content

Commit

Permalink
fix(browser): apply inlined workspace config to browser mode vite ser…
Browse files Browse the repository at this point in the history
…ver (#4947)
  • Loading branch information
hi-ogawa authored Jan 15, 2024
1 parent 4b41131 commit db01f6c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/vitest/src/integrations/browser/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +26,7 @@ export async function createBrowserServer(project: WorkspaceProject, configFile:
},
},
plugins: [
...project.options?.plugins || [],
(await import('@vitest/browser')).default(project, '/'),
CoverageTransform(project.ctx),
{
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,6 +78,7 @@ export class WorkspaceProject {
constructor(
public path: string | number,
public ctx: Vitest,
public options?: InitializeProjectOptions,
) { }

getName(): string {
Expand Down
6 changes: 3 additions & 3 deletions test/workspaces-browser/globalTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'hello'
16 changes: 16 additions & 0 deletions test/workspaces-browser/space_browser_inline/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
20 changes: 20 additions & 0 deletions test/workspaces-browser/vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
])

0 comments on commit db01f6c

Please sign in to comment.