Skip to content

Commit

Permalink
fix: move 'vitest:ui' too
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Sep 27, 2024
1 parent cbf1654 commit 2dafae0
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions packages/ui/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,44 @@ export default (ctx: Vitest): Plugin => {
return <Plugin>{
name: 'vitest:ui',
apply: 'serve',
configureServer(server) {
const uiOptions = ctx.config
const base = uiOptions.uiBase
const coverageFolder = resolveCoverageFolder(ctx)
const coveragePath = coverageFolder ? coverageFolder[1] : undefined
if (coveragePath && base === coveragePath) {
throw new Error(
`The ui base path and the coverage path cannot be the same: ${base}, change coverage.reportsDirectory`,
)
}
configureServer: {
order: 'post',
handler(server) {
const uiOptions = ctx.config
const base = uiOptions.uiBase
const coverageFolder = resolveCoverageFolder(ctx)
const coveragePath = coverageFolder ? coverageFolder[1] : undefined
if (coveragePath && base === coveragePath) {
throw new Error(
`The ui base path and the coverage path cannot be the same: ${base}, change coverage.reportsDirectory`,
)
}

if (coverageFolder) {
if (coverageFolder) {
server.middlewares.use(
coveragePath!,
sirv(coverageFolder[0], {
single: true,
dev: true,
setHeaders: (res) => {
res.setHeader(
'Cache-Control',
'public,max-age=0,must-revalidate',
)
},
}),
)
}

const clientDist = resolve(fileURLToPath(import.meta.url), '../client')
server.middlewares.use(
coveragePath!,
sirv(coverageFolder[0], {
base,
sirv(clientDist, {
single: true,
dev: true,
setHeaders: (res) => {
res.setHeader(
'Cache-Control',
'public,max-age=0,must-revalidate',
)
},
}),
)
}

const clientDist = resolve(fileURLToPath(import.meta.url), '../client')
server.middlewares.use(
base,
sirv(clientDist, {
single: true,
dev: true,
}),
)
},
},
}
}
Expand Down

0 comments on commit 2dafae0

Please sign in to comment.