Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/_common.js

Issue 29616611: Issue 6090 - Allow use of console to be seen during tests (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added missing patch. Review feedback Created Nov. 24, 2017, 3:48 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/filterStorage.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/_common.js
===================================================================
--- a/test/_common.js
+++ b/test/_common.js
@@ -87,18 +87,18 @@
throw new Error(
"Attempt to import unknown JavaScript module " + resource
);
},
reportError(e) {}
},
console: {
- log() {},
- error() {}
+ log: console.log.bind(console),
+ error: console.error.bind(console)
},
navigator: {
},
onShutdown: {
add() {}
},
URL
};
@@ -414,16 +414,37 @@
Date: {
now: () => currentTime
}
};
};
console.warn = console.log;
+exports.silenceAssertionOutput = function(test, msg)
+{
+ let msgMatch = new RegExp(`^Error: ${msg}[\r\n]`);
+ let errorHandler = globals.console.error;
+ globals.console.error = s =>
+ {
+ if (!msgMatch.test(s))
+ errorHandler(s);
+ };
+ let result;
+ try
+ {
+ result = test();
sergei 2017/11/24 16:46:27 There is no necessity in an additional variable, c
hub 2017/11/24 18:17:56 For some reason I believed that return would by-pa
+ }
+ finally
+ {
+ globals.console.error = errorHandler;
+ }
+ return result;
+};
+
exports.setupRandomResult = function()
{
let randomResult = 0.5;
Object.defineProperty(this, "randomResult", {
get: () => randomResult,
set: value => randomResult = value
});
« no previous file with comments | « no previous file | test/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld