Skip to content

Commit 7e47ceb

Browse files
committed
add parallel support - fake minor
1 parent 70b7047 commit 7e47ceb

File tree

13 files changed

+181
-35
lines changed

13 files changed

+181
-35
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# jest-environment-browserstack
22

3-
[![Actions Status](https://github.com/taktakpeops/jest-environment-browserstack/workflows/Node%20CI/badge.svg)](https://github.com/taktakpeops/jest-environment-browserstack/actions) [![npm version](http://img.shields.io/npm/v/jest-environment-browserstack.svg?style=flat)](https://npmjs.org/package/jest-environment-browserstack "View this project on npm")
4-
3+
[![Actions Status](https://github.com/taktakpeops/jest-environment-browserstack/workflows/Node%20CI/badge.svg)](https://github.com/taktakpeops/jest-environment-browserstack/actions) [![npm version](http://img.shields.io/npm/v/jest-environment-browserstack.svg?style=flat)](https://npmjs.org/package/jest-environment-browserstack 'View this project on npm')
54

65
Use Jest as test-runner for running your visual-tests and more using Browserstack.
76

@@ -90,13 +89,30 @@ my-visual-test.spec.js:
9089
/**
9190
* @jest-environment browserstack
9291
*/
93-
import { until, By } from 'selenium-webdriver';
92+
import { By } from 'selenium-webdriver';
9493

9594
describe('my visual test', () => {
96-
it('test something', () => {
97-
global.__driver__.get('https://mysuperurl.ltd');
98-
// do something
99-
// do test
95+
let driver;
96+
97+
beforeAll(async () => {
98+
// you can override the default configuration
99+
driver = await global.__driver__({
100+
'bstack:options': {
101+
sessionName: 'my test',
102+
},
103+
});
104+
driver.get('https://mysuperurl.ltd');
105+
});
106+
107+
afterAll(async () => {
108+
// can be omitted
109+
await driver.quit();
110+
});
111+
112+
it('test something', async () => {
113+
const myElement = await driver.findElement(By.css('.super.class'));
114+
const text = await myElement.getText();
115+
expect(text).toBe('super text');
100116
});
101117
});
102118
```
@@ -121,7 +137,7 @@ The `test` script will run a basic e2e tests, a visual tests making a snapshot o
121137

122138
# Known limitations
123139

124-
For now, only one browser can be defined.
140+
For now, cannot override Browserstack parameters at runtime.
125141

126142
# Bug and more
127143

examples/with-bt-local/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
"start": "PORT=8080 node scripts/start.js",
6868
"build": "node scripts/build.js",
6969
"test:jest": "jest --ci",
70+
"test:visual": "jest --testNamePattern=VisualTest --update-snapshot",
71+
"test:e2e": "jest --testNamePattern=UiTest",
72+
"test:unit": "jest --testNamePattern=UnitTest",
7073
"test": "npm-run-all -p -r start test:jest"
7174
},
7275
"eslintConfig": {

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@
44

55
const { By } = require('selenium-webdriver');
66

7-
describe('ui testing', () => {
8-
const driver = global.__driver__;
7+
describe('ui testing UiTest', () => {
8+
let driver;
9+
10+
beforeAll(async () => {
11+
driver = await global.__driver__({
12+
'bstack:options': {
13+
sessionName: 'ui testing',
14+
},
15+
});
916

10-
it('load the app', async () => {
1117
await driver.get('http://localhost:8080');
18+
}, 10000);
1219

20+
afterAll(async () => {
21+
await driver.quit();
22+
});
23+
24+
it('load the app', async () => {
1325
const title = await driver.getTitle();
1426

1527
expect(title).toBe('React App');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './App';
44

5-
it('renders without crashing', () => {
5+
it('renders without crashing UnitTest', () => {
66
const div = document.createElement('div');
77
ReactDOM.render(<App />, div);
88
ReactDOM.unmountComponentAtNode(div);

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ const { toMatchImageSnapshot } = require('jest-image-snapshot');
55

66
expect.extend({ toMatchImageSnapshot });
77

8-
describe('ui testing', () => {
9-
const driver = global.__driver__;
8+
describe('visual testing VisualTest', () => {
9+
let driver;
10+
11+
beforeAll(async () => {
12+
driver = await global.__driver__({
13+
'bstack:options': {
14+
sessionName: 'visual testing',
15+
},
16+
});
1017

11-
it('load the app', async () => {
1218
await driver.get('http://localhost:8080');
19+
}, 10000);
20+
21+
afterAll(async () => {
22+
await driver.quit();
23+
});
1324

25+
it('check the app', async () => {
1426
const title = await driver.getTitle();
1527

1628
expect(title).toBe('React App');
Loading

examples/with-bt-local/yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,18 @@
11731173
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
11741174
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
11751175

1176+
"@types/lodash.merge@~4.6.6":
1177+
version "4.6.6"
1178+
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
1179+
integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ==
1180+
dependencies:
1181+
"@types/lodash" "*"
1182+
1183+
"@types/lodash@*":
1184+
version "4.14.141"
1185+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.141.tgz#d81f4d0c562abe28713406b571ffb27692a82ae6"
1186+
integrity sha512-v5NYIi9qEbFEUpCyikmnOYe4YlP8BMUdTcNCAquAKzu+FA7rZ1onj9x80mbnDdOW/K5bFf3Tv5kJplP33+gAbQ==
1187+
11761188
"@types/q@^1.5.1":
11771189
version "1.5.2"
11781190
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"
@@ -5256,9 +5268,11 @@ jest-each@^24.9.0:
52565268
version "1.0.0"
52575269
dependencies:
52585270
"@jest/types" "~24.9.0"
5271+
"@types/lodash.merge" "~4.6.6"
52595272
"@types/selenium-webdriver" "~4.0.3"
52605273
browserstack-local "~1.4.2"
52615274
jest-environment-node "~24.9.0"
5275+
lodash.merge "~4.6.2"
52625276
selenium-webdriver "~4.0.0-alpha.5"
52635277

52645278
jest-environment-jsdom-fourteen@0.1.0:
@@ -5923,6 +5937,11 @@ lodash.memoize@^4.1.2:
59235937
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
59245938
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
59255939

5940+
lodash.merge@~4.6.2:
5941+
version "4.6.2"
5942+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
5943+
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
5944+
59265945
lodash.sortby@^4.7.0:
59275946
version "4.7.0"
59285947
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-environment-browserstack",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "an environment for using Browserstack with Jest",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -31,9 +31,11 @@
3131
"license": "MIT",
3232
"dependencies": {
3333
"@jest/types": "~24.9.0",
34+
"@types/lodash.merge": "~4.6.6",
3435
"@types/selenium-webdriver": "~4.0.3",
3536
"browserstack-local": "~1.4.2",
3637
"jest-environment-node": "~24.9.0",
38+
"lodash.merge": "~4.6.2",
3739
"selenium-webdriver": "~4.0.0-alpha.5"
3840
},
3941
"devDependencies": {

src/__tests__/github.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { WebDriver, By } from 'selenium-webdriver';
2+
3+
describe('Github', () => {
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+
sessionName: 'github',
12+
},
13+
});
14+
await driver.get('https://github.com/taktakpeops/jest-environment-browserstack');
15+
}, 10000);
16+
17+
afterAll(async () => {
18+
await driver.quit();
19+
});
20+
21+
it('has an author', async () => {
22+
const authorSpan = await driver.findElement(By.css('.author'));
23+
const author = await authorSpan.getText();
24+
expect(author).toBe('taktakpeops');
25+
});
26+
27+
it('has a repository name', async () => {
28+
const repoSpan = await driver.findElement(By.css('h1.public strong'));
29+
const repo = await repoSpan.getText();
30+
expect(repo).toBe('jest-environment-browserstack');
31+
});
32+
});

0 commit comments

Comments
 (0)