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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/filterStorage.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (resourceName && resources.hasOwnProperty(resourceName)) 85 if (resourceName && resources.hasOwnProperty(resourceName))
86 return {[resourceName]: resources[resourceName]}; 86 return {[resourceName]: resources[resourceName]};
87 87
88 throw new Error( 88 throw new Error(
89 "Attempt to import unknown JavaScript module " + resource 89 "Attempt to import unknown JavaScript module " + resource
90 ); 90 );
91 }, 91 },
92 reportError(e) {} 92 reportError(e) {}
93 }, 93 },
94 console: { 94 console: {
95 log() {}, 95 log: console.log.bind(console),
96 error() {} 96 error: console.error.bind(console)
97 }, 97 },
98 navigator: { 98 navigator: {
99 }, 99 },
100 onShutdown: { 100 onShutdown: {
101 add() {} 101 add() {}
102 }, 102 },
103 URL 103 URL
104 }; 104 };
105 105
106 let knownModules = new Map(); 106 let knownModules = new Map();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 Cr, 412 Cr,
413 XMLHttpRequest, 413 XMLHttpRequest,
414 Date: { 414 Date: {
415 now: () => currentTime 415 now: () => currentTime
416 } 416 }
417 }; 417 };
418 }; 418 };
419 419
420 console.warn = console.log; 420 console.warn = console.log;
421 421
422 exports.silenceAssertionOutput = function(test, msg)
423 {
424 let msgMatch = new RegExp(`^Error: ${msg}[\r\n]`);
425 let errorHandler = globals.console.error;
426 globals.console.error = s =>
427 {
428 if (!msgMatch.test(s))
429 errorHandler(s);
430 };
431 let result;
432 try
433 {
434 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
435 }
436 finally
437 {
438 globals.console.error = errorHandler;
439 }
440 return result;
441 };
442
422 exports.setupRandomResult = function() 443 exports.setupRandomResult = function()
423 { 444 {
424 let randomResult = 0.5; 445 let randomResult = 0.5;
425 Object.defineProperty(this, "randomResult", { 446 Object.defineProperty(this, "randomResult", {
426 get: () => randomResult, 447 get: () => randomResult,
427 set: value => randomResult = value 448 set: value => randomResult = value
428 }); 449 });
429 450
430 return { 451 return {
431 Math: Object.create(Math, { 452 Math: Object.create(Math, {
432 random: { 453 random: {
433 value: () => randomResult 454 value: () => randomResult
434 } 455 }
435 }) 456 })
436 }; 457 };
437 }; 458 };
438 459
439 exports.unexpectedError = function(error) 460 exports.unexpectedError = function(error)
440 { 461 {
441 console.error(error); 462 console.error(error);
442 this.ok(false, "Unexpected error: " + error); 463 this.ok(false, "Unexpected error: " + error);
443 }; 464 };
OLDNEW
« 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