| Index: test/_common.js |
| =================================================================== |
| --- a/test/_common.js |
| +++ b/test/_common.js |
| @@ -86,20 +86,16 @@ |
| return {[resourceName]: resources[resourceName]}; |
| throw new Error( |
| "Attempt to import unknown JavaScript module " + resource |
| ); |
| }, |
| reportError(e) {} |
| }, |
| - console: { |
| - log: console.log.bind(console), |
| - error: console.error.bind(console) |
| - }, |
| navigator: { |
| }, |
| onShutdown: { |
| add() {} |
| }, |
| URL |
| }; |
| @@ -416,48 +412,49 @@ |
| } |
| }; |
| }; |
| console.warn = console.log; |
| exports.silenceWarnOutput = function(test, msg) |
| { |
| - let warnHandler = globals.console.warn; |
| - globals.console.warn = s => |
| + let warnHandler = console.warn; |
| + console.warn = s => |
| { |
| if (s != msg) |
| warnHandler(s); |
| }; |
| try |
| { |
| return test(); |
| } |
| finally |
| { |
| - globals.console.warn = warnHandler; |
| + console.warn = warnHandler; |
| } |
| }; |
| exports.silenceAssertionOutput = function(test, msg) |
| { |
| - let msgMatch = new RegExp(`^Error: ${msg}[\r\n]`); |
| - let errorHandler = globals.console.error; |
| - globals.console.error = s => |
| + let msgMatch = new RegExp("^Error: (.*)[\r\n]"); |
|
hub
2017/11/28 19:49:45
Another alternative is:
let msgMatch = new RegExp
Wladimir Palant
2017/11/28 20:00:57
So, what about looking at s.message only?
|
| + let errorHandler = console.error; |
| + console.error = s => |
|
Wladimir Palant
2017/11/28 20:00:57
Nit: Why is this parameter called s? It's not nece
sergei
2017/11/28 20:34:24
It's Error.prototype.stack (https://github.com/adb
hub
2017/11/28 20:54:33
Oh. I see.
In our code, assert2() will always cal
|
| { |
| - if (!msgMatch.test(s)) |
| + let match = s.match(msgMatch); |
| + if (!match || match[1] != msg) |
| errorHandler(s); |
| }; |
| try |
| { |
| return test(); |
| } |
| finally |
| { |
| - globals.console.error = errorHandler; |
| + console.error = errorHandler; |
| } |
| }; |
| exports.setupRandomResult = function() |
| { |
| let randomResult = 0.5; |
| Object.defineProperty(this, "randomResult", { |
| get: () => randomResult, |