Skip to content

Commit 48465ac

Browse files
author
John Doherty
committed
added some error checking around eyes integration logic to fix #42 - if this fails, we need to back it out
1 parent 23a307f commit 48465ac

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ function collectPaths(value, paths) {
1212
}
1313

1414
function coerceInt(value, defaultValue) {
15+
1516
var int = parseInt(value);
1617

17-
if (typeof int == 'number') {
18-
return int;
19-
}
20-
else {
21-
return defaultValue;
22-
}
18+
if (typeof int === 'number') return int;
19+
20+
return defaultValue;
2321
}
2422

2523
var config = {
@@ -28,7 +26,7 @@ var config = {
2826
sharedObjects: './shared-objects',
2927
reports: './reports',
3028
browser: 'chrome',
31-
timeout: 10000
29+
timeout: 15000
3230
};
3331

3432
var configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');
@@ -61,7 +59,7 @@ program.on('--help', function () {
6159
global.browserName = program.browser;
6260

6361
// store Eyes Api globally (used within world.js to set Eyes)
64-
global.eyeskey = config.eye_key
62+
global.eyesKey = config.eye_key
6563

6664
// used within world.js to import page objects
6765
global.pageObjectPath = path.resolve(program.pageObjects);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
"url": "https://github.com/john-doherty/selenium-cucumber-js/issues"
3434
},
3535
"engines": {
36-
"node": ">= 6.9.0"
36+
"node": "6.11.0"
3737
},
38+
"engineStrict": true,
3839
"homepage": "https://github.com/john-doherty/selenium-cucumber-js#readme",
3940
"dependencies": {
4041
"chai": "3.5.0",

runtime/world.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,21 @@ function getDriverInstance() {
7272

7373

7474
/**
75-
* Initialize the eyes SDK and set your private API key via the config file.*/
75+
* Initialize the eyes SDK and set your private API key via the config file.
76+
*/
7677
function getEyesInstance() {
7778

78-
var eyes = new Eyes();
79+
if (global.eyesKey) {
7980

80-
//retrieve apikey from config file in the project root as defined by the user
81-
eyes.setApiKey(eyeskey);
81+
var eyes = new Eyes();
8282

83-
return eyes;
83+
// retrieve eyes api key from config file in the project root as defined by the user
84+
eyes.setApiKey(global.eyesKey);
8485

86+
return eyes;
87+
}
8588

89+
return null;
8690
}
8791

8892
function consoleInfo() {
@@ -136,7 +140,7 @@ function importSupportObjects() {
136140

137141
if (fs.existsSync(itemPath)) {
138142

139-
var dir = requireDir(itemPath, {camelcase: true});
143+
var dir = requireDir(itemPath, { camelcase: true });
140144

141145
merge(allDirs, dir);
142146
}
@@ -154,7 +158,7 @@ function importSupportObjects() {
154158
if (global.pageObjectPath && fs.existsSync(global.pageObjectPath)) {
155159

156160
// require all page objects using camel case as object names
157-
global.page = requireDir(global.pageObjectPath, {camelcase: true});
161+
global.page = requireDir(global.pageObjectPath, { camelcase: true });
158162
}
159163

160164
// add helpers
@@ -178,9 +182,10 @@ module.exports = function () {
178182

179183
if (!global.driver || !global.eyes) {
180184
global.driver = getDriverInstance();
185+
186+
// TOOD: this all feels a bit hacky, needs rethinking...
181187
global.eyes = getEyesInstance();
182188
}
183-
184189
});
185190

186191
this.registerHandler('AfterFeatures', function (features, done) {
@@ -224,11 +229,17 @@ module.exports = function () {
224229

225230
return driver.close().then(function () {
226231
return driver.quit();
227-
}).then(function () {
228-
// If the test was aborted before eyes.close was called ends the test as aborted.
229-
return eyes.abortIfNotClosed();
232+
})
233+
.then(function() {
234+
235+
if (eyes) {
236+
// If the test was aborted before eyes.close was called ends the test as aborted.
237+
return eyes.abortIfNotClosed();
238+
}
239+
240+
return Promise.resolve();
230241
});
231-
})
242+
});
232243
}
233244

234245
return driver.close().then(function () {

0 commit comments

Comments
 (0)