Skip to content

Commit

Permalink
Merge branch 'main' into feat-resolveSnapshotPath-context
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Oct 29, 2024
2 parents bbb4d64 + 47d7c0a commit 8014420
Show file tree
Hide file tree
Showing 39 changed files with 664 additions and 593 deletions.
113 changes: 113 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,119 @@ export interface Options {
teardown?: Hook
}
```
After the test case is run, the output structure information is as follows:

```
name hz min max mean p75 p99 p995 p999 rme samples
· normal sorting 6,526,368.12 0.0001 0.3638 0.0002 0.0002 0.0002 0.0002 0.0004 ±1.41% 652638
```
```ts
export interface TaskResult {
/*
* the last error that was thrown while running the task
*/
error?: unknown

/**
* The amount of time in milliseconds to run the benchmark task (cycle).
*/
totalTime: number

/**
* the minimum value in the samples
*/
min: number
/**
* the maximum value in the samples
*/
max: number

/**
* the number of operations per second
*/
hz: number

/**
* how long each operation takes (ms)
*/
period: number

/**
* task samples of each task iteration time (ms)
*/
samples: number[]

/**
* samples mean/average (estimate of the population mean)
*/
mean: number

/**
* samples variance (estimate of the population variance)
*/
variance: number

/**
* samples standard deviation (estimate of the population standard deviation)
*/
sd: number

/**
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
*/
sem: number

/**
* degrees of freedom
*/
df: number

/**
* critical value of the samples
*/
critical: number

/**
* margin of error
*/
moe: number

/**
* relative margin of error
*/
rme: number

/**
* median absolute deviation
*/
mad: number

/**
* p50/median percentile
*/
p50: number

/**
* p75 percentile
*/
p75: number

/**
* p99 percentile
*/
p99: number

/**
* p995 percentile
*/
p995: number

/**
* p999 percentile
*/
p999: number
}
```

### bench.skip

Expand Down
4 changes: 2 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2381,9 +2381,9 @@ Relevant only when using with `shouldAdvanceTime: true`. increment mocked time b
#### fakeTimers.shouldClearNativeTimers

- **Type:** `boolean`
- **Default:** `false`
- **Default:** `true`

Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by default, leading to potentially unexpected behavior if timers existed prior to starting fake timers session.
Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.

### workspace<NonProjectOption /> {#workspace}

Expand Down
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"vue": "^3.5.12"
},
"devDependencies": {
"@iconify-json/carbon": "^1.2.3",
"@iconify-json/carbon": "^1.2.4",
"@iconify-json/logos": "^1.2.3",
"@shikijs/vitepress-twoslash": "^1.22.0",
"@shikijs/vitepress-twoslash": "^1.22.1",
"@unocss/reset": "^0.63.6",
"@vite-pwa/assets-generator": "^0.2.6",
"@vite-pwa/vitepress": "^0.5.3",
"@vitejs/plugin-vue": "^5.1.4",
"https-localhost": "^4.7.1",
"tinyglobby": "^0.2.9",
"tinyglobby": "^0.2.10",
"unocss": "^0.63.6",
"unplugin-vue-components": "^0.27.4",
"vite": "^5.2.8",
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@vitest/monorepo",
"type": "module",
"version": "2.1.3",
"version": "2.1.4",
"private": true,
"packageManager": "[email protected].2",
"packageManager": "[email protected].3",
"description": "Next generation testing framework powered by Vite",
"engines": {
"node": "^18.0.0 || >=20.0.0"
Expand Down Expand Up @@ -38,11 +38,11 @@
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@antfu/ni": "^0.23.0",
"@playwright/test": "^1.48.1",
"@playwright/test": "^1.48.2",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@types/node": "^22.7.9",
"@types/node": "^22.8.1",
"@types/ws": "^8.5.12",
"@vitest/browser": "workspace:*",
"@vitest/coverage-istanbul": "workspace:*",
Expand All @@ -55,12 +55,12 @@
"magic-string": "^0.30.12",
"pathe": "^1.1.2",
"rimraf": "^6.0.1",
"rollup": "^4.24.0",
"rollup": "^4.24.2",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-license": "^3.5.3",
"tinyglobby": "^0.2.9",
"tsx": "^4.19.1",
"tinyglobby": "^0.2.10",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"vite": "^5.4.0",
"vitest": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser",
"type": "module",
"version": "2.1.3",
"version": "2.1.4",
"description": "Browser running for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down Expand Up @@ -89,7 +89,7 @@
"@vitest/mocker": "workspace:*",
"@vitest/utils": "workspace:*",
"magic-string": "^0.30.12",
"msw": "^2.5.0",
"msw": "^2.5.2",
"sirv": "^3.0.0",
"tinyrainbow": "^1.2.0",
"ws": "^8.18.0"
Expand All @@ -107,8 +107,8 @@
"mime": "^4.0.4",
"pathe": "^1.1.2",
"periscopic": "^4.0.2",
"playwright": "^1.48.1",
"playwright-core": "^1.48.1",
"playwright": "^1.48.2",
"playwright-core": "^1.48.2",
"safaridriver": "^0.1.2",
"vitest": "workspace:*",
"webdriverio": "^8.40.6"
Expand Down
51 changes: 1 addition & 50 deletions packages/browser/src/client/channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { MockedModuleSerialized } from '@vitest/mocker'
import type { CancelReason } from '@vitest/runner'
import { getBrowserState } from './utils'

Expand All @@ -23,46 +22,6 @@ export interface IframeViewportEvent {
id: string
}

export interface IframeMockEvent {
type: 'mock'
module: MockedModuleSerialized
}

export interface IframeUnmockEvent {
type: 'unmock'
url: string
}

export interface IframeMockingDoneEvent {
type: 'mock:done' | 'unmock:done'
}

export interface IframeMockFactoryRequestEvent {
type: 'mock-factory:request'
eventId: string
id: string
}

export interface IframeMockFactoryResponseEvent {
type: 'mock-factory:response'
eventId: string
exports: string[]
}

export interface IframeMockFactoryErrorEvent {
type: 'mock-factory:error'
eventId: string
error: any
}

export interface IframeViewportChannelEvent {
type: 'viewport:done' | 'viewport:fail'
}

export interface IframeMockInvalidateEvent {
type: 'mock:invalidate'
}

export interface GlobalChannelTestRunCanceledEvent {
type: 'cancel'
reason: CancelReason
Expand All @@ -74,16 +33,8 @@ export type IframeChannelIncomingEvent =
| IframeViewportEvent
| IframeErrorEvent
| IframeDoneEvent
| IframeMockEvent
| IframeUnmockEvent
| IframeMockFactoryResponseEvent
| IframeMockFactoryErrorEvent
| IframeMockInvalidateEvent

export type IframeChannelOutgoingEvent =
| IframeMockFactoryRequestEvent
| IframeViewportChannelEvent
| IframeMockingDoneEvent
export type IframeChannelOutgoingEvent = never

export type IframeChannelEvent =
| IframeChannelIncomingEvent
Expand Down
15 changes: 0 additions & 15 deletions packages/browser/src/client/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { channel, client } from '@vitest/browser/client'
import { globalChannel, type GlobalChannelIncomingEvent, type IframeChannelEvent, type IframeChannelIncomingEvent } from '@vitest/browser/client'
import { generateHash } from '@vitest/runner/utils'
import { relative } from 'pathe'
import { createModuleMockerInterceptor } from './tester/msw'
import { getUiAPI } from './ui'
import { getBrowserState, getConfig } from './utils'

Expand All @@ -13,7 +12,6 @@ const ID_ALL = '__vitest_all__'
class IframeOrchestrator {
private cancelled = false
private runningFiles = new Set<string>()
private interceptor = createModuleMockerInterceptor()
private iframes = new Map<string, HTMLIFrameElement>()

public async init() {
Expand Down Expand Up @@ -186,19 +184,6 @@ class IframeOrchestrator {
}
break
}
case 'mock:invalidate':
this.interceptor.invalidate()
break
case 'unmock':
await this.interceptor.delete(e.data.url)
break
case 'mock':
await this.interceptor.register(e.data.module)
break
case 'mock-factory:error':
case 'mock-factory:response':
// handled manually
break
default: {
e.data satisfies never

Expand Down
32 changes: 0 additions & 32 deletions packages/browser/src/client/tester/mocker.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
import type { IframeChannelOutgoingEvent, IframeMockFactoryErrorEvent, IframeMockFactoryResponseEvent } from '@vitest/browser/client'
import { channel } from '@vitest/browser/client'
import { ModuleMocker } from '@vitest/mocker/browser'
import { getBrowserState } from '../utils'

export class VitestBrowserClientMocker extends ModuleMocker {
setupWorker() {
channel.addEventListener(
'message',
async (e: MessageEvent<IframeChannelOutgoingEvent>) => {
if (e.data.type === 'mock-factory:request') {
try {
const module = await this.resolveFactoryModule(e.data.id)
const exports = Object.keys(module)
channel.postMessage({
type: 'mock-factory:response',
eventId: e.data.eventId,
exports,
} satisfies IframeMockFactoryResponseEvent)
}
catch (err: any) {
channel.postMessage({
type: 'mock-factory:error',
eventId: e.data.eventId,
error: {
name: err.name,
message: err.message,
stack: err.stack,
},
} satisfies IframeMockFactoryErrorEvent)
}
}
},
)
}

// default "vi" utility tries to access mock context to avoid circular dependencies
public getMockContext() {
return { callstack: null }
Expand Down
Loading

0 comments on commit 8014420

Please sign in to comment.