Skip to content

Commit 94a186e

Browse files
authored
fix(ui): render project name consistently (#6329)
1 parent 0b4da69 commit 94a186e

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"typecheck": "tsc -p tsconfig.check.json --noEmit",
3131
"typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt",
3232
"ui:build": "vite build packages/ui",
33-
"ui:dev": "vite packages/ui",
33+
"ui:dev": "npm -C packages/ui run dev:client",
3434
"ui:test": "npm -C packages/ui run test:run",
3535
"test:browser:webdriverio": "pnpm -C test/browser run test:webdriverio",
3636
"test:browser:playwright": "pnpm -C test/browser run test:playwright"

packages/ui/README.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
This package is for UI interface of Vitest.
44

5-
> Work in progress.
6-
75
## Development Setup
86

97
At project root, create terminals with each of the following commands:
108

119
```bash
12-
nr dev
10+
nr ui:dev
1311
```
1412

1513
```bash
1614
nr test --api
1715
```
18-
19-
```bash
20-
nr ui:dev
21-
```

packages/ui/client/components/FileDetails.vue

+20-7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ debouncedWatch(
111111
},
112112
{ debounce: 100, immediate: true },
113113
)
114+
115+
const projectNameColor = computed(() => {
116+
return getProjectNameColor(current.value?.file.projectName)
117+
})
118+
119+
const projectNameTextColor = computed(() => {
120+
switch (projectNameColor.value) {
121+
case 'blue':
122+
case 'green':
123+
case 'magenta':
124+
return 'white'
125+
default:
126+
return 'black'
127+
}
128+
})
114129
</script>
115130

116131
<template>
@@ -127,15 +142,13 @@ debouncedWatch(
127142
<div p="2" h-10 flex="~ gap-2" items-center bg-header border="b base">
128143
<StatusIcon :state="current.result?.state" :mode="current.mode" :failed-snapshot="failedSnapshot" />
129144
<div v-if="isTypecheck" v-tooltip.bottom="'This is a typecheck test. It won\'t report results of the runtime tests'" class="i-logos:typescript-icon" flex-shrink-0 />
130-
<div
145+
<span
131146
v-if="current?.file.projectName"
132-
font-light
133-
op-50
134-
text-sm
135-
:style="{ color: getProjectNameColor(current?.file.projectName) }"
147+
class="rounded-full py-0.5 px-1 text-xs font-light"
148+
:style="{ backgroundColor: projectNameColor, color: projectNameTextColor }"
136149
>
137-
[{{ current?.file.projectName || "" }}]
138-
</div>
150+
{{ current.file.projectName }}
151+
</span>
139152
<div flex-1 font-light op-50 ws-nowrap truncate text-sm>
140153
{{ current?.name }}
141154
</div>

packages/ui/client/components/explorer/ExplorerItem.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const projectNameTextColor = computed(() => {
176176
<div flex items-end gap-2 overflow-hidden>
177177
<div v-if="type === 'file' && typecheck" v-tooltip.bottom="'This is a typecheck test. It won\'t report results of the runtime tests'" class="i-logos:typescript-icon" flex-shrink-0 />
178178
<span text-sm truncate font-light>
179-
<span v-if="type === 'file' && projectName" class="rounded-full p-1 mr-1 text-xs" :style="{ backgroundColor: projectNameColor, color: projectNameTextColor }">
179+
<span v-if="type === 'file' && projectName" class="rounded-full py-0.5 px-1 mr-1 text-xs" :style="{ backgroundColor: projectNameColor, color: projectNameTextColor }">
180180
{{ projectName }}
181181
</span>
182182
<span :text="state === 'fail' ? 'red-500' : ''" v-html="highlighted" />

packages/vitest/src/node/logger.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ export class Logger {
228228

229229
const resolvedUrls = project.browser.vite.resolvedUrls
230230
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]
231+
const provider = project.browser.provider.name
232+
const providerString = provider === 'preview' ? '' : ` by ${provider}`
231233
this.log(
232234
c.dim(
233235
c.green(
234-
` ${output} Browser runner started at ${new URL('/', origin)}`,
236+
` ${output} Browser runner started${providerString} at ${new URL('/', origin)}`,
235237
),
236238
),
237239
)

test/browser/specs/server-url.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ afterEach(() => {
66
})
77

88
test('server-url http', async () => {
9-
const { stdout, stderr } = await runBrowserTests({
9+
const { stdout, stderr, provider } = await runBrowserTests({
1010
root: './fixtures/server-url',
1111
})
1212
expect(stderr).toBe('')
13-
expect(stdout).toContain('Browser runner started at http://localhost:5173/')
13+
expect(stdout).toContain(`Browser runner started by ${provider} at http://localhost:5173/`)
1414
})
1515

1616
test('server-url https', async () => {
1717
process.env.TEST_HTTPS = '1'
18-
const { stdout, stderr } = await runBrowserTests({
18+
const { stdout, stderr, provider } = await runBrowserTests({
1919
root: './fixtures/server-url',
2020
})
2121
expect(stderr).toBe('')
22-
expect(stdout).toContain('Browser runner started at https://localhost:5173/')
22+
expect(stdout).toContain(`Browser runner started by ${provider} at https://localhost:5173/`)
2323
expect(stdout).toContain('Test Files 1 passed')
2424
})

test/browser/specs/utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { UserConfig as ViteUserConfig } from 'vite'
33
import type { UserConfig } from 'vitest'
44
import { runVitest } from '../../test-utils'
55

6-
export const browser = process.env.BROWSER || (process.env.PROVIDER !== 'playwright' ? 'chromium' : 'chrome')
6+
const provider = process.env.PROVIDER || 'playwright'
7+
export const browser = process.env.BROWSER || (provider !== 'playwright' ? 'chromium' : 'chrome')
78

89
export async function runBrowserTests(
910
config?: Omit<UserConfig, 'browser'> & { browser?: Partial<UserConfig['browser']> },
@@ -29,5 +30,5 @@ export async function runBrowserTests(
2930
const passedTests = getPassed(browserResultJson.testResults)
3031
const failedTests = getFailed(browserResultJson.testResults)
3132

32-
return { ...result, browserResultJson, passedTests, failedTests, browser }
33+
return { ...result, browserResultJson, passedTests, failedTests, browser, provider }
3334
}

0 commit comments

Comments
 (0)