chore: introduce debugAssert (#2160)

This commit is contained in:
Pavel Feldman 2020-05-08 10:37:54 -07:00 committed by GitHub
parent 55a067f543
commit 8e59031078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -21,7 +21,7 @@ import { ConsoleMessage } from './console';
import * as dom from './dom';
import { TimeoutError, NotConnectedError } from './errors';
import { Events } from './events';
import { assert, helper, RegisteredListener, assertMaxArguments } from './helper';
import { assert, helper, RegisteredListener, assertMaxArguments, debugAssert } from './helper';
import * as js from './javascript';
import * as network from './network';
import { Page } from './page';
@ -149,7 +149,7 @@ export class FrameManager {
this.removeChildFramesRecursively(frame);
frame._url = url;
frame._name = name;
assert(!frame._pendingDocumentId || frame._pendingDocumentId === documentId);
debugAssert(!frame._pendingDocumentId || frame._pendingDocumentId === documentId);
frame._lastDocumentId = documentId;
frame._pendingDocumentId = '';
for (const task of frame._frameTasks)

View File

@ -337,6 +337,21 @@ export function assert(value: any, message?: string): asserts value {
throw new Error(message);
}
let _isUnderTest = false;
export function setUnderTest() {
_isUnderTest = true;
}
export function isUnderTest(): boolean {
return _isUnderTest;
}
export function debugAssert(value: any, message?: string): asserts value {
if (_isUnderTest && !value)
throw new Error(message);
}
export function assertMaxArguments(count: number, max: number): asserts count {
assert(count <= max, 'Too many arguments. If you need to pass more than 1 argument to the function wrap them in an object.');
}

View File

@ -16,7 +16,6 @@
*/
const fs = require('fs');
const readline = require('readline');
const TestRunner = require('../utils/testrunner/');
const {Environment} = require('../utils/testrunner/Test');
@ -74,6 +73,8 @@ function collect(browserNames) {
// TODO: this should be a preinstalled playwright by default.
const playwrightPath = config.playwrightPath;
const playwright = require(playwrightPath);
const { setUnderTest } = require(require('path').join(playwrightPath, 'lib/helper.js'));
setUnderTest();
const playwrightEnvironment = new Environment('Playwright');
playwrightEnvironment.beforeAll(async state => {