mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
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 { 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)
|
||||
|
@ -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.');
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user