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,61 @@ |
} |
}; |
}; |
console.warn = console.log; |
exports.silenceWarnOutput = function(test, msg) |
{ |
- let warnHandler = globals.console.warn; |
- globals.console.warn = s => |
+ let warnHandler = console.warn; |
+ console.warn = (...args) => |
{ |
+ let s; |
+ if (typeof args[0] === "string") |
sergei
2017/11/29 09:31:53
To be consistent with other JS code it should not
|
+ s = args[0]; |
+ else |
+ s = args[0].message; |
sergei
2017/11/29 09:31:54
args[0] can be undefined and before accessing `mes
Wladimir Palant
2017/11/29 10:27:31
Yes, the better approach is:
let s = (args[0] i
hub
2017/11/29 15:22:32
Done.
|
+ |
if (s != msg) |
- warnHandler(s); |
+ warnHandler(args); |
sergei
2017/11/29 09:31:53
strictly speaking it should be warnHandler.warn.ap
Wladimir Palant
2017/11/29 10:27:31
This should be `warnHandler(...args)` - pass the o
hub
2017/11/29 15:22:32
Done.
|
}; |
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]"); |
+ let errorHandler = console.error; |
+ console.error = (...args) => |
{ |
- if (!msgMatch.test(s)) |
- errorHandler(s); |
+ let s; |
+ if (typeof args[0] === "string") |
+ s = args[0]; |
+ else |
+ s = args[0].message; |
+ |
+ let match = s && s.match(msgMatch); |
+ if (!match || match[1] != msg) |
Wladimir Palant
2017/11/29 10:27:31
So why still use the regular expression if you are
hub
2017/11/29 15:22:32
We want to silence an assert (call to our assert2(
|
+ errorHandler(args); |
}; |
try |
{ |
return test(); |
} |
finally |
{ |
- globals.console.error = errorHandler; |
+ console.error = errorHandler; |
} |
}; |
exports.setupRandomResult = function() |
{ |
let randomResult = 0.5; |
Object.defineProperty(this, "randomResult", { |
get: () => randomResult, |