File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 19
19
"scripts" : {
20
20
"dev" : " vite build --watch" ,
21
21
"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"
23
24
},
24
25
"dependencies" : {},
25
26
"devDependencies" : {
26
27
"typescript" : " ^4.9.4" ,
27
28
"vite" : " ^4.0.3" ,
29
+ "vitest" : " ^0.26.2" ,
28
30
"rollup" : " ^3.8.1"
29
31
},
30
32
"files" : [
Original file line number Diff line number Diff line change
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 = / e l e c t r o n /
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
+ } )
You can’t perform that action at this time.
0 commit comments