OLD | NEW |
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 let resourceName = match && match[1]; | 84 let resourceName = match && match[1]; |
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: { | |
95 log: console.log.bind(console), | |
96 error: console.error.bind(console) | |
97 }, | |
98 navigator: { | 94 navigator: { |
99 }, | 95 }, |
100 onShutdown: { | 96 onShutdown: { |
101 add() {} | 97 add() {} |
102 }, | 98 }, |
103 URL | 99 URL |
104 }; | 100 }; |
105 | 101 |
106 let knownModules = new Map(); | 102 let knownModules = new Map(); |
107 for (let dir of [path.join(__dirname, "stub-modules"), | 103 for (let dir of [path.join(__dirname, "stub-modules"), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 Date: { | 410 Date: { |
415 now: () => currentTime | 411 now: () => currentTime |
416 } | 412 } |
417 }; | 413 }; |
418 }; | 414 }; |
419 | 415 |
420 console.warn = console.log; | 416 console.warn = console.log; |
421 | 417 |
422 exports.silenceWarnOutput = function(test, msg) | 418 exports.silenceWarnOutput = function(test, msg) |
423 { | 419 { |
424 let warnHandler = globals.console.warn; | 420 let warnHandler = console.warn; |
425 globals.console.warn = s => | 421 console.warn = (...args) => |
426 { | 422 { |
| 423 let s = (args[0] instanceof Error ? args[0].message : args[0]); |
| 424 |
427 if (s != msg) | 425 if (s != msg) |
428 warnHandler(s); | 426 warnHandler(...args); |
429 }; | 427 }; |
430 try | 428 try |
431 { | 429 { |
432 return test(); | 430 return test(); |
433 } | 431 } |
434 finally | 432 finally |
435 { | 433 { |
436 globals.console.warn = warnHandler; | 434 console.warn = warnHandler; |
437 } | 435 } |
438 }; | 436 }; |
439 | 437 |
440 exports.silenceAssertionOutput = function(test, msg) | 438 exports.silenceAssertionOutput = function(test, msg) |
441 { | 439 { |
442 let msgMatch = new RegExp(`^Error: ${msg}[\r\n]`); | 440 let msgMatch = new RegExp("^Error: (.*)[\r\n]"); |
443 let errorHandler = globals.console.error; | 441 let errorHandler = console.error; |
444 globals.console.error = s => | 442 console.error = (...args) => |
445 { | 443 { |
446 if (!msgMatch.test(s)) | 444 let s = (args[0] instanceof Error ? args[0].message : args[0]); |
447 errorHandler(s); | 445 let match = s && s.match(msgMatch); |
| 446 if (!match || match[1] != msg) |
| 447 errorHandler(...args); |
448 }; | 448 }; |
449 try | 449 try |
450 { | 450 { |
451 return test(); | 451 return test(); |
452 } | 452 } |
453 finally | 453 finally |
454 { | 454 { |
455 globals.console.error = errorHandler; | 455 console.error = errorHandler; |
456 } | 456 } |
457 }; | 457 }; |
458 | 458 |
459 exports.setupRandomResult = function() | 459 exports.setupRandomResult = function() |
460 { | 460 { |
461 let randomResult = 0.5; | 461 let randomResult = 0.5; |
462 Object.defineProperty(this, "randomResult", { | 462 Object.defineProperty(this, "randomResult", { |
463 get: () => randomResult, | 463 get: () => randomResult, |
464 set: value => randomResult = value | 464 set: value => randomResult = value |
465 }); | 465 }); |
466 | 466 |
467 return { | 467 return { |
468 Math: Object.create(Math, { | 468 Math: Object.create(Math, { |
469 random: { | 469 random: { |
470 value: () => randomResult | 470 value: () => randomResult |
471 } | 471 } |
472 }) | 472 }) |
473 }; | 473 }; |
474 }; | 474 }; |
475 | 475 |
476 exports.unexpectedError = function(error) | 476 exports.unexpectedError = function(error) |
477 { | 477 { |
478 console.error(error); | 478 console.error(error); |
479 this.ok(false, "Unexpected error: " + error); | 479 this.ok(false, "Unexpected error: " + error); |
480 }; | 480 }; |
OLD | NEW |