Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e #238

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

E2e #238

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
- run: |
yarn test --coverage --coverageDirectory=./coverage

- run: |
mkdir __screenshots__
TEST_SCREENSHOT_PATH=__screenshots__ yarn test:e2e

- uses: codecov/codecov-action@v1.1.1

- if: ${{ github.ref == 'master' }}
Expand Down
43 changes: 43 additions & 0 deletions e2e/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as path from "path";

jest.setTimeout(5 * 60 * 1000);

const screenshotPath = process.env["TEST_SCREENSHOT_PATH"];

const maySaveScreenshot = async (filename: string): Promise<void> => {
if (screenshotPath) {
await page.screenshot({
path: path.join(screenshotPath, filename),
fullPage: true,
});
}
};


describe("fuTimer", () => {
beforeEach(async () => {
await page.goto("http://localhost:3232/futimer", {
waitUntil: "networkidle0",
});
});

it("should render", async () => {
await page.waitForTimeout(2000);

await expect(page.title()).resolves.toMatch("fuTimer");

await expect(
page.$eval("[data-testid=scramble]", (el) => el.textContent)
).resolves.toMatch(/[UBRLFB' ]+/);

await maySaveScreenshot("01-loaded.png");

await page.click("[data-testid=timerButton]", { delay: 1000 });

await new Promise((resolve) => setTimeout(resolve, 2000));

await expect(page.$eval("[data-testid=timerButton]", (el) => parseFloat(el.textContent || ""))).resolves.toBeGreaterThan(2.0);

await maySaveScreenshot("02-timer-running.png");
});
});
6 changes: 6 additions & 0 deletions e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: "jest-puppeteer",
transform: {
".tsx?$": "ts-jest",
},
};
Empty file added e2e/server.js
Empty file.
6 changes: 6 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"isolatedModules": false
}
}
21 changes: 21 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const debug = !!process.env["DEBUG"];
const path = require('path');

module.exports = {
launch: {
headless: debug ? false : true,
devtools: debug ? true : false,
slowMo: debug ? 500 : 0,
args: [
"--enable-logging",
"--log-file=" + path.join(process.cwd(), 'chrome.log'),
]
},
server: {
command: "PORT=3232 BROWSER=none yarn start",
port: 3232,
launchTimeout: 30 * 1000,
debug: true,
usedPortAction: "ask",
},
};
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"test:e2e": "jest -c ./e2e/jest.config.js --detectOpenHandles"
},
"devDependencies": {
"gh-pages": "3.1.0",
"@types/classnames": "2.2.11",
"@types/gapi.auth2": "0.0.52",
"@types/gapi.client.drive": "3.0.13",
"@types/gapi.client.sheets": "4.0.20201029",
"@types/jest": "24.9.1",
"@types/jest-environment-puppeteer": "^4.4.1",
"@types/node": "12.19.9",
"@types/react": "16.14.2",
"@types/react-dom": "16.9.10",
Expand All @@ -42,8 +43,14 @@
"@types/redux-actions": "2.6.1",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-prettier": "3.1.4",
"express": "^4.17.1",
"gh-pages": "3.1.0",
"jest-environment-puppeteer": "^5.0.4",
"jest-puppeteer": "^5.0.4",
"prettier": "2.1.2",
"puppeteer": "<10",
"react-scripts": "4.0.0",
"ts-jest": "^26",
"typescript": "4.0.5"
},
"resolutions": {
Expand All @@ -66,5 +73,10 @@
"react-app",
"plugin:prettier/recommended"
]
},
"jest": {
"transform": {
".tsx?$": "ts-jest"
}
}
}
3 changes: 2 additions & 1 deletion src/components/Measurer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ class Measurer extends React.Component<Props, State> {
[this.props.classes.isLoading]: !this.props.scramble,
})}
>
<code>
<code data-testid="scramble">
{this.props.scramble || this.prevScramble || "Generating…"}
</code>
</div>
<ButtonBase
data-testid="timerButton"
action={this.handleButtonMount}
onTouchStart={this.handleHoldStart}
onTouchEnd={this.handleHoldEnd}
Expand Down
Loading