Skip to content

Commit f731ca2

Browse files
authored
test: simplify playground/json/__tests__/ssr (#18701)
1 parent 818cf3e commit f731ca2

File tree

7 files changed

+29
-177
lines changed

7 files changed

+29
-177
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"hello": "this is json"
3+
}

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fileURLToPath } from 'node:url'
22
import path from 'node:path'
3+
import fs from 'node:fs'
34
import { stripVTControlCharacters } from 'node:util'
45
import { expect, test } from 'vitest'
56
import { createServer } from '../../server'
@@ -212,3 +213,27 @@ test('parse error', async () => {
212213
expect.unreachable()
213214
}
214215
})
216+
217+
test('json', async () => {
218+
const server = await createDevServer()
219+
const mod = await server.ssrLoadModule('/fixtures/json/test.json')
220+
expect(mod).toMatchInlineSnapshot(`
221+
{
222+
"default": {
223+
"hello": "this is json",
224+
},
225+
"hello": "this is json",
226+
}
227+
`)
228+
229+
const source = fs.readFileSync(
230+
path.join(root, 'fixtures/json/test.json'),
231+
'utf-8',
232+
)
233+
const json = await server.ssrTransform(
234+
`export default ${source}`,
235+
null,
236+
'/test.json',
237+
)
238+
expect(json?.code.length).toMatchInlineSnapshot(`61`)
239+
})

playground/json/__tests__/ssr/json-ssr.spec.ts

-23
This file was deleted.

playground/json/__tests__/ssr/serve.ts

-35
This file was deleted.

playground/json/index.ssr.html

-23
This file was deleted.

playground/json/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"dev": "vite",
88
"build": "vite build",
99
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
10-
"preview": "vite preview",
11-
"dev:ssr": "node server",
12-
"serve:ssr": "NODE_ENV=production node server",
13-
"debug:ssr": "node --inspect-brk server"
10+
"preview": "vite preview"
1411
},
1512
"devDependencies": {
1613
"@vitejs/test-json-module": "file:./json-module",

playground/json/server.js

-92
This file was deleted.

0 commit comments

Comments
 (0)