Home / File/ fixture.spec.ts — vite Source File

fixture.spec.ts — vite Source File

Architecture documentation for fixture.spec.ts, a typescript file in the vite codebase. 7 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  839c2458_9146_e852_7e4b_c8e0bd3b2368["fixture.spec.ts"]
  b68d9c02_4026_8cfa_8eb1_35ec4a8f23cb["importMetaGlob.ts"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> b68d9c02_4026_8cfa_8eb1_35ec4a8f23cb
  a6007673_0baa_9293_6af0_ff74ed056981["transformGlobImport"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> a6007673_0baa_9293_6af0_ff74ed056981
  926e3b98_b813_2ff8_abb3_16447ab95544["esbuild.ts"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> 926e3b98_b813_2ff8_abb3_16447ab95544
  bf4a41be_9dbf_35be_2072_4283cd478ae7["transformWithEsbuild"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> bf4a41be_9dbf_35be_2072_4283cd478ae7
  51e96894_3556_ed5c_1ede_97d449867adf["node:path"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> 51e96894_3556_ed5c_1ede_97d449867adf
  e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> e6032fbc_44cf_58d6_868d_dd15106c18c5
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  839c2458_9146_e852_7e4b_c8e0bd3b2368 --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  style 839c2458_9146_e852_7e4b_c8e0bd3b2368 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { resolve } from 'node:path'
import { promises as fs } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { transformGlobImport } from '../../../plugins/importMetaGlob'
import { transformWithEsbuild } from '../../../plugins/esbuild'

describe('fixture', async () => {
  const resolveId = (id: string) => id
  const root = import.meta.dirname

  it('transform', async () => {
    const id = resolve(import.meta.dirname, './fixture-a/index.ts')
    const code = (
      await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id)
    ).code

    expect(
      (await transformGlobImport(code, id, root, resolveId))?.s.toString(),
    ).toMatchSnapshot()
  })

  it('preserve line count', async () => {
    const getTransformedLineCount = async (code: string) =>
      (await transformGlobImport(code, 'virtual:module', root, resolveId))?.s
        .toString()
        .split('\n').length

    expect(await getTransformedLineCount("import.meta.glob('./*.js')")).toBe(1)
    expect(
      await getTransformedLineCount(
        `
          import.meta.glob(
            './*.js'
          )
        `.trim(),
      ),
    ).toBe(3)
  })

  it('virtual modules', async () => {
    const root = resolve(import.meta.dirname, './fixture-a')
    const code = [
      "import.meta.glob('/modules/*.ts')",
      "import.meta.glob(['/../fixture-b/*.ts'])",
      "import.meta.glob(['./*.ts'], { base: '/modules' })",
    ].join('\n')
    expect(
      (
        await transformGlobImport(code, 'virtual:module', root, resolveId)
      )?.s.toString(),
    ).toMatchSnapshot()

    try {
      await transformGlobImport(
        "import.meta.glob('./modules/*.ts')",
        'virtual:module',
        root,
        resolveId,
      )
      expect('no error').toBe('should throw an error')
    } catch (err) {
      expect(err).toMatchInlineSnapshot(
        "[Error: In virtual modules, all globs must start with '/']",
      )
    }
  })

  it('transform with restoreQueryExtension', async () => {
    const id = resolve(import.meta.dirname, './fixture-a/index.ts')
    const code = (
      await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id)
    ).code

    expect(
      (
        await transformGlobImport(code, id, root, resolveId, true)
      )?.s.toString(),
    ).toMatchSnapshot()
  })
})

Domain

Frequently Asked Questions

What does fixture.spec.ts do?
fixture.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain.
What does fixture.spec.ts depend on?
fixture.spec.ts imports 7 module(s): esbuild.ts, importMetaGlob.ts, node:fs, node:path, transformGlobImport, transformWithEsbuild, vitest.
Where is fixture.spec.ts in the architecture?
fixture.spec.ts is located at packages/vite/src/node/__tests__/plugins/importGlob/fixture.spec.ts (domain: ViteCore, directory: packages/vite/src/node/__tests__/plugins/importGlob).

Analyze Your Own Codebase

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

Try Supermodel Free