Skip to content

Commit ecc130c

Browse files
authored
test: convert evaluation.spec to jest+fixtures (#2968)
1 parent 7080767 commit ecc130c

File tree

12 files changed

+361
-83
lines changed

12 files changed

+361
-83
lines changed

.github/workflows/tests.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141
env:
4242
BROWSER: ${{ matrix.browser }}
4343
DEBUG: "*,-pw:wrapped*"
44-
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest 2>>./testrun.log"
44+
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
45+
if: ${{ always() }}
4546
env:
4647
BROWSER: ${{ matrix.browser }}
47-
DEBUG: "*,-pw:wrapped*"
4848
- uses: actions/upload-artifact@v1
4949
if: failure()
5050
with:
@@ -80,10 +80,10 @@ jobs:
8080
env:
8181
BROWSER: ${{ matrix.browser }}
8282
DEBUG: "*,-pw:wrapped*"
83-
- run: npm run jest 2>>./${{ matrix.browser }}-mac-testrun.log
83+
- run: npm run jest -- --testTimeout=30000
84+
if: ${{ always() }}
8485
env:
8586
BROWSER: ${{ matrix.browser }}
86-
DEBUG: "*,-pw:wrapped*"
8787
- uses: actions/upload-artifact@v1
8888
if: failure()
8989
with:
@@ -115,11 +115,11 @@ jobs:
115115
env:
116116
BROWSER: ${{ matrix.browser }}
117117
DEBUG: "*,-pw:wrapped*"
118-
- run: npm run jest 2>>./${{ matrix.browser }}-win-testrun.log
118+
- run: npm run jest -- --testTimeout=30000
119+
if: ${{ always() }}
119120
shell: bash
120121
env:
121122
BROWSER: ${{ matrix.browser }}
122-
DEBUG: "*,-pw:wrapped*"
123123
- uses: actions/upload-artifact@v1
124124
if: failure()
125125
with:
@@ -170,6 +170,21 @@ jobs:
170170
env:
171171
DEBUG: "*"
172172
HEADLESS: "false"
173+
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
174+
if: ${{ always() }}
175+
env:
176+
BROWSER: "chromium"
177+
HEADLESS: "false"
178+
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
179+
if: ${{ always() }}
180+
env:
181+
BROWSER: "firefox"
182+
HEADLESS: "false"
183+
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
184+
if: ${{ always() }}
185+
env:
186+
BROWSER: "webkit"
187+
HEADLESS: "false"
173188
- uses: actions/upload-artifact@v1
174189
if: failure()
175190
with:
@@ -208,6 +223,11 @@ jobs:
208223
BROWSER: ${{ matrix.browser }}
209224
DEBUG: "*,-pw:wrapped*"
210225
PWCHANNEL: ${{ matrix.transport }}
226+
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
227+
if: ${{ always() }}
228+
env:
229+
BROWSER: ${{ matrix.browser }}
230+
PWCHANNEL: ${{ matrix.transport }}
211231
- uses: actions/upload-artifact@v1
212232
if: failure()
213233
with:

jest.config.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2-
"rootDir": "./test/jest",
3-
"testEnvironment": ".",
4-
"testMatch": ["**/?(*.)spec.[jt]s"],
5-
"testRunner": "jest-circus/runner"
2+
"rootDir": "./test",
3+
"testEnvironment": "./jest",
4+
"testMatch": ["**/?(*.)jest.[jt]s"],
5+
"testRunner": "jest-circus/runner",
6+
"testTimeout": 10000,
7+
"globalSetup": "./jest/setup.js",
8+
"globalTeardown": "./jest/teardown.js"
69
}

package-lock.json

Lines changed: 125 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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
"ftest": "cross-env BROWSER=firefox node --unhandled-rejections=strict test/test.js",
1717
"wtest": "cross-env BROWSER=webkit node --unhandled-rejections=strict test/test.js",
1818
"test": "cross-env node --unhandled-rejections=strict test/test.js",
19-
"cunit": "cross-env BROWSER=chromium node --unhandled-rejections=strict test/test.js",
20-
"funit": "cross-env BROWSER=firefox node --unhandled-rejections=strict test/test.js",
21-
"wunit": "cross-env BROWSER=webkit node --unhandled-rejections=strict test/test.js",
22-
"unit": "cross-env node --unhandled-rejections=strict test/test.js",
2319
"ccoverage": "cross-env COVERAGE=true BROWSER=chromium node --unhandled-rejections=strict test/test.js",
2420
"fcoverage": "cross-env COVERAGE=true BROWSER=firefox node --unhandled-rejections=strict test/test.js",
2521
"wcoverage": "cross-env COVERAGE=true BROWSER=webkit node --unhandled-rejections=strict test/test.js",
@@ -83,6 +79,7 @@
8379
"formidable": "^1.2.1",
8480
"jest": "^26.1.0",
8581
"jest-circus": "^26.1.0",
82+
"jest-image-snapshot": "^4.0.2",
8683
"ncp": "^2.0.0",
8784
"node-stream-zip": "^1.8.2",
8885
"pirates": "^4.0.1",

