Skip to content

Commit

Permalink
Merge branch 'main' into fix-equality-helper-check-URL
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 5, 2023
2 parents 8765594 + 748205d commit 315de69
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 26 deletions.
17 changes: 0 additions & 17 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> (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
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/integrations/snapshot/chai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions packages/vitest/src/node/cli-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
13 changes: 12 additions & 1 deletion packages/vitest/src/node/pkg.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,12 +11,22 @@ 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

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
Expand Down
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/core/test/snapshot-inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]`)
Expand Down

0 comments on commit 315de69

Please sign in to comment.