@@ -5,7 +5,7 @@ const chalk = require('chalk');
5
5
const _ = require ( 'lodash' ) ;
6
6
const PassthroughEmitter = require ( './passthrough-emitter' ) ;
7
7
const Promise = require ( 'bluebird' ) ;
8
- const q = require ( 'bluebird-q' ) ;
8
+ const bluebirdQ = require ( 'bluebird-q' ) ;
9
9
const pluginsLoader = require ( 'plugins-loader' ) ;
10
10
const gracefulFs = require ( 'graceful-fs' ) ;
11
11
@@ -37,6 +37,10 @@ module.exports = class Gemini extends PassthroughEmitter {
37
37
return new Gemini ( config , allowOverrides ) ;
38
38
}
39
39
40
+ static readRawConfig ( filePath ) {
41
+ return Config . readRawConfig ( filePath ) ;
42
+ }
43
+
40
44
constructor ( config , allowOverrides ) {
41
45
super ( ) ;
42
46
@@ -46,74 +50,42 @@ module.exports = class Gemini extends PassthroughEmitter {
46
50
this . SuiteCollection = SuiteCollection ;
47
51
48
52
setupLog ( this . config . system . debug ) ;
49
- this . _loadPlugins ( ) ;
50
53
}
51
54
52
- static readRawConfig ( filePath ) {
53
- return Config . readRawConfig ( filePath ) ;
55
+ getScreenshotPath ( suite , stateName , browserId ) {
56
+ return this . config . forBrowser ( browserId ) . getScreenshotPath ( suite , stateName ) ;
54
57
}
55
58
56
- _run ( stateProcessor , paths , options ) {
57
- if ( ! options ) {
58
- //if there are only two arguments, they are
59
- //(stateProcessor, options) and paths are
60
- //the default.
61
- options = paths ;
62
- paths = undefined ;
63
- }
64
- options = options || { } ;
65
- options . reporters = options . reporters || [ ] ;
66
-
67
- temp . init ( this . config . system . tempDir ) ;
68
-
69
- const runner = Runner . create ( this . config , stateProcessor ) ;
70
- const envBrowsers = parseBrowsers ( process . env . GEMINI_BROWSERS ) ;
71
- const envSkipBrowsers = parseBrowsers ( process . env . GEMINI_SKIP_BROWSERS ) ;
72
-
73
- options . browsers = options . browsers || envBrowsers ;
74
-
75
- this . _passThroughEvents ( runner ) ;
59
+ getBrowserCapabilites ( browserId ) {
60
+ return this . config . forBrowser ( browserId ) . desiredCapabilities ;
61
+ }
76
62
77
- // it is important to require signal handler here in order to guarantee subscribing to "INTERRUPT" event
78
- require ( './signal-handler' ) . on ( Events . INTERRUPT , ( data ) => {
79
- this . emit ( Events . INTERRUPT , data ) ;
63
+ getValidBrowsers ( browsers ) {
64
+ return _ . intersection ( browsers , this . browserIds ) ;
65
+ }
80
66
81
- runner . cancel ( ) ;
82
- } ) ;
67
+ checkUnknownBrowsers ( browsers ) {
68
+ const browsersFromConfig = this . browserIds ;
69
+ const unknownBrowsers = _ . difference ( browsers , browsersFromConfig ) ;
83
70
84
- if ( options . browsers ) {
85
- this . checkUnknownBrowsers ( options . browsers ) ;
71
+ if ( unknownBrowsers . length ) {
72
+ console . warn (
73
+ `${ chalk . yellow ( 'WARNING:' ) } Unknown browsers id: ${ unknownBrowsers . join ( ', ' ) } .\n` +
74
+ `Use one of the browser ids specified in config file: ${ browsersFromConfig . join ( ', ' ) } `
75
+ ) ;
86
76
}
77
+ }
87
78
88
- const getTests = ( source , options ) => {
89
- return source instanceof SuiteCollection
90
- ? Promise . resolve ( source )
91
- : this . readTests ( source , options ) ;
92
- } ;
93
-
94
- return getTests ( paths , options )
95
- . then ( ( suiteCollection ) => {
96
- this . checkUnknownBrowsers ( envSkipBrowsers ) ;
97
-
98
- const validSkippedBrowsers = this . getValidBrowsers ( envSkipBrowsers ) ;
99
-
100
- suiteCollection . skipBrowsers ( validSkippedBrowsers ) ;
101
- options . reporters . forEach ( ( reporter ) => applyReporter ( runner , reporter ) ) ;
102
-
103
- let testsStatistic ;
104
- runner . on ( Events . END , ( stats ) => testsStatistic = stats ) ;
105
-
106
- return runner . run ( suiteCollection )
107
- . then ( ( ) => testsStatistic ) ;
108
- } ) ;
79
+ get browserIds ( ) {
80
+ return this . config . getBrowserIds ( ) ;
109
81
}
110
82
111
- _passThroughEvents ( runner ) {
112
- this . passthroughEvent ( runner , _ . values ( Events ) ) ;
83
+ update ( paths , options ) {
84
+ return this . _exec ( ( ) => this . _run ( StateProcessor . createScreenUpdater ( options ) , paths , options ) ) ;
113
85
}
114
86
115
- _loadPlugins ( ) {
116
- pluginsLoader . load ( this , this . config . system . plugins , PREFIX ) ;
87
+ test ( paths , options ) {
88
+ return this . _exec ( ( ) => this . _run ( StateProcessor . createTester ( this . config ) , paths , options ) ) ;
117
89
}
118
90
119
91
readTests ( paths , options ) {
@@ -127,16 +99,25 @@ module.exports = class Gemini extends PassthroughEmitter {
127
99
options = options || { } ;
128
100
}
129
101
102
+ return this . _exec ( ( ) => this . _readTests ( paths , options ) ) ;
103
+ }
104
+
105
+ _exec ( fn ) {
106
+ const plugins = pluginsLoader . load ( this , this . config . system . plugins , PREFIX ) ;
107
+ return bluebirdQ ( Promise . all ( plugins ) . then ( ( ) => fn ( ) ) ) ;
108
+ }
109
+
110
+ _readTests ( paths , options ) {
130
111
options = _ . assignIn ( options , { paths} ) ;
131
112
132
- return q ( readTests ( this , this . config , options )
113
+ return readTests ( this , this . config , options )
133
114
. then ( ( rootSuite ) => {
134
115
if ( options . grep ) {
135
116
applyGrep_ ( options . grep , rootSuite ) ;
136
117
}
137
118
138
119
return new SuiteCollection ( rootSuite . children ) ;
139
- } ) ) ;
120
+ } ) ;
140
121
141
122
function applyGrep_ ( grep , suite ) {
142
123
if ( ! suite . hasStates ) {
@@ -155,40 +136,63 @@ module.exports = class Gemini extends PassthroughEmitter {
155
136
}
156
137
}
157
138
158
- update ( paths , options ) {
159
- return q ( this . _run ( StateProcessor . createScreenUpdater ( options ) , paths , options ) ) ;
160
- }
139
+ _run ( stateProcessor , paths , options ) {
140
+ if ( ! options ) {
141
+ //if there are only two arguments, they are
142
+ //(stateProcessor, options) and paths are
143
+ //the default.
144
+ options = paths ;
145
+ paths = undefined ;
146
+ }
147
+ options = options || { } ;
148
+ options . reporters = options . reporters || [ ] ;
161
149
162
- test ( paths , options ) {
163
- return q ( this . _run ( StateProcessor . createTester ( this . config ) , paths , options ) ) ;
164
- }
150
+ temp . init ( this . config . system . tempDir ) ;
165
151
166
- getScreenshotPath ( suite , stateName , browserId ) {
167
- return this . config . forBrowser ( browserId ) . getScreenshotPath ( suite , stateName ) ;
168
- }
152
+ const runner = Runner . create ( this . config , stateProcessor ) ;
153
+ const envBrowsers = parseBrowsers ( process . env . GEMINI_BROWSERS ) ;
154
+ const envSkipBrowsers = parseBrowsers ( process . env . GEMINI_SKIP_BROWSERS ) ;
169
155
170
- getBrowserCapabilites ( browserId ) {
171
- return this . config . forBrowser ( browserId ) . desiredCapabilities ;
172
- }
156
+ options . browsers = options . browsers || envBrowsers ;
173
157
174
- getValidBrowsers ( browsers ) {
175
- return _ . intersection ( browsers , this . browserIds ) ;
176
- }
158
+ this . _passThroughEvents ( runner ) ;
177
159
178
- checkUnknownBrowsers ( browsers ) {
179
- const browsersFromConfig = this . browserIds ;
180
- const unknownBrowsers = _ . difference ( browsers , browsersFromConfig ) ;
160
+ // it is important to require signal handler here in order to guarantee subscribing to "INTERRUPT" event
161
+ require ( './signal-handler' ) . on ( Events . INTERRUPT , ( data ) => {
162
+ this . emit ( Events . INTERRUPT , data ) ;
181
163
182
- if ( unknownBrowsers . length ) {
183
- console . warn (
184
- ` ${ chalk . yellow ( 'WARNING:' ) } Unknown browsers id: ${ unknownBrowsers . join ( ', ' ) } .\n` +
185
- `Use one of the browser ids specified in config file: ${ browsersFromConfig . join ( ', ' ) } `
186
- ) ;
164
+ runner . cancel ( ) ;
165
+ } ) ;
166
+
167
+ if ( options . browsers ) {
168
+ this . checkUnknownBrowsers ( options . browsers ) ;
187
169
}
170
+
171
+ const getTests = ( source , options ) => {
172
+ return source instanceof SuiteCollection
173
+ ? Promise . resolve ( source )
174
+ : this . _readTests ( source , options ) ;
175
+ } ;
176
+
177
+ return getTests ( paths , options )
178
+ . then ( ( suiteCollection ) => {
179
+ this . checkUnknownBrowsers ( envSkipBrowsers ) ;
180
+
181
+ const validSkippedBrowsers = this . getValidBrowsers ( envSkipBrowsers ) ;
182
+
183
+ suiteCollection . skipBrowsers ( validSkippedBrowsers ) ;
184
+ options . reporters . forEach ( ( reporter ) => applyReporter ( runner , reporter ) ) ;
185
+
186
+ let testsStatistic ;
187
+ runner . on ( Events . END , ( stats ) => testsStatistic = stats ) ;
188
+
189
+ return runner . run ( suiteCollection )
190
+ . then ( ( ) => testsStatistic ) ;
191
+ } ) ;
188
192
}
189
193
190
- get browserIds ( ) {
191
- return this . config . getBrowserIds ( ) ;
194
+ _passThroughEvents ( runner ) {
195
+ this . passthroughEvent ( runner , _ . values ( Events ) ) ;
192
196
}
193
197
} ;
194
198
0 commit comments