Home / File/ json-csr.spec.ts — vite Source File

json-csr.spec.ts — vite Source File

Architecture documentation for json-csr.spec.ts, a typescript file in the vite codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  3eff32db_56eb_992d_2110_9b804849a3d2["json-csr.spec.ts"]
  a67e84c9_62a8_8b0c_2ec9_7bab84683b2a["test.json"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> a67e84c9_62a8_8b0c_2ec9_7bab84683b2a
  07976602_57af_4e57_a032_d469282a0275["hmr.json"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> 07976602_57af_4e57_a032_d469282a0275
  e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> e6032fbc_44cf_58d6_868d_dd15106c18c5
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  ff95c247_8d48_ba97_abb9_bcf34f521fef["package.json"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> ff95c247_8d48_ba97_abb9_bcf34f521fef
  d3fd5575_295b_d6be_24dd_62d277645dc9["~utils"]
  3eff32db_56eb_992d_2110_9b804849a3d2 --> d3fd5575_295b_d6be_24dd_62d277645dc9
  style 3eff32db_56eb_992d_2110_9b804849a3d2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { readFileSync } from 'node:fs'
import { expect, test } from 'vitest'
import deepJson from 'vue/package.json'
import testJson from '../../test.json'
import hmrJson from '../../hmr.json'
import { editFile, isBuild, isServe, page } from '~utils'

const stringified = JSON.stringify(testJson)
const deepStringified = JSON.stringify(deepJson)
const hmrStringified = JSON.stringify(hmrJson)

test('default import', async () => {
  expect(await page.textContent('.full')).toBe(stringified)
})

test('named import', async () => {
  expect(await page.textContent('.named')).toBe(testJson.hello)
})

test('deep import', async () => {
  expect(await page.textContent('.deep-full')).toBe(deepStringified)
})

test('named deep import', async () => {
  expect(await page.textContent('.deep-named')).toBe(deepJson.name)
})

test('dynamic import', async () => {
  expect(await page.textContent('.dynamic')).toBe(stringified)
})

test('dynamic import, named', async () => {
  expect(await page.textContent('.dynamic-named')).toBe(testJson.hello)
})

test('fetch', async () => {
  expect(await page.textContent('.fetch')).toBe(stringified)
})

test('?url', async () => {
  expect(await page.textContent('.url')).toMatch(
    isBuild ? 'data:application/json' : '/test.json',
  )
})

test('?raw', async () => {
  expect(await page.textContent('.raw')).toBe(
    readFileSync(require.resolve('../../test.json'), 'utf-8'),
  )
})

test('require(json) returns object without default export', async () => {
  expect(await page.textContent('.require')).toBe(JSON.stringify({ 200: 'ok' }))
})

test.runIf(isServe)('should full reload', async () => {
  expect(await page.textContent('.hmr')).toBe(hmrStringified)

  editFile('hmr.json', (code) =>
    code.replace('"this is hmr json"', '"this is hmr update json"'),
  )
  await expect
    .poll(() => page.textContent('.hmr'))
    .toMatch('"this is hmr update json"')
})

Domain

Dependencies

Frequently Asked Questions

What does json-csr.spec.ts do?
json-csr.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain.
What does json-csr.spec.ts depend on?
json-csr.spec.ts imports 6 module(s): hmr.json, node:fs, package.json, test.json, vitest, ~utils.
Where is json-csr.spec.ts in the architecture?
json-csr.spec.ts is located at playground/json/__tests__/csr/json-csr.spec.ts (domain: ViteCore, directory: playground/json/__tests__/csr).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free