Skip to content

Commit fb65abb

Browse files
authored
Fix error with Firefox, allow to skip BrowserStack Local (#63)
1 parent fd9bd14 commit fb65abb

6 files changed

Lines changed: 37 additions & 37 deletions

File tree

Gulpfile.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
var path = require('path');
22
var gulp = require('gulp');
33
var babel = require('gulp-babel');
4-
var sequence = require('gulp-sequence');
54
var del = require('del');
6-
var nodeVersion = require('node-version');
75
var execa = require('execa');
86

97

108
var PACKAGE_PARENT_DIR = path.join(__dirname, '../');
119
var PACKAGE_SEARCH_PATH = (process.env.NODE_PATH ? process.env.NODE_PATH + path.delimiter : '') + PACKAGE_PARENT_DIR;
1210

1311

14-
gulp.task('clean', function () {
12+
function clean () {
1513
return del('lib');
16-
});
17-
18-
gulp.task('lint', function () {
19-
// TODO: eslint supports node version 4 or higher.
20-
// Remove this condition once we get rid of node 0.10 support.
21-
if (nodeVersion.major === '0')
22-
return null;
14+
}
2315

16+
function lint () {
2417
var eslint = require('gulp-eslint');
2518

2619
return gulp
@@ -32,14 +25,14 @@ gulp.task('lint', function () {
3225
.pipe(eslint())
3326
.pipe(eslint.format())
3427
.pipe(eslint.failAfterError());
35-
});
28+
}
3629

37-
gulp.task('build', ['lint', 'clean'], function () {
30+
function build () {
3831
return gulp
3932
.src('src/**/*.js')
4033
.pipe(babel())
4134
.pipe(gulp.dest('lib'));
42-
});
35+
}
4336

4437
function testMocha () {
4538
if (!process.env.BROWSERSTACK_USERNAME || !process.env.BROWSERSTACK_ACCESS_KEY)
@@ -62,17 +55,17 @@ function testMocha () {
6255
return execa(mochaCmd, mochaOpts, { stdio: 'inherit' });
6356
}
6457

65-
gulp.task('test-mocha', ['build'], function () {
58+
function testMochaRest () {
6659
process.env.BROWSERSTACK_USE_AUTOMATE = 0;
6760

6861
return testMocha();
69-
});
62+
}
7063

71-
gulp.task('test-mocha-automate', ['build'], function () {
64+
function testMochaAutomate () {
7265
process.env.BROWSERSTACK_USE_AUTOMATE = 1;
7366

7467
return testMocha();
75-
});
68+
}
7669

7770
function testTestcafe () {
7871
if (!process.env.BROWSERSTACK_USERNAME || !process.env.BROWSERSTACK_ACCESS_KEY)
@@ -93,16 +86,19 @@ function testTestcafe () {
9386
return execa(testCafeCmd, testCafeOpts, { stdio: 'inherit' });
9487
}
9588

96-
gulp.task('test-testcafe', ['build'], function () {
89+
function testTestcafeRest () {
9790
process.env.BROWSERSTACK_USE_AUTOMATE = '0';
9891

9992
return testTestcafe();
100-
});
93+
}
10194

102-
gulp.task('test-testcafe-automate', ['build'], function () {
95+
function testTestcafeAutomate () {
10396
process.env.BROWSERSTACK_USE_AUTOMATE = '1';
10497

10598
return testTestcafe();
106-
});
99+
}
107100

108-
gulp.task('test', sequence('test-mocha', 'test-mocha-automate', 'test-testcafe', 'test-testcafe-automate'));
101+
exports.clean = clean;
102+
exports.lint = lint;
103+
exports.build = gulp.parallel(gulp.series(clean, build), lint);
104+
exports.test = gulp.series(exports.build, testMochaRest, testMochaAutomate, testTestcafeRest, testTestcafeAutomate);

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"babel-runtime": "^6.11.6",
3333
"browserstack-local": "^1.3.6",
3434
"desired-capabilities": "^0.1.0",
35-
"jimp": "^0.2.27",
35+
"jimp": "^0.2.28",
3636
"os-family": "^1.0.0",
3737
"pinkie": "^2.0.4",
38-
"request": "^2.79.0",
38+
"request": "^2.88.0",
3939
"request-promise": "^4.1.1"
4040
},
4141
"devDependencies": {
@@ -48,13 +48,11 @@
4848
"chai": "^3.5.0",
4949
"del": "^2.2.2",
5050
"execa": "^0.9.0",
51-
"gulp": "^3.9.1",
51+
"gulp": "^4.0.0",
5252
"gulp-babel": "^6.1.2",
5353
"gulp-eslint": "^3.0.1",
54-
"gulp-sequence": "^0.4.6",
5554
"mocha": "^5.0.1",
56-
"node-version": "^1.0.0",
57-
"publish-please": "^2.1.4",
55+
"publish-please": "^5.4.3",
5856
"testcafe": "latest",
5957
"tmp": "0.0.31"
6058
}

src/backends/automate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const BROWSERSTACK_API_PATHS = {
6363
function requestApi (path, params) {
6464
return requestApiBase(path, params)
6565
.then(response => {
66-
if (response.status !== 0)
66+
if (response.status)
6767
throw new Error(`API error ${response.status}: ${response.value.message}`);
6868

6969
return response;

src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import BrowserstackConnector from './connector';
55
import JSTestingBackend from './backends/js-testing';
66
import AutomateBackend from './backends/automate';
77
import BrowserProxy from './browser-proxy';
8+
import isEnvVarTrue from './utils/is-env-var-true';
89

910
const ANDROID_PROXY_RESPONSE_DELAY = 500;
1011

11-
function isAutomateEnabled () {
12-
return process.env['BROWSERSTACK_USE_AUTOMATE'] && process.env['BROWSERSTACK_USE_AUTOMATE'] !== '0';
13-
}
1412

13+
const isAutomateEnabled = () => isEnvVarTrue('BROWSERSTACK_USE_AUTOMATE');
14+
const isLocalEnabled = () => !isEnvVarTrue('BROWSERSTACK_NO_LOCAL');
1515

1616
export default {
1717
// Multiple browsers support
@@ -44,7 +44,7 @@ export default {
4444
_getConnector () {
4545
this.connectorPromise = this.connectorPromise
4646
.then(async connector => {
47-
if (!connector) {
47+
if (!connector && isLocalEnabled()) {
4848
connector = new BrowserstackConnector(process.env['BROWSERSTACK_ACCESS_KEY']);
4949

5050
await connector.create();
@@ -171,8 +171,11 @@ export default {
171171
this._addEnvironmentPreferencesToCapabilities(capabilities);
172172

173173
capabilities.name = `TestCafe test run ${id}`;
174-
capabilities.localIdentifier = connector.connectorInstance.localIdentifierFlag;
175-
capabilities.local = true;
174+
175+
if (connector) {
176+
capabilities.localIdentifier = connector.connectorInstance.localIdentifierFlag;
177+
capabilities.local = true;
178+
}
176179

177180
await this.backend.openBrowser(id, pageUrl, capabilities);
178181

src/utils/is-env-var-true.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function (envVar) {
2+
return process.env[envVar] && process.env[envVar] !== '0';
3+
}

test/mocha/browser-names-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('Browser names', function () {
3030
'edge@15.0:Windows 10',
3131
'iPhone 7@10.3',
3232
'iPhone SE@11.2',
33-
'iPad Pro@11.2',
34-
'Google Nexus 5@4.4'
33+
'iPhone XR@12.1',
34+
'Google Nexus 6@6.0'
3535
]);
3636
});
3737
});

0 commit comments

Comments
 (0)