@@ -8,13 +8,20 @@ const path = require('path')
8
8
const OUTPUT_PATH = path . resolve ( __dirname , '..' , 'electron.d.ts' )
9
9
let output
10
10
11
+ function getDefinitionsForInterface ( interfaceName ) {
12
+ const interface_ = output . match ( interfaceName + '[^{]+{([\\s\\S]+?)}' )
13
+ expect ( interface_ ) . to . be . an ( 'array' )
14
+ return interface_ [ 1 ] . split ( ';' ) . map ( l => l . trim ( ) )
15
+ }
16
+
11
17
describe ( 'Definition File' , function ( ) {
12
18
this . timeout ( 20000 )
13
19
14
20
before ( ( done ) => {
15
21
spawn ( 'node' , [ 'cli.js' , '-o=electron.d.ts' ] , {
16
22
cwd : path . resolve ( __dirname , '..' )
17
23
} ) . on ( 'exit' , ( ) => done ( ) )
24
+ done ( )
18
25
} )
19
26
20
27
it ( 'should output a electron.d.ts file' , ( ) => {
@@ -23,18 +30,20 @@ describe('Definition File', function () {
23
30
} )
24
31
25
32
it ( 'should correctly output all exported Electron modules' , ( ) => {
26
- const AllElectron = output . match ( / A l l E l e c t r o n { ( [ \s \S ] + ?) } / )
27
- expect ( AllElectron ) . to . be . an ( 'array' )
28
- const AllElectronModules = AllElectron [ 1 ] . split ( ';' ) . map ( l => l . trim ( ) )
33
+ const AllElectronModules = getDefinitionsForInterface ( 'MainInterface' ) . concat (
34
+ getDefinitionsForInterface ( 'CommonInterface' ) ,
35
+ getDefinitionsForInterface ( 'RendererInterface' )
36
+ )
29
37
const knownElectronModules = [ 'clipboard' , 'app' , 'autoUpdater' , 'dialog' , 'ipcMain' , 'Menu' , 'MenuItem' , 'webContents' , 'BrowserWindow' ]
30
38
knownElectronModules . forEach ( knownModule => expect ( AllElectronModules . some ( tModule => tModule . indexOf ( knownModule ) === 0 ) ) . to . equal ( true ) )
31
39
} )
32
40
33
41
it ( 'should not output classes that are not exported Electron modules' , ( ) => {
34
- const AllElectron = output . match ( / A l l E l e c t r o n { ( [ \s \S ] + ?) } / )
35
- expect ( AllElectron ) . to . be . an ( 'array' )
36
- const AllElectronModules = AllElectron [ 1 ] . split ( ';' ) . map ( l => l . trim ( ) )
42
+ const AllElectronModules = getDefinitionsForInterface ( 'MainInterface' ) . concat (
43
+ getDefinitionsForInterface ( 'CommonInterface' ) ,
44
+ getDefinitionsForInterface ( 'RendererInterface' )
45
+ )
37
46
const unKnownElectronModules = [ 'Clipboard' , 'CrashReport' , 'WebContents' , 'menu' , 'Session' ]
38
- unKnownElectronModules . forEach ( knownModule => expect ( AllElectronModules . some ( tModule => tModule . indexOf ( knownModule ) === 0 ) ) . to . equal ( false ) )
47
+ unKnownElectronModules . forEach ( knownModule => expect ( AllElectronModules . some ( tModule => tModule . indexOf ( knownModule ) === 0 ) ) . to . equal ( false , knownModule ) )
39
48
} )
40
49
} )
0 commit comments