Skip to content

Commit 13e0a8f

Browse files
authored
Improvements (#1)
* fix security issue + improve override of capabilities * fix specs for mobile * fix integration tests
1 parent ff8f76f commit 13e0a8f

File tree

9 files changed

+73
-59
lines changed

9 files changed

+73
-59
lines changed

examples/with-bt-local/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
"scripts": {
6767
"start": "PORT=8080 node scripts/start.js",
6868
"build": "node scripts/build.js",
69-
"test:jest": "jest --ci",
69+
"test:jest": "jest --ci --runInBand",
7070
"test:visual": "jest --testNamePattern=VisualTest --update-snapshot",
71-
"test:e2e": "jest --testNamePattern=UiTest",
71+
"test:e2e": "jest --testNamePattern=UiTest --runInBand --ci",
7272
"test:unit": "jest --testNamePattern=UnitTest",
7373
"test": "npm-run-all -p -r start test:jest"
7474
},

examples/with-bt-local/src/App.e2e.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ describe('ui testing UiTest', () => {
88
let driver;
99

1010
beforeAll(async () => {
11-
driver = await global.__driver__({
12-
'bstack:options': {
13-
sessionName: 'ui testing',
14-
},
15-
});
11+
driver = await global.__driver__();
1612

1713
await driver.get('http://localhost:8080');
1814
}, 20000);

examples/with-bt-local/src/__visual_testing__/App.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ describe('visual testing VisualTest', () => {
99
let driver;
1010

1111
beforeAll(async () => {
12-
driver = await global.__driver__({
13-
'bstack:options': {
14-
sessionName: 'visual testing',
15-
},
16-
});
12+
driver = await global.__driver__();
1713

1814
await driver.get('http://localhost:8080');
1915
}, 20000);

package-lock.json

Lines changed: 14 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lint": "eslint --ext .ts src/*",
1818
"lint:fix": "eslint --ext .ts src/* --fix",
1919
"prettier": "prettier --write \"**/*.{md,ts}\"",
20-
"test": "npm run build && jest"
20+
"test": "npm run build && jest --runInBand --ci"
2121
},
2222
"keywords": [
2323
"jest",
@@ -31,11 +31,9 @@
3131
"license": "MIT",
3232
"dependencies": {
3333
"@jest/types": "~24.9.0",
34-
"@types/lodash.merge": "~4.6.6",
3534
"@types/selenium-webdriver": "~4.0.3",
3635
"browserstack-local": "~1.4.2",
3736
"jest-environment-node": "~24.9.0",
38-
"lodash.merge": "~4.6.2",
3937
"selenium-webdriver": "~4.0.0-alpha.5"
4038
},
4139
"devDependencies": {

src/__tests__/github.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ describe('Github', () => {
66
beforeAll(async () => {
77
// eslint-disable-next-line
88
// @ts-ignore
9-
driver = await global.__driver__({
10-
'bstack:options': {
11-
sessionName: 'github',
12-
},
13-
});
9+
driver = await global.__driver__();
1410
await driver.get('https://github.com/taktakpeops/jest-environment-browserstack');
1511
}, 20000);
1612

src/__tests__/npm.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ describe('NPM', () => {
66
beforeAll(async () => {
77
// eslint-disable-next-line
88
// @ts-ignore
9-
driver = await global.__driver__({
10-
'bstack:options': {
11-
sessionName: 'npm',
12-
},
13-
});
9+
driver = await global.__driver__();
1410
await driver.get('https://www.npmjs.com/package/jest-environment-browserstack');
1511
}, 20000);
1612

src/__tests__/switch.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { WebDriver, By } from 'selenium-webdriver';
2+
3+
describe('Switch specs', () => {
4+
let driver: WebDriver;
5+
6+
beforeAll(async () => {
7+
// eslint-disable-next-line
8+
// @ts-ignore
9+
driver = await global.__driver__({
10+
'bstack:options': {
11+
osVersion: '11',
12+
deviceName: 'iPhone 8 Plus',
13+
realMobile: 'true',
14+
buildName: 'jest-environment-browserstack',
15+
sessionName: 'override capabilities',
16+
},
17+
browserName: 'iPhone',
18+
});
19+
await driver.get('https://github.com/taktakpeops/jest-environment-browserstack');
20+
}, 20000);
21+
22+
afterAll(async () => {
23+
await driver.quit();
24+
});
25+
26+
it('has an author', async () => {
27+
const authorSpan = await driver.findElement(By.css('.Details .Header-link:first-of-type'));
28+
const author = await authorSpan.getText();
29+
expect(author).toBe('taktakpeops');
30+
});
31+
32+
it('has a repository name', async () => {
33+
const repoSpan = await driver.findElement(By.css('.Details .Header-link:last-of-type'));
34+
const repo = await repoSpan.getText();
35+
expect(repo).toBe('jest-environment-browserstack');
36+
});
37+
});

src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Options, Local } from 'browserstack-local';
44
import { Builder, WebDriver } from 'selenium-webdriver';
55
import { randomBytes } from 'crypto';
66
import { Script } from 'vm';
7-
import merge from 'lodash.merge';
87

98
import { BrowserstackCapabilities } from './types';
109

@@ -53,6 +52,8 @@ export default class BrowserstackEnvironment extends NodeEnvironment {
5352
this.localIdentifier = opts.localIdentifier;
5453
}
5554

55+
this.btCapabilities['bstack:options'].localIdentifier = this.localIdentifier;
56+
5657
this.btTunnelOpts = localTesting;
5758
}
5859

@@ -90,7 +91,19 @@ export default class BrowserstackEnvironment extends NodeEnvironment {
9091
}
9192

9293
private async createWDDriver(capabilities?: BrowserstackCapabilities): Promise<WebDriver> {
93-
const driverFactory = new Builder().usingServer(this.selHubUrl).withCapabilities(merge(this.btCapabilities, capabilities));
94+
// checks if we have new capabilities
95+
if (capabilities) {
96+
// define username + accessKey + tunnelIdentifier if any
97+
capabilities['bstack:options'].userName = this.btCapabilities['bstack:options'].userName;
98+
capabilities['bstack:options'].accessKey = this.btCapabilities['bstack:options'].accessKey;
99+
100+
if (this.localIdentifier) {
101+
capabilities['bstack:options'].localIdentifier = this.btCapabilities['bstack:options'].localIdentifier;
102+
}
103+
}
104+
105+
const driverFactory = new Builder().usingServer(this.selHubUrl).withCapabilities(capabilities || this.btCapabilities);
106+
94107
const driver = await driverFactory.build();
95108

96109
this.drivers.push(driver);

0 commit comments

Comments
 (0)