Skip to content

Commit 3e93fb3

Browse files
committed
Merge branch 'main' of github.com:vitest-dev/vitest into feat/new-reporter-api
2 parents ebff697 + 5178948 commit 3e93fb3

File tree

38 files changed

+417
-133
lines changed

38 files changed

+417
-133
lines changed

docs/advanced/reporters.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class CustomReporter extends BaseReporter {
3636
Or implement the `Reporter` interface:
3737

3838
```ts [custom-reporter.js]
39-
import { Reporter } from 'vitest/reporters'
39+
import type { Reporter } from 'vitest/node'
4040

4141
export default class CustomReporter implements Reporter {
4242
onCollected() {
@@ -65,9 +65,7 @@ Instead of using the tasks that reporters receive, it is recommended to use the
6565
You can get access to this API by calling `vitest.state.getReportedEntity(runnerTask)`:
6666

6767
```ts twoslash
68-
import type { Vitest } from 'vitest/node'
69-
import type { RunnerTestFile } from 'vitest'
70-
import type { Reporter, TestModule } from 'vitest/reporters'
68+
import type { Reporter, RunnerTestFile, TestModule, Vitest } from 'vitest/node'
7169

7270
class MyReporter implements Reporter {
7371
private vitest!: Vitest

docs/guide/migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ The [`resolveConfig`](/advanced/api/#resolveconfig) is now more useful. Instead
8181

8282
This function is not used internally and exposed exclusively as a public API.
8383

84+
### Cleaned up `vitest/reporters` types <Badge type="danger">API</Badge> {#cleaned-up-vitest-reporters-types}
85+
86+
The `vitest/reporters` entrypoint now only exports reporters implementations and options types. If you need access to `TestCase`/`TestSuite` and other task related types, import them additionally from `vitest/node`.
87+
8488
## Migrating to Vitest 2.0 {#vitest-2}
8589

8690
### Default Pool is `forks`

docs/guide/ui.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ vitest --ui
1818

1919
Then you can visit the Vitest UI at <a href="http://localhost:51204/__vitest__/">`http://localhost:51204/__vitest__/`</a>
2020

21+
::: warning
22+
The UI is interactive and requires a running Vite server, so make sure to run Vitest in `watch` mode (the default). Alternatively, you can generate a static HTML report that looks identical to the Vitest UI by specifying `html` in config's `reporters` option.
23+
:::
24+
2125
<img alt="Vitest UI" img-light src="/ui-1-light.png">
2226
<img alt="Vitest UI" img-dark src="/ui-1-dark.png">
2327

docs/guide/workspace.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default defineConfig({
4444
Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If this glob pattern matches any file it will be considered a Vitest config even if it doesn't have a `vitest` in its name.
4545

4646
::: warning
47-
Vitest does not treat the root `vitest.config` file as a workspace project unless it is explicitly specified in the workspace configuration. Consequently, the root configuration will only influence global options such as `reporters` and `coverage`.
47+
Vitest does not treat the root `vitest.config` file as a workspace project unless it is explicitly specified in the workspace configuration. Consequently, the root configuration will only influence global options such as `reporters` and `coverage`. Note that Vitest will always run certain plugin hooks, like `apply`, `config`, `configResolved` or `configureServer`, specified in the root config file. Vitest also uses the same plugins to execute global setups, workspace files and custom coverage provider.
4848
:::
4949

5050
You can also reference projects with their config files:
@@ -233,7 +233,7 @@ bun test --project e2e --project unit
233233

234234
## Configuration
235235

236-
None of the configuration options are inherited from the root-level config file. You can create a shared config file and merge it with the project config yourself:
236+
None of the configuration options are inherited from the root-level config file, even if the workspace is defined inside that config and not in a separate `vitest.workspace` file. You can create a shared config file and merge it with the project config yourself:
237237

238238
```ts [packages/a/vitest.config.ts]
239239
import { defineProject, mergeConfig } from 'vitest/config'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"devDependencies": {
3939
"@antfu/eslint-config": "^3.11.2",
40-
"@antfu/ni": "^0.23.2",
40+
"@antfu/ni": "^23.2.0",
4141
"@playwright/test": "^1.49.1",
4242
"@rollup/plugin-commonjs": "^28.0.2",
4343
"@rollup/plugin-json": "^6.1.0",

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"magic-string": "^0.30.17",
9595
"msw": "^2.7.0",
9696
"sirv": "^3.0.0",
97-
"tinyrainbow": "^1.2.0",
97+
"tinyrainbow": "^2.0.0",
9898
"ws": "^8.18.0"
9999
},
100100
"devDependencies": {

packages/browser/src/client/tester/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { format, stringify } from 'vitest/utils'
22
import { getConfig } from '../utils'
33
import { rpc } from './rpc'
44

5-
const { Date, console } = globalThis
5+
const { Date, console, performance } = globalThis
66

77
export function setupConsoleLogSpy() {
88
const {
@@ -71,7 +71,7 @@ export function setupConsoleLogSpy() {
7171
if (!(label in timeLabels)) {
7272
sendLog('stderr', `Timer "${label}" does not exist`)
7373
}
74-
else if (start) {
74+
else if (typeof start !== 'undefined') {
7575
const duration = end - start
7676
sendLog('stdout', `${label}: ${duration} ms`)
7777
}

packages/browser/src/node/plugin.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,15 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
245245
}
246246

247247
// since we override the resolution in the esbuild plugin, Vite can no longer optimizer it
248-
// have ?. until Vitest 3.0 for backwards compatibility
248+
const vue = isPackageExists('vitest-browser-vue', fileRoot)
249+
if (vue) {
250+
// we override them in the esbuild plugin so optimizer can no longer intercept it
251+
include.push(
252+
'vitest-browser-vue',
253+
'vitest-browser-vue > @vue/test-utils',
254+
'vitest-browser-vue > @vue/test-utils > @vue/compiler-core',
255+
)
256+
}
249257
const vueTestUtils = isPackageExists('@vue/test-utils', fileRoot)
250258
if (vueTestUtils) {
251259
include.push('@vue/test-utils')
@@ -522,10 +530,10 @@ body {
522530
{
523531
name: 'test-utils-rewrite',
524532
setup(build) {
525-
build.onResolve({ filter: /^@vue\/test-utils$/ }, (args) => {
526-
const _require = getRequire()
527-
// resolve to CJS instead of the browser because the browser version expects a global Vue object
528-
const resolved = _require.resolve(args.path, {
533+
// test-utils: resolve to CJS instead of the browser because the browser version expects a global Vue object
534+
// compiler-core: only CJS version allows slots as strings
535+
build.onResolve({ filter: /^@vue\/(test-utils|compiler-core)$/ }, (args) => {
536+
const resolved = getRequire().resolve(args.path, {
529537
paths: [args.importer],
530538
})
531539
return { path: resolved }

packages/coverage-istanbul/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"istanbul-reports": "^3.1.7",
5454
"magicast": "^0.3.5",
5555
"test-exclude": "^7.0.1",
56-
"tinyrainbow": "^1.2.0"
56+
"tinyrainbow": "^2.0.0"
5757
},
5858
"devDependencies": {
5959
"@types/debug": "^4.1.12",

packages/coverage-v8/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"magicast": "^0.3.5",
6666
"std-env": "^3.8.0",
6767
"test-exclude": "^7.0.1",
68-
"tinyrainbow": "^1.2.0"
68+
"tinyrainbow": "^2.0.0"
6969
},
7070
"devDependencies": {
7171
"@types/debug": "^4.1.12",

0 commit comments

Comments
 (0)