-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
basic.test.ts
41 lines (35 loc) · 1.15 KB
/
basic.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { expect, test } from 'vitest'
test('basic', () => {
// relative path
expect(
cleanDir(import.meta.resolve('../package.json')),
).toMatchInlineSnapshot(`"__DIR__/test/import-meta-resolve/package.json"`)
// not throw in latest NodeJS
expect(cleanDir(import.meta.resolve('../no-such-file'))).toMatchInlineSnapshot(
`"__DIR__/test/import-meta-resolve/no-such-file"`,
)
// with 2nd argument `parent`
expect(
cleanDir(
import.meta.resolve('./package.json', new URL('..', import.meta.url)),
),
).toMatchInlineSnapshot(`"__DIR__/test/import-meta-resolve/package.json"`)
// node_module
expect(cleanDir(import.meta.resolve('vitest'))).toMatchInlineSnapshot(
`"__DIR__/packages/vitest/dist/index.js"`,
)
expect(() =>
cleanDir(import.meta.resolve('@vitest/not-such-module')),
).toThrow(
expect.objectContaining({
message: expect.stringContaining(
'Cannot find package \'@vitest/not-such-module\' imported from',
),
}),
)
})
// make output deterministic
function cleanDir(out: string) {
const dir = new URL('../../..', import.meta.url).toString()
return out.replace(dir, '__DIR__/')
}