Skip to content

Commit

Permalink
chore: always show workspace name
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 8, 2023
1 parent f85088c commit bde49db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/vitest/src/node/core.ts
Expand Up @@ -50,6 +50,8 @@ export class Vitest {
restartsCount = 0
runner: ViteNodeRunner = undefined!

private coreWorkspace!: VitestWorkspace

public workspaces: VitestWorkspace[] = []
private workspacesTestFiles = new Map<string, Set<VitestWorkspace>>()

Expand Down Expand Up @@ -138,9 +140,16 @@ export class Vitest {
runner: this.runner,
server: this.vitenode,
})
this.coreWorkspace = coreWorkspace
return coreWorkspace
}

public getCoreWorkspace() {
if (!this.coreWorkspace)
throw new Error('Core workspace not initialized')
return this.coreWorkspace
}

private async resolveWorkspaces(options: UserConfig) {
const rootFiles = await fs.readdir(this.config.root)
const workspacesConfigPath = workspacesFiles.find((configFile) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/logger.ts
Expand Up @@ -113,7 +113,7 @@ export class Logger {
if (!workspace.browser)
return
const name = workspace.getName()
const output = (name === this.ctx.config.root || name === this.ctx.config.name) ? '' : ` [${name}]`
const output = workspace.isCore() ? '' : ` [${name}]`

this.log(c.dim(c.green(` ${output} Browser runner started at http://${workspace.config.browser.api?.host || 'localhost'}:${c.bold(`${workspace.browser.config.server.port}`)}`)))
})
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/node/plugins/workspace.ts
@@ -1,4 +1,4 @@
import { relative } from 'pathe'
import { dirname, relative } from 'pathe'
import type { UserConfig as ViteConfig, Plugin as VitePlugin } from 'vite'
import { configDefaults } from '../../defaults'
import { generateScopedClassName } from '../../integrations/css/css-modules'
Expand All @@ -11,6 +11,7 @@ import { GlobalSetupPlugin } from './globalSetup'

interface WorkspaceOptions {
root: string
workspacePath: string
}

export function WorkspaceVitestPlugin(workspace: VitestWorkspace, options: WorkspaceOptions) {
Expand Down Expand Up @@ -89,6 +90,7 @@ export function WorkspaceVitestPlugin(workspace: VitestWorkspace, options: Works
},
test: {
env,
name: testConfig.name || dirname(options.workspacePath).split('/').pop(),
},
}

Expand Down
10 changes: 7 additions & 3 deletions packages/vitest/src/node/workspace.ts
Expand Up @@ -29,12 +29,12 @@ export async function initializeWorkspace(workspacePath: string, ctx: Vitest) {
const root = dirname(workspacePath)

const config: ViteInlineConfig = {
root: dirname(workspacePath),
root,
logLevel: 'error',
configFile,
// this will make "mode" = "test" inside defineConfig
mode: ctx.config.mode || process.env.NODE_ENV,
plugins: WorkspaceVitestPlugin(workspace, { root }),
plugins: WorkspaceVitestPlugin(workspace, { root, workspacePath }),
}

const server = await createServer(config)
Expand Down Expand Up @@ -67,7 +67,11 @@ export class VitestWorkspace {
) { }

getName() {
return this.config.name || dirname(this.path)
return this.config.name
}

isCore() {
return this.ctx.getCoreWorkspace() === this
}

get reporters() {
Expand Down

0 comments on commit bde49db

Please sign in to comment.