Skip to content

Commit

Permalink
move test infrastructure from cypress to puppeteer
Browse files Browse the repository at this point in the history
cypress had a weird way to handle asynchronosity and
also strange behaviour for failing, puppeteer on top
of jest seems to be a way more stable alternative
  • Loading branch information
DanielMSchmidt committed Nov 9, 2017
1 parent 32c22ab commit 6798400
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 476 deletions.
21 changes: 18 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@ matrix:
- 'cat coverage/lcov.info | ./node_modules/.bin/coveralls'

# E2E Web
- services:
- docker
- language: node_js
node_js: 8.7
services:
- docker
cache:
yarn: true
directories:
- node_modules
dist: trusty
addons:
apt:
packages:
# This is required to run new chrome on old trusty
- libnss3
env:
- CI=false
- NODE_VERSION="8.7"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- yarn install
- cd e2e-tests/react
Expand All @@ -27,4 +42,4 @@ matrix:
script:
- yarn test
after_script:
- kill -9 $SERVER_PID
- kill -9 $SERVER_PID
31 changes: 31 additions & 0 deletions e2e-tests/react/__tests__/0-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fetch from "node-fetch";
import puppeteer from "puppeteer";
import { getContent } from "../utils";

describe("Setup", () => {
let browser, page;
beforeAll(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
});

it("should be able to access zipkin", async () => {
const response = await fetch("http://localhost:9411/api/v2/traces");
expect(response.status).toBe(200);
});

it("should reach the demo page", async () => {
await page.goto("http://localhost:3000");
await page.click("#Basic");

const before = await getContent(page, "#buttonLabel");
expect(before).toBe("Not-Pressed");

await page.click("#basicButton");

const after = await getContent(page, "#buttonLabel");
expect(after).toBe("Is-Pressed");

await browser.close();
});
});
24 changes: 24 additions & 0 deletions e2e-tests/react/__tests__/1-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fetch from "node-fetch";
import puppeteer from "puppeteer";

describe("Basic: Spans", () => {
let browser, page;
beforeAll(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
});

beforeEach(async () => {
await page.goto("http://localhost:3000");
await page.click("#Basic");
});

afterAll(async () => {
await browser.close();
});

it("only starting one should not add a new span");
it("starting and finishing a span should register one in the server");
it("span should have a name");
it("span should have a service set");
});
4 changes: 0 additions & 4 deletions e2e-tests/react/cypress.json

This file was deleted.

5 changes: 0 additions & 5 deletions e2e-tests/react/cypress/fixtures/example.json

This file was deleted.

68 changes: 0 additions & 68 deletions e2e-tests/react/cypress/integration/basic_spec.js

This file was deleted.

25 changes: 0 additions & 25 deletions e2e-tests/react/cypress/support/commands.js

This file was deleted.

20 changes: 0 additions & 20 deletions e2e-tests/react/cypress/support/index.js

This file was deleted.

Empty file.
6 changes: 4 additions & 2 deletions e2e-tests/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
"build": "react-scripts build",
"eject": "react-scripts eject",
"test:build": "serve -p 3000 -s build",
"test": "cypress run --record --key $CYPRESS_KEY"
"test": "jest --runInBand"
},
"devDependencies": {
"babel-polyfill": "^6.26.0",
"cypress": "^1.0.3",
"jest": "^21.2.1",
"node-fetch": "^1.7.3",
"npmlog": "^4.1.2",
"puppeteer": "^0.12.0",
"serve": "^6.4.0"
}
}
9 changes: 9 additions & 0 deletions e2e-tests/react/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import log from "npmlog";

export function getContent(page, selector) {
log.info("utils", "query selector: %s", selector);
return page.evaluate(
selector => document.querySelector(selector).textContent,
selector
);
}
Loading

0 comments on commit 6798400

Please sign in to comment.