From 64c3ec74f7ac410506f366ed2044973256e7c8e2 Mon Sep 17 00:00:00 2001 From: dsyddall Date: Wed, 29 Nov 2023 09:31:06 +0000 Subject: [PATCH 01/11] docs(api): add docs for describe.runIf (#4536) --- docs/api/index.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/api/index.md b/docs/api/index.md index 3baca17aad45..bd3c438976b3 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -598,8 +598,8 @@ import { describe, test } from 'vitest' const isDev = process.env.NODE_ENV === 'development' -describe.skipIf(isDev)('prod only test', () => { - // this test only runs in production +describe.skipIf(isDev)('prod only test suite', () => { + // this test suite only runs in production }) ``` @@ -607,6 +607,26 @@ describe.skipIf(isDev)('prod only test', () => { You cannot use this syntax when using Vitest as [type checker](/guide/testing-types). ::: +### describe.runIf + +- **Type:** `(condition: any) => void` + +Opposite of [describe.skipIf](#describe-skipif). + +```ts +import { assert, test } from 'vitest' + +const isDev = process.env.NODE_ENV === 'development' + +describe.runIf(isDev)('dev only test suite', () => { + // this test suite only runs in development +}) +``` + +::: warning +You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types). +::: + ### describe.only - **Type:** `(name: string | Function, fn: TestFunction, options?: number | TestOptions) => void` From 2ff35330b223ec915dc7d7df7670aba305ca9457 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 29 Nov 2023 10:34:58 +0100 Subject: [PATCH 02/11] docs: add section about mocking methods inside the same file (#4611) Co-authored-by: Anjorin Damilare --- docs/guide/mocking.md | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docs/guide/mocking.md b/docs/guide/mocking.md index e3d0783d119a..a47079c39faf 100644 --- a/docs/guide/mocking.md +++ b/docs/guide/mocking.md @@ -168,6 +168,62 @@ The following principles apply * All objects will be deeply cloned * All instances of classes and their prototypes will be deeply cloned +### Mocking Pitfalls + +Beware that it is not possible to mock calls to methods that are called inside other methods of the same file. For example, in this code: + +```ts +export function foo() { + return 'foo' +} + +export function foobar() { + return `${foo()}bar` +} +``` + +It is not possible to mock the `foo` method from the outside because it is referenced directly. So this code will have no effect on the `foo` call inside `foobar` (but it will affect the `foo` call in other modules): + +```ts +import { vi } from 'vitest' +import * as mod from './foobar.js' + +// this will only affect "foo" outside of the original module +vi.spyOn(mod, 'foo') +vi.mock('./foobar.js', async (importOriginal) => { + return { + ...await importOriginal(), + // this will only affect "foo" outside of the original module + foo: () => 'mocked' + } +}) +``` + +You can confirm this behaviour by providing the implementation to the `foobar` method directly: + +```ts +// foobar.test.js +import * as mod from './foobar.js' + +vi.spyOn(mod, 'foo') + +// exported foo references mocked method +mod.foobar(mod.foo) +``` + +```ts +// foobar.js +export function foo() { + return 'foo' +} + +export function foobar(injectedFoo) { + return injectedFoo !== foo // false +} +``` + +This is the intended behaviour. It is usually a sign of bad code when mocking is involved in such a manner. Consider refactoring your code into multiple files or improving your application architecture by using techniques such as [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection). + ### Example ```js From ec3d6949eb12b2b57ab6aeef920f6697d5e6a8a1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 29 Nov 2023 14:30:59 +0100 Subject: [PATCH 03/11] fix(browser): don't go into an infinite reload loop, don't fail if "error" event is caught (#4618) --- packages/browser/src/client/main.ts | 59 ++++++++++++++++++++++++---- packages/browser/src/client/utils.ts | 20 +--------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/packages/browser/src/client/main.ts b/packages/browser/src/client/main.ts index 94a279c3829c..1e8420e0867b 100644 --- a/packages/browser/src/client/main.ts +++ b/packages/browser/src/client/main.ts @@ -22,6 +22,7 @@ const browserHashMap = new Map() const url = new URL(location.href) const testId = url.searchParams.get('id') || 'unknown' +const reloadTries = Number(url.searchParams.get('reloadTries') || '0') function getQueryPaths() { return url.searchParams.getAll('path') @@ -62,21 +63,51 @@ function on(event: string, listener: (...args: any[]) => void) { return () => window.removeEventListener(event, listener) } -// we can't import "processError" yet because error might've been thrown before the module was loaded -async function defaultErrorReport(type: string, unhandledError: any) { - const error = { +function serializeError(unhandledError: any) { + return { ...unhandledError, name: unhandledError.name, message: unhandledError.message, - stack: unhandledError.stack, + stack: String(unhandledError.stack), } +} + +// we can't import "processError" yet because error might've been thrown before the module was loaded +async function defaultErrorReport(type: string, unhandledError: any) { + const error = serializeError(unhandledError) if (testId !== 'no-isolate') error.VITEST_TEST_PATH = testId await client.rpc.onUnhandledError(error, type) await client.rpc.onDone(testId) } -const stopErrorHandler = on('error', e => defaultErrorReport('Error', e.error)) +function catchWindowErrors(cb: (e: ErrorEvent) => void) { + let userErrorListenerCount = 0 + function throwUnhandlerError(e: ErrorEvent) { + if (userErrorListenerCount === 0 && e.error != null) + cb(e) + else + console.error(e.error) + } + const addEventListener = window.addEventListener.bind(window) + const removeEventListener = window.removeEventListener.bind(window) + window.addEventListener('error', throwUnhandlerError) + window.addEventListener = function (...args: Parameters) { + if (args[0] === 'error') + userErrorListenerCount++ + return addEventListener.apply(this, args) + } + window.removeEventListener = function (...args: Parameters) { + if (args[0] === 'error' && userErrorListenerCount) + userErrorListenerCount-- + return removeEventListener.apply(this, args) + } + return function clearErrorHandlers() { + window.removeEventListener('error', throwUnhandlerError) + } +} + +const stopErrorHandler = catchWindowErrors(e => defaultErrorReport('Error', e.error)) const stopRejectionHandler = on('unhandledrejection', e => defaultErrorReport('Unhandled Rejection', e.reason)) let runningTests = false @@ -100,15 +131,27 @@ ws.addEventListener('open', async () => { const { getSafeTimers } = await importId('vitest/utils') as typeof import('vitest/utils') safeRpc = createSafeRpc(client, getSafeTimers) } - catch (err) { - location.reload() + catch (err: any) { + if (reloadTries >= 10) { + const error = serializeError(new Error('Vitest failed to load "vitest/utils" after 10 retries.')) + error.cause = serializeError(err) + + await client.rpc.onUnhandledError(error, 'Reload Error') + await client.rpc.onDone(testId) + return + } + + const tries = reloadTries + 1 + const newUrl = new URL(location.href) + newUrl.searchParams.set('reloadTries', String(tries)) + location.href = newUrl.href return } stopErrorHandler() stopRejectionHandler() - on('error', event => reportUnexpectedError(safeRpc, 'Error', event.error)) + catchWindowErrors(event => reportUnexpectedError(safeRpc, 'Error', event.error)) on('unhandledrejection', event => reportUnexpectedError(safeRpc, 'Unhandled Rejection', event.reason)) // @ts-expect-error untyped global for internal use diff --git a/packages/browser/src/client/utils.ts b/packages/browser/src/client/utils.ts index b79f353d319e..27a390af601d 100644 --- a/packages/browser/src/client/utils.ts +++ b/packages/browser/src/client/utils.ts @@ -1,23 +1,5 @@ -// it's possible that import was not optimized yet -async function tryImport(id: string, tries = 20): Promise { - try { - return await import(id) - } - catch (cause) { - if (tries <= 0) { - location.reload() - throw new Error(`Failed to import ${id}.`, { cause }) - } - - await new Promise(resolve => setTimeout(resolve, 0)) - return await tryImport(id, tries - 1) - } -} - export async function importId(id: string) { const name = `/@id/${id}` - // TODO: this import _should_ always work, but sometimes it doesn't - // this is a workaround until we can properly debug it - maybe server is not ready? // @ts-expect-error mocking vitest apis - return __vi_wrap_module__(tryImport(name)) + return __vi_wrap_module__(import(name)) } From f7a73338a552e5479a0f383cba8f761351552201 Mon Sep 17 00:00:00 2001 From: Philipp Rudloff Date: Wed, 29 Nov 2023 14:31:18 +0100 Subject: [PATCH 04/11] feat(expect): compare URL objects by href (#4615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ari Perkkiƶ --- packages/expect/src/jest-utils.ts | 3 +++ test/core/test/jest-expect.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/expect/src/jest-utils.ts b/packages/expect/src/jest-utils.ts index fa9206bcbfd2..63aa295b5a20 100644 --- a/packages/expect/src/jest-utils.ts +++ b/packages/expect/src/jest-utils.ts @@ -96,6 +96,9 @@ function eq( if (a instanceof Error && b instanceof Error) return a.message === b.message + if (a instanceof URL && b instanceof URL) + return a.href === b.href + if (Object.is(a, b)) return true diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 1e92701e2055..4f78f9b8e1cd 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -51,6 +51,18 @@ describe('jest-expect', () => { expect(new Date(0)).toEqual(new Date(0)) expect(new Date('inValId')).toEqual(new Date('inValId')) + expect(new Error('message')).toEqual(new Error('message')) + expect(new Error('message')).not.toEqual(new Error('different message')) + + expect(new URL('https://example.org')).toEqual(new URL('https://example.org')) + expect(new URL('https://example.org')).not.toEqual(new URL('https://different-example.org')) + expect(new URL('https://example.org?query=value')).toEqual(new URL('https://example.org?query=value')) + expect(new URL('https://example.org?query=one')).not.toEqual(new URL('https://example.org?query=two')) + expect(new URL('https://subdomain.example.org/path?query=value#fragment-identifier')).toEqual(new URL('https://subdomain.example.org/path?query=value#fragment-identifier')) + expect(new URL('https://subdomain.example.org/path?query=value#fragment-identifier')).not.toEqual(new URL('https://subdomain.example.org/path?query=value#different-fragment-identifier')) + expect(new URL('https://example.org/path')).toEqual(new URL('/path', 'https://example.org')) + expect(new URL('https://example.org/path')).not.toEqual(new URL('/path', 'https://example.com')) + expect(BigInt(1)).toBeGreaterThan(BigInt(0)) expect(1).toBeGreaterThan(BigInt(0)) expect(BigInt(1)).toBeGreaterThan(0) From e0e20176cd6c93988727ae2c9883fead23d2d39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Thu, 30 Nov 2023 17:09:20 +0200 Subject: [PATCH 05/11] perf: close pool early in run-mode (#4623) --- packages/vitest/src/node/core.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index bc36be4c30d3..58d1a1903d0c 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -10,7 +10,7 @@ import { ViteNodeRunner } from 'vite-node/client' import { SnapshotManager } from '@vitest/snapshot/manager' import type { CancelReason, File } from '@vitest/runner' import { ViteNodeServer } from 'vite-node/server' -import type { ArgumentsType, CoverageProvider, OnServerRestartHandler, Reporter, ResolvedConfig, UserConfig, UserWorkspaceConfig, VitestRunMode } from '../types' +import type { ArgumentsType, Awaitable, CoverageProvider, OnServerRestartHandler, Reporter, ResolvedConfig, UserConfig, UserWorkspaceConfig, VitestRunMode } from '../types' import { hasFailed, noop, slash, toArray } from '../utils' import { getCoverageProvider } from '../integrations/coverage' import type { BrowserProvider } from '../types/browser' @@ -76,6 +76,7 @@ export class Vitest { private _onClose: (() => Awaited)[] = [] private _onSetServer: OnServerRestartHandler[] = [] private _onCancelListeners: ((reason: CancelReason) => Promise | void)[] = [] + private _poolClosePromise?: Awaitable async setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig) { this.unregisterWatcher?.() @@ -357,6 +358,10 @@ export class Vitest { await this.runFiles(files) } + // In run mode close pool as early as possible + if (!this.config.watch && this.pool?.close) + this._poolClosePromise = this.pool.close() + await this.reportCoverage(true) if (this.config.watch) @@ -780,7 +785,9 @@ export class Vitest { if (this.pool) { closePromises.push((async () => { - await this.pool?.close?.() + await (this._poolClosePromise || this.pool?.close?.()) + + this._poolClosePromise = undefined this.pool = undefined })()) } From 723f65b9b20dbda37522f73b0f8ff691d8bd1251 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 30 Nov 2023 19:48:48 +0100 Subject: [PATCH 06/11] fix(browser): respect "server" option in vite config (#4627) --- packages/vitest/src/integrations/browser/server.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/integrations/browser/server.ts b/packages/vitest/src/integrations/browser/server.ts index 84a12a8ce157..2485b2fe7479 100644 --- a/packages/vitest/src/integrations/browser/server.ts +++ b/packages/vitest/src/integrations/browser/server.ts @@ -39,7 +39,10 @@ export async function createBrowserServer(project: WorkspaceProject, configFile: // browser never runs in middleware mode server.middlewareMode = false - config.server = server + config.server = { + ...config.server, + ...server, + } config.server.fs ??= {} config.server.fs.allow = config.server.fs.allow || [] config.server.fs.allow.push( From c01c2ff06aadc2f91e1330ef8064c2a8759e3057 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 30 Nov 2023 22:22:03 +0100 Subject: [PATCH 07/11] docs: set node to 20, update tsx (#4629) --- netlify.toml | 2 +- package.json | 2 +- pnpm-lock.yaml | 57 +++++++++++++++++++++++++------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/netlify.toml b/netlify.toml index 4e1a606e9416..7a1c0873a351 100755 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,5 @@ [build.environment] - NODE_VERSION = "18" + NODE_VERSION = "20" # don't need playwright for docs build PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1" diff --git a/package.json b/package.json index 02796f9fd2ab..4dc59eb41213 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "rollup-plugin-esbuild": "^6.1.0", "rollup-plugin-license": "^3.2.0", "simple-git-hooks": "^2.9.0", - "tsx": "^4.1.1", + "tsx": "^4.6.1", "typescript": "^5.2.2", "vite": "^5.0.0-beta.19", "vitest": "workspace:*" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b85e08c62343..10fa0810c6d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,8 +96,8 @@ importers: specifier: ^2.9.0 version: 2.9.0 tsx: - specifier: ^4.1.1 - version: 4.1.1 + specifier: ^4.6.1 + version: 4.6.1 typescript: specifier: ^5.2.2 version: 5.2.2 @@ -5563,7 +5563,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 jest-message-util: 27.5.1 jest-util: 27.5.1 @@ -5584,7 +5584,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.8.1 @@ -5621,7 +5621,7 @@ packages: dependencies: '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 jest-mock: 27.5.1 dev: true @@ -5638,7 +5638,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@sinonjs/fake-timers': 8.1.0 - '@types/node': 20.10.0 + '@types/node': 18.18.9 jest-message-util: 27.5.1 jest-mock: 27.5.1 jest-util: 27.5.1 @@ -5667,7 +5667,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 collect-v8-coverage: 1.0.2 exit: 0.1.2 @@ -5798,7 +5798,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.6 '@types/istanbul-reports': 3.0.4 - '@types/node': 20.10.0 + '@types/node': 18.18.9 '@types/yargs': 16.0.7 chalk: 4.1.2 dev: true @@ -8922,7 +8922,7 @@ packages: resolution: {integrity: sha512-N7UDG0/xiPQa2D/XrVJXjkWbpqHCd2sBaB32ggRF2l83RhPfamgKGF8gwwqyksS95qUS5ZYF9aF+lLPRlwI2UA==} dependencies: '@types/connect': 3.4.37 - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/braces@3.0.1: @@ -8943,7 +8943,7 @@ packages: /@types/connect@3.4.37: resolution: {integrity: sha512-zBUSRqkfZ59OcwXon4HVxhx5oWCJmc0OtBTK05M+p0dYjgN6iTwIL2T/WbsQZrEsdnwaF9cWQ+azOnpPvIqY3Q==} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/cookie@0.4.1: @@ -9010,7 +9010,7 @@ packages: /@types/express-serve-static-core@4.17.39: resolution: {integrity: sha512-BiEUfAiGCOllomsRAZOiMFP7LAnrifHpt56pc4Z7l9K6ACyN06Ns1JLMBxwkfLOjJRlSf06NwWsT7yzfpaVpyQ==} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 '@types/qs': 6.9.9 '@types/range-parser': 1.2.6 '@types/send': 0.17.3 @@ -9064,7 +9064,7 @@ packages: /@types/graceful-fs@4.1.8: resolution: {integrity: sha512-NhRH7YzWq8WiNKVavKPBmtLYZHxNY19Hh+az28O/phfp68CF45pMFud+ZzJ8ewnxnC5smIdF3dqFeiSUQ5I+pw==} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/hast@2.3.4: @@ -9214,7 +9214,7 @@ packages: /@types/node-fetch@2.6.7: resolution: {integrity: sha512-lX17GZVpJ/fuCjguZ5b3TjEbSENxmEk1B2z02yoXSK9WMEWRivhdSY73wWMn6bpcCDAOh6qAdktpKHIlkDk2lg==} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 form-data: 4.0.0 dev: true @@ -9393,7 +9393,7 @@ packages: /@types/resolve@1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/resolve@1.20.2: @@ -9411,7 +9411,7 @@ packages: resolution: {integrity: sha512-/7fKxvKUoETxjFUsuFlPB9YndePpxxRAOfGC/yJdc9kTjTeP5kRCTzfnE8kPUKCeyiyIZu0YQ76s50hCedI1ug==} dependencies: '@types/mime': 1.3.4 - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/serve-static@1.15.4: @@ -9419,7 +9419,7 @@ packages: dependencies: '@types/http-errors': 2.0.3 '@types/mime': 3.0.3 - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /@types/set-cookie-parser@2.4.2: @@ -18182,7 +18182,7 @@ packages: '@jest/environment': 27.5.1 '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 co: 4.6.0 dedent: 0.7.0 @@ -18317,7 +18317,7 @@ packages: '@jest/environment': 27.5.1 '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 jest-mock: 27.5.1 jest-util: 27.5.1 jsdom: 16.7.0 @@ -18335,7 +18335,7 @@ packages: '@jest/environment': 27.5.1 '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 jest-mock: 27.5.1 jest-util: 27.5.1 dev: true @@ -18379,7 +18379,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@types/graceful-fs': 4.1.8 - '@types/node': 20.10.0 + '@types/node': 18.18.9 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.11 @@ -18419,7 +18419,7 @@ packages: '@jest/source-map': 27.5.1 '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 co: 4.6.0 expect: 27.5.1 @@ -18499,7 +18499,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 dev: true /jest-pnp-resolver@1.2.3(jest-resolve@27.5.1): @@ -18560,7 +18560,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 emittery: 0.8.1 graceful-fs: 4.2.11 @@ -18625,7 +18625,7 @@ packages: resolution: {integrity: sha512-jZCyo6iIxO1aqUxpuBlwTDMkzOAJS4a3eYz3YzgxxVQFwLeSA7Jfq5cbqCY+JLvTDrWirgusI/0KwxKMgrdf7w==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: - '@types/node': 20.10.0 + '@types/node': 18.18.9 graceful-fs: 4.2.11 dev: true @@ -18676,7 +18676,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 chalk: 4.1.2 ci-info: 3.9.0 graceful-fs: 4.2.11 @@ -18713,7 +18713,7 @@ packages: dependencies: '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 20.10.0 + '@types/node': 18.18.9 ansi-escapes: 4.3.2 chalk: 4.1.2 jest-util: 27.5.1 @@ -24885,14 +24885,13 @@ packages: fsevents: 2.3.3 dev: true - /tsx@4.1.1: - resolution: {integrity: sha512-zyPn5BFMB0TB5kMLbYPNx4x/oL/oSlaecdKCv6WeJ0TeSEfx8RTJWjuB5TZ2dSewktgfBsBO/HNA9mrMWqLXMA==} + /tsx@4.6.1: + resolution: {integrity: sha512-OQ4TAPHXAPUo/NZAmmIybl0o8LFOTlycQxFepLBAp6EV87U88fOKYGCQI2viGAEOVU9UW/cgQcxcOMnfEKVY3Q==} engines: {node: '>=18.0.0'} hasBin: true dependencies: esbuild: 0.18.20 get-tsconfig: 4.7.2 - source-map-support: 0.5.21 optionalDependencies: fsevents: 2.3.3 dev: true From ca870270a4478fb266147711824b556e0f3f93d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Thu, 30 Nov 2023 23:22:37 +0200 Subject: [PATCH 08/11] docs: update social links (#4624) Co-authored-by: Vladimir --- docs/.vitepress/contributors.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/.vitepress/contributors.ts b/docs/.vitepress/contributors.ts index 187ece01e93c..6991219ddab4 100644 --- a/docs/.vitepress/contributors.ts +++ b/docs/.vitepress/contributors.ts @@ -73,6 +73,9 @@ const plainTeamMembers: CoreTeam[] = [ avatar: contributorsAvatars.AriPerkkio, name: 'Ari Perkkiƶ', github: 'AriPerkkio', + mastodon: 'https://elk.zone/m.webtoo.ls/@AriPerkkio', + twitter: 'ari_perkkio', + sponsor: 'https://github.com/sponsors/AriPerkkio', title: 'A fullstack developer, working', desc: 'Core team member of Vitest', org: 'Cloudamite', From 8c74e456c6a54e5d930ca025b4263770aa83eb12 Mon Sep 17 00:00:00 2001 From: Sjoert <63722509+Sjoertjuh@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:48:32 +0100 Subject: [PATCH 09/11] chore: fix undefined mocked key error suggestion (#4636) --- packages/vitest/src/runtime/mocker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/runtime/mocker.ts b/packages/vitest/src/runtime/mocker.ts index 44812b8b3cb0..686a0ed9d428 100644 --- a/packages/vitest/src/runtime/mocker.ts +++ b/packages/vitest/src/runtime/mocker.ts @@ -207,7 +207,7 @@ export class VitestMocker { return { ...actual, // your mocked methods - }, + } })`)}\n`, ) } From 8385c981747e719e274ff24313d9a3d087aa0d0c Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Sat, 2 Dec 2023 01:53:17 +1100 Subject: [PATCH 10/11] fix: BrowserTestRunner called incorrect super methods (#4632) --- packages/browser/src/client/runner.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/browser/src/client/runner.ts b/packages/browser/src/client/runner.ts index 5f5693bc5b24..cfa79438d840 100644 --- a/packages/browser/src/client/runner.ts +++ b/packages/browser/src/client/runner.ts @@ -1,4 +1,4 @@ -import type { File, TaskResultPack, Test } from '@vitest/runner' +import type { File, TaskResultPack, Test, VitestRunner } from '@vitest/runner' import type { ResolvedConfig } from 'vitest' import { rpc } from './rpc' @@ -11,7 +11,10 @@ interface CoverageHandler { takeCoverage: () => Promise } -export function createBrowserRunner(original: any, coverageModule: CoverageHandler | null) { +export function createBrowserRunner( + original: { new(config: ResolvedConfig): VitestRunner }, + coverageModule: CoverageHandler | null, +): { new(options: BrowserRunnerOptions): VitestRunner } { return class BrowserTestRunner extends original { public config: ResolvedConfig hashMap = new Map() @@ -23,7 +26,7 @@ export function createBrowserRunner(original: any, coverageModule: CoverageHandl } async onAfterRunTask(task: Test) { - await super.onAfterRunTest?.(task) + await super.onAfterRunTask?.(task) task.result?.errors?.forEach((error) => { console.error(error.message) }) @@ -39,8 +42,8 @@ export function createBrowserRunner(original: any, coverageModule: CoverageHandl } } - async onAfterRunFiles() { - await super.onAfterRun?.() + async onAfterRunFiles(files: File[]) { + await super.onAfterRunFiles?.(files) const coverage = await coverageModule?.takeCoverage?.() if (coverage) { From ceca93dc6d679c0571b279e77673396d033b0992 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 1 Dec 2023 22:57:31 +0800 Subject: [PATCH 11/11] docs: `os.cpu()` should be `os.cpus()` (#4634) --- docs/config/index.md | 2 +- packages/vitest/src/types/coverage.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index eeb7bf9e5d88..e756e27f6150 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1326,7 +1326,7 @@ Watermarks for statements, lines, branches and functions. See [istanbul document #### coverage.processingConcurrency - **Type:** `boolean` -- **Default:** `Math.min(20, os.cpu().length)` +- **Default:** `Math.min(20, os.cpus().length)` - **Available for providers:** `'v8' | 'istanbul'` - **CLI:** `--coverage.processingConcurrency=` diff --git a/packages/vitest/src/types/coverage.ts b/packages/vitest/src/types/coverage.ts index 9b88026200fe..9590a61442af 100644 --- a/packages/vitest/src/types/coverage.ts +++ b/packages/vitest/src/types/coverage.ts @@ -208,7 +208,7 @@ export interface BaseCoverageOptions { /** * Concurrency limit used when processing the coverage results. - * Defaults to `Math.min(20, os.cpu().length)` + * Defaults to `Math.min(20, os.cpus().length)` */ processingConcurrency?: number }