-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.config.ts
More file actions
34 lines (33 loc) · 1 KB
/
vitest.config.ts
File metadata and controls
34 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: { environment: 'jsdom' },
plugins: [
{
name: 'vitest-css-import-as-text',
resolveId(source, importer) {
if (!source.startsWith('css:')) return null
const rel = source.slice(4)
const base = importer
? importer.startsWith('file:')
? fileURLToPath(importer)
: importer
: process.cwd()
const resolved = rel.startsWith('/')
? rel
: path.resolve(path.dirname(base), rel)
const url = pathToFileURL(resolved).href
return 'css:' + url
},
load(id) {
if (!id.startsWith('css:')) return null
const url = id.slice(4)
const file = fileURLToPath(url)
const css = fs.readFileSync(file, 'utf8')
return `export default ${JSON.stringify(css)}`
},
},
],
})