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

test: add REPORT_ONLY mode for test collection #3225

Merged
merged 1 commit into from
Jul 31, 2020
Merged
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
33 changes: 25 additions & 8 deletions test/jest/playwrightEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ const os = require('os');
const path = require('path');
const fs = require('fs');
const debug = require('debug');
const platform = os.platform();
const platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');
const {installCoverageHooks} = require('./coverage');
const browserName = process.env.BROWSER || 'chromium';
const reportOnly = !!process.env.REPORT_ONLY_PLATFORM;

class PlaywrightEnvironment extends NodeEnvironment {
constructor(config, context) {
Expand Down Expand Up @@ -109,21 +110,32 @@ class PlaywrightEnvironment extends NodeEnvironment {
return args[0] ? describeSkip : this.global.describe;
return describeSkip(...args);
};
this.global.describe.fail = this.global.describe.skip;

function addSlow(f) {
f.slow = () => {
return (...args) => f(...args, 90000);
};
return f;
}

const itSkip = this.global.it.skip;
itSkip.slow = () => itSkip;
addSlow(itSkip);
addSlow(this.global.it);
this.global.it.skip = (...args) => {
if (args.length === 1)
return args[0] ? itSkip : this.global.it;
return itSkip(...args);
};
this.global.it.fail = this.global.it.skip;
this.global.it.slow = () => {
return (name, fn) => {
return this.global.it(name, fn, 90000);
if (reportOnly) {
this.global.it.fail = condition => {
return addSlow((...inner) => {
inner[1].__fail = !!condition;
return this.global.it(...inner);
});
};
};
} else {
this.global.it.fail = this.global.it.skip;
}

const testOptions = this.global.testOptions;
function toBeGolden(received, goldenName) {
Expand Down Expand Up @@ -159,6 +171,11 @@ class PlaywrightEnvironment extends NodeEnvironment {
if (event.name === 'test_start') {
const fn = event.test.fn;
event.test.fn = async () => {
if (reportOnly) {
if (fn.__fail)
throw new Error('fail');
return;
}
debug('pw:test')(`start "${testOrSuiteName(event.test)}"`);
try {
await this.fixturePool.resolveParametersAndRun(fn);
Expand Down
7 changes: 5 additions & 2 deletions test/jest/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
* limitations under the License.
*/

const fs = require("fs")
const fs = require('fs');
const os = require('os');

module.exports = function Reporter() {
this.onRunComplete = (test, runResults) => {
runResults.platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
runResults.browserName = process.env.BROWSER || 'chromium';
fs.writeFileSync('jest-report.json', JSON.stringify(runResults, undefined, 2));
}
};
}
13 changes: 7 additions & 6 deletions test/page.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ describe('Async stacks', () => {
});
});

describe.fail(FFOX && WIN || USES_HOOKS)('Page.Events.Crash', function() {
const CRASH_FAIL = (FFOX && WIN) || USES_HOOKS;
describe('Page.Events.Crash', function() {
// Firefox Win: it just doesn't crash sometimes.

function crash(pageImpl) {
Expand All @@ -125,27 +126,27 @@ describe.fail(FFOX && WIN || USES_HOOKS)('Page.Events.Crash', function() {
pageImpl._delegate._session.send('Page.crash', {}).catch(e => {});
}

it('should emit crash event when page crashes', async({page, toImpl}) => {
it.fail(CRASH_FAIL)('should emit crash event when page crashes', async({page, toImpl}) => {
await page.setContent(`<div>This page should crash</div>`);
crash(toImpl(page));
await new Promise(f => page.on('crash', f));
});
it('should throw on any action after page crashes', async({page, toImpl}) => {
it.fail(CRASH_FAIL)('should throw on any action after page crashes', async({page, toImpl}) => {
await page.setContent(`<div>This page should crash</div>`);
crash(toImpl(page));
await page.waitForEvent('crash');
const err = await page.evaluate(() => {}).then(() => null, e => e);
expect(err).toBeTruthy();
expect(err.message).toContain('crash');
});
it('should cancel waitForEvent when page crashes', async({page, toImpl}) => {
it.fail(CRASH_FAIL)('should cancel waitForEvent when page crashes', async({page, toImpl}) => {
await page.setContent(`<div>This page should crash</div>`);
const promise = page.waitForEvent('response').catch(e => e);
crash(toImpl(page));
const error = await promise;
expect(error.message).toContain('Page crashed');
});
it('should cancel navigation when page crashes', async({page, toImpl, server}) => {
it.fail(CRASH_FAIL)('should cancel navigation when page crashes', async({page, toImpl, server}) => {
await page.setContent(`<div>This page should crash</div>`);
server.setRoute('/one-style.css', () => {});
const promise = page.goto(server.PREFIX + '/one-style.html').catch(e => e);
Expand All @@ -154,7 +155,7 @@ describe.fail(FFOX && WIN || USES_HOOKS)('Page.Events.Crash', function() {
const error = await promise;
expect(error.message).toContain('Navigation failed because page crashed');
});
it('should be able to close context when page crashes', async({page, toImpl}) => {
it.fail(CRASH_FAIL)('should be able to close context when page crashes', async({page, toImpl}) => {
await page.setContent(`<div>This page should crash</div>`);
crash(toImpl(page));
await page.waitForEvent('crash');
Expand Down