Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue/4298
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Oct 13, 2023
2 parents 1996100 + 9112cc9 commit e554a36
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/guide/test-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ it('math is hard', ({ skip }) => {

## Extend Test Context

Vitest provides two diffident ways to help you extend the test context.
Vitest provides two different ways to help you extend the test context.

### `test.extend`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/monorepo",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"private": true,
"packageManager": "[email protected]",
"description": "Next generation testing framework powered by Vite",
Expand Down
6 changes: 3 additions & 3 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": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Browser running for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down Expand Up @@ -39,11 +39,11 @@
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"vitest": ">=0.34.0"
"vitest": "^1.0.0-0"
},
"dependencies": {
"estree-walker": "^3.0.3",
"magic-string": "^0.30.1",
"magic-string": "^0.30.4",
"sirv": "^2.0.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/esmInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,6 @@ export function injectVitestModule(code: string, id: string, parse: (code: strin
return {
ast,
code: s.toString(),
map: s.generateMap({ hires: true, source: id }),
map: s.generateMap({ hires: 'boundary', source: id }),
}
}
4 changes: 2 additions & 2 deletions packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/coverage-istanbul",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Istanbul coverage provider for Vitest",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -42,7 +42,7 @@
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"vitest": ">=0.32.0 <1"
"vitest": "^1.0.0-0"
},
"dependencies": {
"istanbul-lib-coverage": "^3.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/coverage-v8/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/coverage-v8",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "V8 coverage provider for Vitest",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -42,7 +42,7 @@
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"vitest": ">=0.32.0 <1"
"vitest": "^1.0.0-0"
},
"dependencies": {
"@ampproject/remapping": "^2.2.1",
Expand All @@ -51,7 +51,7 @@
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^4.0.1",
"istanbul-reports": "^3.1.5",
"magic-string": "^0.30.1",
"magic-string": "^0.30.4",
"picocolors": "^1.0.0",
"std-env": "^3.3.3",
"test-exclude": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function removeViteHelpersFromSourceMaps(source: string | undefined, map: Encode
sourceWithoutHelpers.replaceAll(VITE_EXPORTS_LINE_PATTERN, '\n')

const mapWithoutHelpers = sourceWithoutHelpers.generateMap({
hires: true,
hires: 'boundary',
})

// A merged source map where the first one excludes helpers
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/expect",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Jest's expect matchers as a Chai plugin",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/runner",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Vitest test runner",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/snapshot",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Vitest snapshot manager",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/spy/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/spy",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Lightweight Jest compatible spy implementation",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/ui",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "UI for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down Expand Up @@ -44,7 +44,7 @@
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"vitest": ">=0.30.1 <1"
"vitest": "^1.0.0-0"
},
"dependencies": {
"@vitest/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/utils",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Shared Vitest utility functions",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-node",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Vite as Node.js runtime",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vitest",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Next generation testing framework powered by Vite",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -157,7 +157,7 @@
"chai": "^4.3.10",
"debug": "^4.3.4",
"local-pkg": "^0.4.3",
"magic-string": "^0.30.1",
"magic-string": "^0.30.4",
"pathe": "^1.1.1",
"picocolors": "^1.0.0",
"std-env": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const config = {
watch: !isCI,
globals: false,
environment: 'node' as const,
pool: 'threads',
pool: 'threads' as const,
clearMocks: false,
restoreMocks: false,
mockReset: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { EnhancedSpy, MaybeMocked, MaybeMockedDeep, MaybePartiallyMocked, M
import { fn, isMockFunction, spies, spyOn } from './spy'
import { waitFor, waitUntil } from './wait'

interface VitestUtils {
export interface VitestUtils {
isFakeTimers(): boolean
useFakeTimers(config?: FakeTimerInstallOpts): this
useRealTimers(): this
Expand Down
7 changes: 2 additions & 5 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ export function resolveConfig(
return resolved
}

export function isBrowserEnabled(config: ResolvedConfig) {
if (config.browser?.enabled)
return true

return config.poolMatchGlobs?.length && config.poolMatchGlobs.some(([, pool]) => pool === 'browser')
export function isBrowserEnabled(config: ResolvedConfig): boolean {
return Boolean(config.browser?.enabled)
}
5 changes: 3 additions & 2 deletions packages/vitest/src/node/hoistMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ function transformImportSpecifiers(node: ImportDeclaration) {
}

const regexpHoistable = /^[ \t]*\b(vi|vitest)\s*\.\s*(mock|unmock|hoisted)\(/m
const regexpAssignedHoisted = /=[ \t]*(\bawait|)[ \t]*\b(vi|vitest)\s*\.\s*hoisted\(/
const hashbangRE = /^#!.*\n/

export function hoistMocks(code: string, id: string, parse: (code: string, options: any) => AcornNode) {
const hasMocks = regexpHoistable.test(code)
const hasMocks = regexpHoistable.test(code) || regexpAssignedHoisted.test(code)

if (!hasMocks)
return
Expand Down Expand Up @@ -187,6 +188,6 @@ export function hoistMocks(code: string, id: string, parse: (code: string, optio
return {
ast,
code: s.toString(),
map: s.generateMap({ hires: true, source: id }),
map: s.generateMap({ hires: 'boundary', source: id }),
}
}
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/ssrReplacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function SsrReplacerPlugin(): Plugin {
return {
code: s.toString(),
map: s.generateMap({
hires: true,
hires: 'boundary',

// Remove possible query parameters, e.g. vue's "?vue&type=script&src=true&lang.ts"
source: cleanUrl(id),
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function createPool(ctx: Vitest): ProcessPool {

function getPoolName([project, file]: WorkspaceSpec) {
for (const [glob, pool] of project.config.poolMatchGlobs || []) {
if (pool === 'browser')
if ((pool as Pool) === 'browser')
throw new Error('Since Vitest 0.31.0 "browser" pool is not supported in "poolMatchGlobs". You can create a workspace to run some of your tests in browser in parallel. Read more: https://vitest.dev/guide/workspace')
if (mm.isMatch(file, glob, { cwd: project.config.root }))
return pool as Pool
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export interface InlineConfig {
*
* @default 'threads'
*/
pool?: Omit<Pool, 'browser'>
pool?: Exclude<Pool, 'browser'>

/**
* Pool options
Expand All @@ -314,7 +314,7 @@ export interface InlineConfig {
* // ...
* ]
*/
poolMatchGlobs?: [string, Omit<Pool, 'browser'>][]
poolMatchGlobs?: [string, Exclude<Pool, 'browser'>][]

/**
* Update snapshot
Expand Down Expand Up @@ -704,7 +704,7 @@ export interface UserConfig extends InlineConfig {
shard?: string
}

export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions'> {
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions' | 'pool'> {
mode: VitestRunMode

base?: string
Expand Down
4 changes: 2 additions & 2 deletions packages/web-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/web-worker",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Web Worker support for testing in Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down Expand Up @@ -41,7 +41,7 @@
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"vitest": ">=0.34.0"
"vitest": "^1.0.0-0"
},
"dependencies": {
"debug": "^4.3.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/ws-client",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "WebSocket client wrapper for communicating with Vitest",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand Down
Loading

0 comments on commit e554a36

Please sign in to comment.