From a9908453a0ac57202424bb4db6b7847cb1e2dde4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Tue, 5 Dec 2023 11:32:30 +0200 Subject: [PATCH 1/5] fix(cli): prompted packages fail to install (#4593) --- packages/vitest/LICENSE.md | 17 ----------------- packages/vitest/package.json | 2 +- pnpm-lock.yaml | 10 ++++++++-- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/vitest/LICENSE.md b/packages/vitest/LICENSE.md index d372cd14575e..c29741383da7 100644 --- a/packages/vitest/LICENSE.md +++ b/packages/vitest/LICENSE.md @@ -1085,23 +1085,6 @@ Repository: sindresorhus/p-locate --------------------------------------- -## path-exists -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/path-exists - -> MIT License -> -> Copyright (c) Sindre Sorhus (sindresorhus.com) -> -> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---------------------------------------- - ## picomatch License: MIT By: Jon Schlinkert diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 6b79f407543d..62b6712a7991 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -161,7 +161,7 @@ }, "devDependencies": { "@ampproject/remapping": "^2.2.1", - "@antfu/install-pkg": "^0.1.1", + "@antfu/install-pkg": "^0.3.1", "@edge-runtime/vm": "^3.1.7", "@sinonjs/fake-timers": "11.1.0", "@types/estree": "^1.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39fa007b6941..ea72b9dd0dce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1331,8 +1331,8 @@ importers: specifier: ^2.2.1 version: 2.2.1 '@antfu/install-pkg': - specifier: ^0.1.1 - version: 0.1.1 + specifier: ^0.3.1 + version: 0.3.1 '@edge-runtime/vm': specifier: ^3.1.7 version: 3.1.7 @@ -2228,6 +2228,12 @@ packages: find-up: 5.0.0 dev: true + /@antfu/install-pkg@0.3.1: + resolution: {integrity: sha512-A3zWY9VeTPnxlMiZtsGHw2lSd3ghwvL8s9RiGOtqvDxhhFfZ781ynsGBa/iUnDJ5zBrmTFQrJDud3TGgRISaxw==} + dependencies: + execa: 8.0.1 + dev: true + /@antfu/ni@0.21.12: resolution: {integrity: sha512-2aDL3WUv8hMJb2L3r/PIQWsTLyq7RQr3v9xD16fiz6O8ys1xEyLhhTOv8gxtZvJiTzjTF5pHoArvRdesGL1DMQ==} hasBin: true From 775e2014703116248d7a60a087c1ab34cb3be5ec Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Tue, 5 Dec 2023 11:22:03 +0100 Subject: [PATCH 2/5] fix: don't check if vite is installed (#4659) --- packages/vitest/src/node/cli-api.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/vitest/src/node/cli-api.ts b/packages/vitest/src/node/cli-api.ts index b9b83e3573d0..f67de6484ce4 100644 --- a/packages/vitest/src/node/cli-api.ts +++ b/packages/vitest/src/node/cli-api.ts @@ -36,11 +36,6 @@ export async function startVitest( // this shouldn't affect _application root_ that can be changed inside config const root = resolve(options.root || process.cwd()) - if (!await ensurePackageInstalled('vite', root)) { - process.exitCode = 1 - return - } - if (typeof options.coverage === 'boolean') options.coverage = { enabled: options.coverage } From 1df299111b4f18dec9a9396f6e95dd6ee9ad1c7e Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Tue, 5 Dec 2023 11:22:44 +0100 Subject: [PATCH 3/5] chore: improve grammar in "Missing dep" error (#4658) --- packages/vitest/src/node/pkg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/pkg.ts b/packages/vitest/src/node/pkg.ts index f1de8b90d01c..642378033868 100644 --- a/packages/vitest/src/node/pkg.ts +++ b/packages/vitest/src/node/pkg.ts @@ -15,7 +15,7 @@ export async function ensurePackageInstalled( const promptInstall = !isCI && process.stdout.isTTY - process.stderr.write(c.red(`${c.inverse(c.red(' MISSING DEP '))} Can not find dependency '${dependency}'\n\n`)) + process.stderr.write(c.red(`${c.inverse(c.red(' MISSING DEPENDENCY '))} Cannot find dependency '${dependency}'\n\n`)) if (!promptInstall) return false From 574cc7d0d20833eab545eb62a1f0eb5d62b79405 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Tue, 5 Dec 2023 11:24:55 +0100 Subject: [PATCH 4/5] fix: fix ensurePackageInstalled on Yarn PnP (#4657) --- packages/vitest/src/node/pkg.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/vitest/src/node/pkg.ts b/packages/vitest/src/node/pkg.ts index 642378033868..783264b9c6e3 100644 --- a/packages/vitest/src/node/pkg.ts +++ b/packages/vitest/src/node/pkg.ts @@ -1,4 +1,5 @@ import url from 'node:url' +import { createRequire } from 'node:module' import c from 'picocolors' import { isPackageExists } from 'local-pkg' import { EXIT_CODE_RESTART } from '../constants' @@ -10,6 +11,16 @@ export async function ensurePackageInstalled( dependency: string, root: string, ) { + if (process.versions.pnp) { + const targetRequire = createRequire(__dirname) + try { + targetRequire.resolve(dependency, { paths: [root, __dirname] }) + return true + } + catch (error) { + } + } + if (isPackageExists(dependency, { paths: [root, __dirname] })) return true From 748205dc1d5d4d82ed732a7a1e698f68bf155894 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 5 Dec 2023 19:29:14 +0900 Subject: [PATCH 5/5] fix: apply `stripSnapshotIndentation` for thrown snapshot (#4663) --- .../vitest/src/integrations/snapshot/chai.ts | 3 +++ test/core/test/snapshot-inline.test.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/vitest/src/integrations/snapshot/chai.ts b/packages/vitest/src/integrations/snapshot/chai.ts index 4f86d0b0668f..6ee0b0e62d6e 100644 --- a/packages/vitest/src/integrations/snapshot/chai.ts +++ b/packages/vitest/src/integrations/snapshot/chai.ts @@ -154,6 +154,9 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => { const promise = utils.flag(this, 'promise') as string | undefined const errorMessage = utils.flag(this, 'message') + if (inlineSnapshot) + inlineSnapshot = stripSnapshotIndentation(inlineSnapshot) + getSnapshotClient().assert({ received: getError(expected, promise), message, diff --git a/test/core/test/snapshot-inline.test.ts b/test/core/test/snapshot-inline.test.ts index 657e7a243940..fa91f4f74873 100644 --- a/test/core/test/snapshot-inline.test.ts +++ b/test/core/test/snapshot-inline.test.ts @@ -100,6 +100,22 @@ test('throwing inline snapshots', async () => { newlines" `) + expect(() => { + throw new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n')) + }).toThrowErrorMatchingInlineSnapshot(` + [Error: Inline + snapshot + with + newlines] + `) + + expect(new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n'))).toMatchInlineSnapshot(` + [Error: Inline + snapshot + with + newlines] + `) + await expect(async () => { throw new Error('omega') }).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: omega]`)