-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvitest.config.ts
More file actions
34 lines (32 loc) · 1004 Bytes
/
vitest.config.ts
File metadata and controls
34 lines (32 loc) · 1004 Bytes
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 * as fsp from 'node:fs/promises'
import * as path from 'node:path'
import { cloudflareTest } from '@cloudflare/vitest-pool-workers'
import { defineConfig } from 'vitest/config'
const bytesRE = /[?&]bytes\b/
export default defineConfig({
plugins: [
{
name: 'vite-plugin-bytes',
enforce: 'pre',
resolveId(source, importer) {
if (!bytesRE.test(source) || !importer)
return
const file = source.replace(/[?#].*$/, '')
const resolved = path.resolve(path.dirname(importer.replace(/[?#].*$/, '')), file)
return `${resolved}?bytes`
},
async load(id) {
if (!bytesRE.test(id))
return
const file = id.replace(/[?#].*$/, '')
const base64 = (await fsp.readFile(file)).toString('base64')
return `export default Uint8Array.from(atob("${base64}"), c => c.charCodeAt(0));`
},
},
cloudflareTest({
wrangler: {
configPath: './wrangler.jsonc',
},
}),
],
})