Skip to content

Commit f2f5833

Browse files
authored
Merge pull request #184 from defmethodinc/feature/e2e-performance-tests
Feature/e2e performance tests
2 parents a4c5618 + 3913642 commit f2f5833

17 files changed

+1899
-96
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build/
33
dist/
44
gulpfile.js
55
webpack.config.js
6+
jest-puppeteer.config.js

.eslintrc.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
"analytics": true,
1515
"window": true,
1616
"document": true,
17-
"global": true
17+
"global": true,
18+
"page": true,
19+
"browser": true,
20+
"context": true,
21+
"jestPuppeteer": true
1822
},
1923
"parser": "babel-eslint",
2024
"settings": {},
@@ -33,8 +37,9 @@
3337
},
3438
"overrides": [
3539
{
36-
"files": "**/*Spec.test.js",
40+
"files": "**/*.test.js",
3741
"env": {
42+
"node": true,
3843
"jest": true,
3944
"es6": true
4045
},

.github/workflows/nodejs.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ jobs:
2828
run: npm run build
2929
- name: Run tests
3030
run: npm test
31-
env:
32-
CI: true
31+
- name: Run e2e tests
32+
run: |
33+
export DISPLAY=:99
34+
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
35+
npm run e2e
3336
- name: Semantic Release
3437
env:
3538
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

.jest.puppeteer.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'jest-puppeteer',
3+
globalSetup: './e2e/global-setup.js',
4+
globalTeardown: './e2e/global-teardown.js',
5+
};

e2e/global-setup.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { e2eSetup } from './utility.js';
2+
import { setup } from 'jest-environment-puppeteer';
3+
4+
export default async function globalSetup(globalConfig) {
5+
e2eSetup();
6+
await setup(globalConfig);
7+
}

e2e/global-teardown.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { e2eTeardown } from './utility.js';
2+
import { teardown } from 'jest-environment-puppeteer';
3+
4+
export default async function globalTeardown(globalConfig) {
5+
await teardown(globalConfig);
6+
e2eTeardown();
7+
}

e2e/local.perf.test.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import * as path from 'path';
2+
import * as Util from '../src/helpers/util.js';
3+
4+
const ONE_MINUTE = 5000 * 12;
5+
jest.setTimeout(ONE_MINUTE * 2);
6+
7+
const TEST_WAIT_TIME = Util.WAIT_TIME + 100;
8+
const TEST_PAGE = path.join(__dirname, '..', 'public', 'jns-test.html');
9+
10+
async function assertWarnings(expected, options) {
11+
if (expected > 0) {
12+
await page.waitForSelector('.jns-highlight', options);
13+
}
14+
const numWarnings = await page.$$('.jns-highlight');
15+
//longer phrases can wrap lines and create multiple tooltips
16+
await expect(numWarnings.length).toBeGreaterThanOrEqual(expected);
17+
}
18+
19+
describe('Just Not Sorry', () => {
20+
beforeEach(async () => {
21+
await page.goto(`file://${TEST_PAGE}`);
22+
await page.waitForTimeout(500);
23+
await page.click('#email');
24+
await assertWarnings(0, { visible: false, timeout: TEST_WAIT_TIME });
25+
});
26+
27+
it('should work', async () => {
28+
await page.keyboard.type(`just not sorry.`);
29+
await page.keyboard.press('Enter');
30+
await page.keyboard.press('Enter');
31+
32+
//blur
33+
await page.keyboard.down('Shift');
34+
await page.keyboard.press('Tab');
35+
await page.keyboard.up('Shift');
36+
await assertWarnings(2, { visible: false, timeout: TEST_WAIT_TIME });
37+
38+
//focus
39+
await page.keyboard.press('Tab');
40+
await assertWarnings(2, { visible: true, timeout: TEST_WAIT_TIME });
41+
});
42+
43+
it('should display 500 words with 200 warnings', async () => {
44+
const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`;
45+
expect(fiftyWords.split(' ').length).toBe(50);
46+
47+
for (let i = 0; i < 500 / 50; i++) {
48+
await page.keyboard.type(fiftyWords);
49+
await page.keyboard.press('Enter');
50+
await page.keyboard.press('Enter');
51+
52+
//blur
53+
await page.keyboard.down('Shift');
54+
await page.keyboard.press('Tab', { delay: 500 });
55+
await page.keyboard.up('Shift');
56+
const numExpected = 20 * (i + 1);
57+
await assertWarnings(numExpected, {
58+
visible: false,
59+
timeout: TEST_WAIT_TIME,
60+
});
61+
62+
//focus
63+
await page.keyboard.press('Tab', { delay: 500 });
64+
await assertWarnings(numExpected, {
65+
visible: true,
66+
timeout: TEST_WAIT_TIME,
67+
});
68+
}
69+
});
70+
71+
it('should display 1000 words with 400 warnings with blur', async () => {
72+
const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`;
73+
expect(fiftyWords.split(' ').length).toBe(50);
74+
75+
for (let i = 0; i < 1000 / 50; i++) {
76+
await page.keyboard.type(fiftyWords);
77+
await page.keyboard.press('Enter');
78+
await page.keyboard.press('Enter');
79+
80+
//blur
81+
await page.keyboard.down('Shift');
82+
await page.keyboard.press('Tab', { delay: 500 });
83+
await page.keyboard.up('Shift');
84+
const numExpected = 20 * (i + 1);
85+
await assertWarnings(numExpected, {
86+
visible: false,
87+
timeout: TEST_WAIT_TIME,
88+
});
89+
90+
//focus
91+
await page.keyboard.press('Tab', { delay: 500 });
92+
await assertWarnings(numExpected, {
93+
visible: true,
94+
timeout: TEST_WAIT_TIME,
95+
});
96+
}
97+
});
98+
99+
it('should display 1000 words with 400 warnings with delay', async () => {
100+
const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`;
101+
expect(fiftyWords.split(' ').length).toBe(50);
102+
103+
for (let i = 0; i < 1000 / 50; i++) {
104+
await page.keyboard.type(fiftyWords);
105+
await page.keyboard.press('Enter');
106+
await page.keyboard.press('Enter');
107+
108+
await page.waitForTimeout(500);
109+
await assertWarnings(20 * (i + 1), {
110+
visible: true,
111+
timeout: TEST_WAIT_TIME,
112+
});
113+
}
114+
});
115+
});

e2e/utility.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
// eslint-disable-next-line no-undef
5+
const manifestPath = path.join(__dirname, '..', 'build', 'manifest.json');
6+
export function e2eSetup() {
7+
fs.readFile(manifestPath, (err, data) => {
8+
if (err) throw err;
9+
const newValue = data
10+
.toString()
11+
.replace(
12+
'https://mail.google.com/*',
13+
'file:///*/just-not-sorry/public/jns-test.html'
14+
);
15+
fs.writeFile(manifestPath, newValue, 'utf-8', function (err) {
16+
if (err) throw err;
17+
});
18+
});
19+
}
20+
export function e2eTeardown() {
21+
fs.readFile(manifestPath, (err, data) => {
22+
if (err) throw err;
23+
const newValue = data
24+
.toString()
25+
.replace(
26+
'file:///*/just-not-sorry/public/jns-test.html',
27+
'https://mail.google.com/*'
28+
);
29+
fs.writeFile(manifestPath, newValue, 'utf-8', function (err) {
30+
if (err) throw err;
31+
});
32+
});
33+
}

jest-puppeteer.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//This filename is the default path for jest config
2+
module.exports = {
3+
launch: {
4+
headless: false,
5+
slowMo: false,
6+
devtools: false,
7+
args: [
8+
`--disable-extensions-except=build`,
9+
`--load-extension=build`,
10+
`--window-size=800,800`,
11+
],
12+
},
13+
};

0 commit comments

Comments
 (0)