src/common/utilityScriptSerializers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17+
function isRegExp(obj: any): obj is RegExp {
18+
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
19+
}
20+
21+
function isDate(obj: any): obj is Date {
22+
return obj instanceof Date || Object.prototype.toString.call(obj) === '[object Date]';
23+
}
24+
1725
export function parseEvaluationResultValue(value: any, handles: any[] = []): any {
1826
if (value === undefined)
1927
return undefined;
@@ -85,9 +93,9 @@ function serialize(value: any, jsHandleSerializer: (value: any) => { fallThrough
8593
}
8694
return `${error.name}: ${error.message}\n${error.stack}`;
8795
}
88-
if (value instanceof Date)
96+
if (isDate(value))
8997
return { d: value.toJSON() };
90-
if (value instanceof RegExp)
98+
if (isRegExp(value))
9199
return { r: [ value.source, value.flags ] };
92100

93101
if (Array.isArray(value)) {

test/environments.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ class PlaywrightEnvironment {
180180
if (!this.expectExit)
181181
throw new Error(`Server closed with exitCode=${exitCode} signal=${signal}`);
182182
});
183-
process.on('exit', () => this._killProcess());
184183
const transport = new Transport(this.spawnedProcess.stdin, this.spawnedProcess.stdout);
185184
connection.onmessage = message => transport.send(JSON.stringify(message));
186185
transport.onmessage = message => connection.dispatch(JSON.parse(message));
@@ -213,20 +212,6 @@ class PlaywrightEnvironment {
213212
}
214213
delete state.playwright;
215214
}
216-
217-
_killProcess() {
218-
if (this.spawnedProcess && this.spawnedProcess.pid) {
219-
this.expectExit = true;
220-
try {
221-
if (process.platform === 'win32')
222-
childProcess.execSync(`taskkill /pid ${this.spawnedProcess.pid} /T /F`);
223-
else
224-
process.kill(-this.spawnedProcess.pid, 'SIGKILL');
225-
} catch (e) {
226-
// the process might have already stopped
227-
}
228-
}
229-
}
230215
}
231216

232217
class BrowserTypeEnvironment {

test/evaluation.spec.js renamed to test/evaluation.jest.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
const utils = require('./utils');
1919
const path = require('path');
20-
const {FFOX, CHROMIUM, WEBKIT, USES_HOOKS, CHANNEL} = utils.testOptions(browserType);
2120

2221
describe('Page.evaluate', function() {
2322
it('should work', async({page, server}) => {
@@ -357,7 +356,7 @@ describe('Page.evaluate', function() {
357356
});
358357
expect(result).toEqual([42]);
359358
});
360-
it.fail(WEBKIT)('should not throw an error when evaluation does a synchronous navigation and returns an object', async({page, server}) => {
359+
(WEBKIT ? it.skip : it)('should not throw an error when evaluation does a synchronous navigation and returns an object', async({page, server}) => {
361360
// It is imporant to be on about:blank for sync reload.
362361
const result = await page.evaluate(() => {
363362
window.location.reload();
@@ -373,7 +372,7 @@ describe('Page.evaluate', function() {
373372
});
374373
expect(result).toBe(undefined);
375374
});
376-
it.slow().skip(CHANNEL)('should transfer 100Mb of data from page to node.js', async({page, server}) => {
375+
(CHANNEL ? it.skip : it)('should transfer 100Mb of data from page to node.js', async({page}) => {
377376
const a = await page.evaluate(() => Array(100 * 1024 * 1024 + 1).join('a'));
378377
expect(a.length).toBe(100 * 1024 * 1024);
379378
});
@@ -389,7 +388,7 @@ describe('Page.evaluate', function() {
389388
const result = await page.evaluate(() => ({abc: 123}));
390389
expect(result).toEqual({abc: 123});
391390
});
392-
it.fail(FFOX)('should await promise from popup', async function({page, server}) {
391+
(FFOX ? it.skip : it)('should await promise from popup', async ({page, server}) => {
393392
// Something is wrong about the way Firefox waits for the chained promise
394393
await page.goto(server.EMPTY_PAGE);
395394
const result = await page.evaluate(() => {
@@ -574,14 +573,14 @@ describe('Frame.evaluate', function() {
574573
else
575574
expect(pageImpl._delegate._contextIdToContext.size).toBe(count);
576575
}
577-
it.skip(USES_HOOKS)('should dispose context on navigation', async({page, server, toImpl}) => {
576+
(USES_HOOKS ? it.skip : it)('should dispose context on navigation', async({page, server, toImpl}) => {
578577
await page.goto(server.PREFIX + '/frames/one-frame.html');
579578
expect(page.frames().length).toBe(2);
580579
expectContexts(toImpl(page), 4);
581580
await page.goto(server.EMPTY_PAGE);
582581
expectContexts(toImpl(page), 2);
583582
});
584-
it.skip(USES_HOOKS)('should dispose context on cross-origin navigation', async({page, server, toImpl}) => {
583+
(USES_HOOKS ? it.skip : it)('should dispose context on cross-origin navigation', async({page, server, toImpl}) => {
585584
await page.goto(server.PREFIX + '/frames/one-frame.html');
586585
expect(page.frames().length).toBe(2);
587586
expectContexts(toImpl(page), 4);

0 commit comments

Comments
 (0)