Skip to content

Commit

Permalink
Merge pull request #2 from Russo-creation/jest-and-puppeteer
Browse files Browse the repository at this point in the history
fix jest e2e test
  • Loading branch information
Russo-creation authored Dec 21, 2020
2 parents 91d8f82 + 224d4dd commit 50e43db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
Binary file modified frontend/__image_snapshots__/customSnapshotName-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
56 changes: 35 additions & 21 deletions frontend/src/components/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import puppeteer from 'puppeteer';

import {globalTestFunction} from "../../testGlobalFunctions"

function sleep(millisecondsCount) {
if (!millisecondsCount) {
return;
}
return new Promise(resolve => setTimeout(resolve, millisecondsCount)).catch();
}

describe('image-snapshot', () => {
globalTestFunction();

Expand All @@ -34,33 +41,40 @@ describe('image-snapshot', () => {

it('visual regression test', async done => {
try {
await page.goto(`${process.env.REACT_APP_FRONTEND_URL}/`, { waitUntil: 'load' });
await page.goto(`${process.env.REACT_APP_FRONTEND_URL}/`, { waitUntil: ['load', 'domcontentloaded', 'networkidle2'], timeout: 12000 });

//write to input id="myinput" value Hello
await page.type('#myinput', 'Hello');
await page.evaluateHandle('document.fonts.ready').then(async() => {

//check if page title equals React App
//await expect(page.title()).resolves.toMatch('React App');
//write to input id="myinput" value Hello
await page.type('#myinput', 'Hello');

// await expect(page).toMatch('GraphQL');
//check if page title equals React App
//await expect(page.title()).resolves.toMatch('React App');

// await page.reload({waitUntil: 'networkidle0'});

//add timeout for something
// await page.waitForTimeout(1000).then(() => console.log('Waited a second!'));
// await expect(page).toMatch('GraphQL');

const image = await page.screenshot({
fullPage: true,
});
expect(image).toMatchImageSnapshot({
customSnapshotsDir: "./__image_snapshots__/",
customSnapshotIdentifier: 'customSnapshotName',
// customDiffDir: "./__image_snapshots__/",
failureThreshold: 0.005,
failureThresholdType: 'percent'
});
// await page.reload({waitUntil: 'networkidle0'});

//add timeout for something
// await page.waitForTimeout(1000).then(() => console.log('Waited a second!'));

const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
await page.setViewport({ width: 300, height: bodyHeight });

const image = await page.screenshot({
//fullPage: true,
});
expect(image).toMatchImageSnapshot({
customSnapshotsDir: "./__image_snapshots__/",
customSnapshotIdentifier: 'customSnapshotName',
// customDiffDir: "./__image_snapshots__/",
failureThreshold: 0.005,
failureThresholdType: 'percent'
});

done();

done();
});
} catch (err) {
console.log(err);
}
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/style/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
font-family: 'Roboto', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
font-family: 'Roboto', sans-serif;
}

0 comments on commit 50e43db

Please sign in to comment.