/
ssrLoadModule.spec.ts
54 lines (48 loc) · 1.38 KB
/
ssrLoadModule.spec.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
42
43
44
45
46
47
48
49
50
51
52
53
54
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { expect, test } from 'vitest'
import { createServer } from '../../server'
import { normalizePath } from '../../utils'
const root = fileURLToPath(new URL('./', import.meta.url))
async function createDevServer() {
const server = await createServer({
configFile: false,
root,
logLevel: 'silent',
optimizeDeps: {
disabled: true,
},
})
server.pluginContainer.buildStart({})
return server
}
test('ssrLoad', async () => {
expect.assertions(1)
const server = await createDevServer()
const moduleRelativePath = '/fixtures/modules/has-invalid-import.js'
const moduleAbsolutePath = normalizePath(path.join(root, moduleRelativePath))
try {
await server.ssrLoadModule(moduleRelativePath)
} catch (e) {
expect(e.message).toBe(
`Failed to load url ./non-existent.js (resolved id: ./non-existent.js) in ${moduleAbsolutePath}. Does the file exist?`,
)
}
})
test('error has same instance', async () => {
expect.assertions(3)
const s = Symbol()
const server = await createDevServer()
try {
await server.ssrLoadModule('/fixtures/modules/has-error.js')
} catch (e) {
expect(e[s]).toBeUndefined()
e[s] = true
expect(e[s]).toBe(true)
}
try {
await server.ssrLoadModule('/fixtures/modules/has-error.js')
} catch (e) {
expect(e[s]).toBe(true)
}
})