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

workerImportMetaUrl.spec.ts — vite Source File

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

File typescript ViteCore ConfigEngine 8 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  d6dd4268_24a5_9669_1bf7_bf10416c60f7["workerImportMetaUrl.spec.ts"]
  f241296c_aba8_08ac_c4f9_aed85a9eb247["workerImportMetaUrl.ts"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> f241296c_aba8_08ac_c4f9_aed85a9eb247
  cc381763_acbd_6aeb_4970_907e43d5b95f["workerImportMetaUrlPlugin"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> cc381763_acbd_6aeb_4970_907e43d5b95f
  7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> 7da774f9_eca5_d54e_6e01_6bee7d460a2b
  58c4a210_68fe_1b4d_ed49_d59203f97ef1["resolveConfig"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> 58c4a210_68fe_1b4d_ed49_d59203f97ef1
  84057c57_14eb_2f16_cd5c_1899e8da6db0["baseEnvironment.ts"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> 84057c57_14eb_2f16_cd5c_1899e8da6db0
  dc928824_33f2_0b61_b231_90d8800b77a5["PartialEnvironment"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> dc928824_33f2_0b61_b231_90d8800b77a5
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  91052f78_b6ab_99f1_a964_0e21b06fe727["parseAst"]
  d6dd4268_24a5_9669_1bf7_bf10416c60f7 --> 91052f78_b6ab_99f1_a964_0e21b06fe727
  style d6dd4268_24a5_9669_1bf7_bf10416c60f7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { describe, expect, test } from 'vitest'
import { parseAst } from 'rollup/parseAst'
import { workerImportMetaUrlPlugin } from '../../plugins/workerImportMetaUrl'
import { resolveConfig } from '../../config'
import { PartialEnvironment } from '../../baseEnvironment'

async function createWorkerImportMetaUrlPluginTransform() {
  const config = await resolveConfig({ configFile: false }, 'serve')
  const instance = workerImportMetaUrlPlugin(config)
  const environment = new PartialEnvironment('client', config)

  return async (code: string) => {
    // @ts-expect-error transform.handler should exist
    const result = await instance.transform.handler.call(
      { environment, parse: parseAst },
      code,
      'foo.ts',
    )
    return result?.code || result
  }
}

describe('workerImportMetaUrlPlugin', async () => {
  const transform = await createWorkerImportMetaUrlPluginTransform()

  test('without worker options', async () => {
    expect(
      await transform('new Worker(new URL("./worker.js", import.meta.url))'),
    ).toMatchInlineSnapshot(
      `"new Worker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=classic", '' + import.meta.url))"`,
    )
  })

  test('with shared worker', async () => {
    expect(
      await transform(
        'new SharedWorker(new URL("./worker.js", import.meta.url))',
      ),
    ).toMatchInlineSnapshot(
      `"new SharedWorker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=classic", '' + import.meta.url))"`,
    )
  })

  test('with static worker options and identifier properties', async () => {
    expect(
      await transform(
        'new Worker(new URL("./worker.js", import.meta.url), { type: "module", name: "worker1" })',
      ),
    ).toMatchInlineSnapshot(
      `"new Worker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=module", '' + import.meta.url), { type: "module", name: "worker1" })"`,
    )
  })

  test('with static worker options and literal properties', async () => {
    expect(
      await transform(
        'new Worker(new URL("./worker.js", import.meta.url), { "type": "module", "name": "worker1" })',
      ),
    ).toMatchInlineSnapshot(
      `"new Worker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=module", '' + import.meta.url), { "type": "module", "name": "worker1" })"`,
// ... (197 more lines)

Domain

Subdomains

Frequently Asked Questions

What does workerImportMetaUrl.spec.ts do?
workerImportMetaUrl.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in workerImportMetaUrl.spec.ts?
workerImportMetaUrl.spec.ts defines 1 function(s): createWorkerImportMetaUrlPluginTransform.
What does workerImportMetaUrl.spec.ts depend on?
workerImportMetaUrl.spec.ts imports 8 module(s): PartialEnvironment, baseEnvironment.ts, config.ts, parseAst, resolveConfig, vitest, workerImportMetaUrl.ts, workerImportMetaUrlPlugin.
Where is workerImportMetaUrl.spec.ts in the architecture?
workerImportMetaUrl.spec.ts is located at packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/__tests__/plugins).

Analyze Your Own Codebase

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

Try Supermodel Free