chore: introduce debugAssert (#2160)
This commit is contained in:
parent
55a067f543
commit
8e59031078
|
|
@ -21,7 +21,7 @@ import { ConsoleMessage } from './console';
|
||||||
import * as dom from './dom';
|
import * as dom from './dom';
|
||||||
import { TimeoutError, NotConnectedError } from './errors';
|
import { TimeoutError, NotConnectedError } from './errors';
|
||||||
import { Events } from './events';
|
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 js from './javascript';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
|
|
@ -149,7 +149,7 @@ export class FrameManager {
|
||||||
this.removeChildFramesRecursively(frame);
|
this.removeChildFramesRecursively(frame);
|
||||||
frame._url = url;
|
frame._url = url;
|
||||||
frame._name = name;
|
frame._name = name;
|
||||||
assert(!frame._pendingDocumentId || frame._pendingDocumentId === documentId);
|
debugAssert(!frame._pendingDocumentId || frame._pendingDocumentId === documentId);
|
||||||
frame._lastDocumentId = documentId;
|
frame._lastDocumentId = documentId;
|
||||||
frame._pendingDocumentId = '';
|
frame._pendingDocumentId = '';
|
||||||
for (const task of frame._frameTasks)
|
for (const task of frame._frameTasks)
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,21 @@ export function assert(value: any, message?: string): asserts value {
|
||||||
throw new Error(message);
|
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 {
|
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.');
|
assert(count <= max, 'Too many arguments. If you need to pass more than 1 argument to the function wrap them in an object.');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
|
||||||
const TestRunner = require('../utils/testrunner/');
|
const TestRunner = require('../utils/testrunner/');
|
||||||
const {Environment} = require('../utils/testrunner/Test');
|
const {Environment} = require('../utils/testrunner/Test');
|
||||||
|
|
||||||
|
|
@ -74,6 +73,8 @@ function collect(browserNames) {
|
||||||
// TODO: this should be a preinstalled playwright by default.
|
// TODO: this should be a preinstalled playwright by default.
|
||||||
const playwrightPath = config.playwrightPath;
|
const playwrightPath = config.playwrightPath;
|
||||||
const playwright = require(playwrightPath);
|
const playwright = require(playwrightPath);
|
||||||
|
const { setUnderTest } = require(require('path').join(playwrightPath, 'lib/helper.js'));
|
||||||
|
setUnderTest();
|
||||||
|
|
||||||
const playwrightEnvironment = new Environment('Playwright');
|
const playwrightEnvironment = new Environment('Playwright');
|
||||||
playwrightEnvironment.beforeAll(async state => {
|
playwrightEnvironment.beforeAll(async state => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue