Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: introduce debugAssert (#2160)

Pavel Feldman8e5903107833
diff --git a/src/frames.ts b/src/frames.ts
index dbbace39d4..ddd9789579 100644
--- a/src/frames.ts
+++ b/src/frames.ts
@@ -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)
diff --git a/src/helper.ts b/src/helper.ts
index 43b7825da6..b1dbca4fab 100644
--- a/src/helper.ts
+++ b/src/helper.ts
@@ -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.');
}
diff --git a/test/test.js b/test/test.js
index 526393d9aa..844f30c55c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -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 => {