Skip to content

Commit 1d7eca5

Browse files
committed
feat: add test 🌱
1 parent 9ef3e8e commit 1d7eca5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
"scripts": {
2020
"dev": "vite build --watch",
2121
"build": "rm -rf types && tsc --emitDeclarationOnly && vite build",
22-
"prepublishOnly": "npm run build"
22+
"prepublishOnly": "npm run test && npm run build",
23+
"test": "vitest run"
2324
},
2425
"dependencies": {},
2526
"devDependencies": {
2627
"typescript": "^4.9.4",
2728
"vite": "^4.0.3",
29+
"vitest": "^0.26.2",
2830
"rollup": "^3.8.1"
2931
},
3032
"files": [

Diff for: test/config.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { builtinModules } from 'node:module'
2+
import { ExternalOption } from 'rollup'
3+
import type { InlineConfig } from 'vite'
4+
import {
5+
describe,
6+
expect,
7+
it,
8+
} from 'vitest'
9+
import { withExternalBuiltins } from '../src/config'
10+
11+
const builtins: any[] = builtinModules.filter(e => !e.startsWith('_')); builtins.push('electron', ...builtins.map(m => `node:${m}`))
12+
const getConfig = (external: ExternalOption): InlineConfig => ({ build: { rollupOptions: { external } } })
13+
const external_string: ExternalOption = 'electron'
14+
const external_array: ExternalOption = ['electron']
15+
const external_regexp: ExternalOption = /electron/
16+
const external_function: ExternalOption = source => ['electron'].includes(source)
17+
18+
describe('src/config', () => {
19+
it('withExternalBuiltins', async () => {
20+
const external_str = withExternalBuiltins(getConfig(external_string))!.build!.rollupOptions!.external
21+
expect(external_str).toEqual(builtins.concat(external_string))
22+
23+
const external_arr = withExternalBuiltins(getConfig(external_array))!.build!.rollupOptions!.external
24+
expect(external_arr).toEqual(builtins.concat(external_array))
25+
26+
const external_reg = withExternalBuiltins(getConfig(external_regexp))!.build!.rollupOptions!.external
27+
expect(external_reg).toEqual(builtins.concat(external_regexp))
28+
29+
const external_fun = withExternalBuiltins(getConfig(external_function))!.build!.rollupOptions!.external
30+
expect((external_fun as (source: string) => boolean)('electron')).true
31+
})
32+
})

0 commit comments

Comments
 (0)