File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ module . exports = {
2+ globals : {
3+ __APP__ : undefined , // A different app will be launched in each test environment
4+ } ,
5+ testEnvironment : "./tests/environment" ,
6+ testTimeout : 30000 , // 30s
7+ } ;
Original file line number Diff line number Diff line change 1+ const path = require ( "path" ) ;
2+
3+ const getPort = require ( "get-port" ) ;
4+ const NodeEnvironment = require ( "jest-environment-node" ) ;
5+ const { Application } = require ( "spectron" ) ;
6+
7+ class TestEnvironment extends NodeEnvironment {
8+ constructor ( config ) {
9+ super ( config ) ;
10+ }
11+
12+ async setup ( ) {
13+ await super . setup ( ) ;
14+
15+ const electronPath = path . resolve (
16+ __dirname ,
17+ ".." ,
18+ "node_modules" ,
19+ ".bin" ,
20+ "electron"
21+ ) ;
22+ const appPath = path . resolve ( __dirname , ".." ) ;
23+ const port = await getPort ( ) ;
24+
25+ this . global . __APP__ = new Application ( {
26+ path : electronPath ,
27+ args : [ appPath ] ,
28+ port,
29+ } ) ;
30+ await this . global . __APP__ . start ( ) ;
31+ const { client } = this . global . __APP__ ;
32+ await client . waitUntilWindowLoaded ( ) ;
33+ }
34+
35+ async teardown ( ) {
36+ await this . global . __APP__ . stop ( ) ;
37+ await super . teardown ( ) ;
38+ }
39+
40+ runScript ( script ) {
41+ return super . runScript ( script ) ;
42+ }
43+ }
44+
45+ module . exports = TestEnvironment ;
You can’t perform that action at this time.
0 commit comments