mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: stop using console.assert everywhere (#2646)
Since Node 10, `console.assert` no longer throws an AssertionError. (This is generally good since it aligns Node.js with Browsers.) This patch migrates all usages of `console.assert` in our codebase. - All the `lib/` and testing code is migrated onto a handmade `assert` function. This is to make Puppeteer transpilation / bundling easier. - All the tooling is switched to use Node's `assert` module. Fixes #2547.
This commit is contained in:
@@ -44,7 +44,8 @@ class Expect {
|
||||
function applyMatcher(matcherName, matcher, inverse, value, ...args) {
|
||||
const result = matcher.call(null, value, ...args);
|
||||
const message = `expect.${inverse ? 'not.' : ''}${matcherName} failed` + (result.message ? `: ${result.message}` : '');
|
||||
console.assert(result.pass !== inverse, message);
|
||||
if (result.pass === inverse)
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ class TestRunner extends EventEmitter {
|
||||
}
|
||||
|
||||
_addHook(hookName, callback) {
|
||||
console.assert(this._currentSuite[hookName] === null, `Only one ${hookName} hook available per suite`);
|
||||
assert(this._currentSuite[hookName] === null, `Only one ${hookName} hook available per suite`);
|
||||
const hook = new UserCallback(callback, this._timeout);
|
||||
this._currentSuite[hookName] = hook;
|
||||
}
|
||||
@@ -389,6 +389,15 @@ class TestRunner extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} value
|
||||
* @param {string=} message
|
||||
*/
|
||||
function assert(value, message) {
|
||||
if (!value)
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
TestRunner.Events = {
|
||||
Started: 'started',
|
||||
TestStarted: 'teststarted',
|
||||
|
||||
Reference in New Issue
Block a user