-
-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathvitest.config.ts
More file actions
69 lines (64 loc) · 2.43 KB
/
Copy pathvitest.config.ts
File metadata and controls
69 lines (64 loc) · 2.43 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { defineConfig, mergeConfig } from 'vitest/config'
import path, { resolve } from 'path'
import fs from 'fs/promises'
import { normalizePath, Plugin } from 'vite'
export const nodejsPolarsDirnamePlugin = () => {
const name = 'nodejs-polars-dirname-plugin'
return {
name,
transform(code: string, id: string) {
// aim for the node_modules/nodejs-polars/bin/native-polars.js file
if (id.endsWith('.node')) {
const file = path.basename(id)
return `
// create a custom require function to load .node files
import { createRequire } from 'module';
const customRequire = createRequire(import.meta.url)
// load the .node file expecting it to be in the same directory as the output bundle
const content = customRequire('./${file}')
// export the content straight back out again
export default content
`
} else if (id.includes('?asset')) {
const file = path.basename(id)
// Remove query parameters
const cleanFile = file.split('?')[0]
return `
import { join } from 'path'
export default join(__dirname, "${cleanFile}")
`
} else if (id.includes('?asarUnpack')) {
const file = path.basename(id)
// Remove query parameters
const cleanFile = file.split('?')[0]
return `
import { join } from 'path'
export default join(__dirname, "${cleanFile}")
`
}
// else return the original code (leave code unrelated to nodejs-polars untouched)
return code
}
}
}
//export default mergeConfig(config.main as any, defineConfig({
export default defineConfig({
resolve: {
alias: {
'@r': resolve('src/renderer/src'),
nodeCan: resolve(__dirname, 'src/main/share'),
src: resolve(__dirname, 'src')
}
},
test: {
// 全局设置文件,在所有测试文件运行前执行
setupFiles: ['./test/setup.ts']
// 或者使用 setupFilesAfterEnv,在测试环境设置后执行
// setupFilesAfterEnv: ['./test/setup-after-env.ts'],
// 全局设置,在整个测试套件开始前执行一次
// globalSetup: './test/global-setup.ts',
// 全局清理,在整个测试套件结束后执行一次
// globalTeardown: './test/global-teardown.ts',
},
plugins: [nodejsPolarsDirnamePlugin()]
})