Skip to content

Commit

Permalink
fix: spread all InitializeProjectOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 13, 2024
1 parent eeaeaa5 commit aff160d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/vitest/src/integrations/browser/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import { createServer } from 'vite'
import { defaultBrowserPort } from '../../constants'
import { resolveApiServerConfig } from '../../node/config'
import { CoverageTransform } from '../../node/plugins/coverageTransform'
import type { WorkspaceProject } from '../../node/workspace'
import type { InitializeProjectOptions, WorkspaceProject } from '../../node/workspace'
import { MocksPlugin } from '../../node/plugins/mocks'
import { resolveFsAllow } from '../../node/plugins/utils'

export async function createBrowserServer(project: WorkspaceProject, configFile: string | undefined) {
export async function createBrowserServer(project: WorkspaceProject, configFile: string | undefined, options?: InitializeProjectOptions) {
const root = project.config.root

await project.ctx.packageInstaller.ensureInstalled('@vitest/browser', root)

const configPath = typeof configFile === 'string' ? configFile : false

const server = await createServer({
...options,
logLevel: 'error',
mode: project.config.mode,
// test config can be inlined in root workspace config without dedicated vite/vitest configFile for this project
test: project.config,
configFile: configPath,
// watch is handled by Vitest
server: {
Expand All @@ -27,6 +26,7 @@ export async function createBrowserServer(project: WorkspaceProject, configFile:
},
},
plugins: [
...options?.plugins || [],
(await import('@vitest/browser')).default(project, '/'),
CoverageTransform(project.ctx),
{
Expand Down
7 changes: 4 additions & 3 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import type { GlobalSetupFile } from './globalSetup'
import { loadGlobalSetupFiles } from './globalSetup'
import { divider } from './reporters/renderers/utils'

interface InitializeProjectOptions extends UserWorkspaceConfig {
export interface InitializeProjectOptions extends UserWorkspaceConfig {
workspaceConfigPath: string
extends?: string
}

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 Expand Up @@ -271,7 +272,7 @@ export class WorkspaceProject {
if (!this.isBrowserEnabled())
return
await this.browser?.close()
this.browser = await createBrowserServer(this, configFile)
this.browser = await createBrowserServer(this, configFile, this.options)
}

static createBasicProject(ctx: Vitest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ test('window is defined', () => {
})

test('"defined" from workspace inline config', () => {
// TODO
// expect(typeof TEST_DEIFNE).toBe("string")
// @ts-expect-error vite define
expect(TEST_DEFINE).toBe('hello')
})
2 changes: 1 addition & 1 deletion test/workspaces-browser/vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineWorkspace([
},
},
define: {
TEST_DEIFNE: 'hello',
TEST_DEFINE: '"hello"',
},
},
])

0 comments on commit aff160d

Please sign in to comment.