ファイル
btrc-hub/frontend/vite.config.test.ts
T

32 行
1.1 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import { resolveConfig, transformWithEsbuild } from 'vite'
import { afterAll, afterEach, expect, it, vi } from 'vitest'
vi.hoisted (() => {
vi.stubGlobal ('Uint8Array', Object.getPrototypeOf (new TextEncoder ().encode ('')).constructor)
})
afterAll (() => vi.unstubAllGlobals ())
afterEach (() => {
vi.unstubAllEnvs ()
})
it ('builds JSX for the production runtime under a development NODE_ENV', async () => {
vi.stubEnv ('NODE_ENV', 'development')
const config = await resolveConfig ({
configFile: fileURLToPath (new URL ('./vite.config.ts', import.meta.url)) }, 'build')
expect (config.esbuild).not.toBe (false)
if (config.esbuild === false)
throw new Error ('esbuild is required for JSX transformation')
const result = await transformWithEsbuild (
'export const element = <div />',
'regression.tsx',
{ jsx: 'automatic', jsxDev: config.esbuild.jsxDev })
expect (result.code).toContain ('"react/jsx-runtime"')
expect (result.code).not.toContain ('jsxDEV')
expect (result.code).not.toContain ('jsx-dev-runtime')
})