This commit is contained in:
Stephen Zhou 2026-03-24 17:24:14 +08:00
parent 1113988a10
commit 0001eb239c
No known key found for this signature in database
2 changed files with 1 additions and 30 deletions

View File

@ -1,29 +0,0 @@
import fs from 'node:fs'
import path from 'node:path'
import { getRootClientInjectTarget, rootClientInjectTargetRelativePath } from '@/plugins/vite/inject-target'
const projectRoot = process.cwd()
const rootLayoutFile = path.resolve(projectRoot, 'app/layout.tsx')
const rootClientInjectTarget = getRootClientInjectTarget(projectRoot)
describe('vite dev inject target', () => {
describe('target module', () => {
it('should point to an existing root-mounted client component', () => {
expect(rootClientInjectTarget).toBe(path.resolve(projectRoot, rootClientInjectTargetRelativePath))
expect(fs.existsSync(rootClientInjectTarget)).toBe(true)
const targetCode = fs.readFileSync(rootClientInjectTarget, 'utf-8')
expect(targetCode).toMatch(/^'use client'/)
})
})
describe('root layout wiring', () => {
it('should import and render the inject target from the root layout', () => {
const layoutCode = fs.readFileSync(rootLayoutFile, 'utf-8')
expect(layoutCode).toContain('import RoutePrefixHandle from \'./routePrefixHandle\'')
expect(layoutCode).toContain('<RoutePrefixHandle />')
})
})
})

View File

@ -1,6 +1,6 @@
import path from 'node:path'
export const rootClientInjectTargetRelativePath = 'app/routePrefixHandle.tsx'
export const rootClientInjectTargetRelativePath = 'instrumentation-client.ts'
export const getRootClientInjectTarget = (projectRoot: string): string => {
return path.resolve(projectRoot, rootClientInjectTargetRelativePath)