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

Side by Side Diff: test/_common.js

Issue 29355872: Issue 4223 - Adapt synchronizer tests to work in adblockpluscore repository (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created Oct. 5, 2016, 8:05 a.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/filterListener.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let fs = require("fs"); 20 let fs = require("fs");
21 let path = require("path"); 21 let path = require("path");
22 let SandboxedModule = require("sandboxed-module"); 22 let SandboxedModule = require("sandboxed-module");
23 23
24 let globals = { 24 let globals = {
25 atob: data => new Buffer(data, "base64").toString("binary"), 25 atob: data => new Buffer(data, "base64").toString("binary"),
26 btoa: data => new Buffer(data, "binary").toString("base64"), 26 btoa: data => new Buffer(data, "binary").toString("base64"),
27 Ci: { 27 Ci: {
28 }, 28 },
29 Cu: { 29 Cu: {
30 import: () => 30 import: () => {},
31 { 31 reportError: e => undefined
32 } 32 },
33 console: {
34 log: () => undefined,
kzar 2016/10/05 11:36:51 I think suppressing logging for all tests might be
Wladimir Palant 2016/10/05 12:12:51 Not really. An exception in a test should still be
kzar 2016/10/05 12:18:16 Yea, a switch to enable logging would be pretty us
35 error: () => undefined,
33 }, 36 },
34 navigator: { 37 navigator: {
35 }, 38 },
36 onShutdown: { 39 onShutdown: {
37 add: () => 40 add: () =>
38 { 41 {
39 } 42 }
40 }, 43 },
41 Services: { 44 Services: {
42 obs: { 45 obs: {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 83 }
81 84
82 return source.replace(/(\brequire\(["'])([^"']+)/g, (match, prefix, request) = > 85 return source.replace(/(\brequire\(["'])([^"']+)/g, (match, prefix, request) = >
83 { 86 {
84 if (request in knownModules) 87 if (request in knownModules)
85 return prefix + escapeString(knownModules[request]); 88 return prefix + escapeString(knownModules[request]);
86 return match; 89 return match;
87 }); 90 });
88 } 91 }
89 92
90 exports.createSandbox = function(extraExports) 93 exports.createSandbox = function(options)
91 { 94 {
95 if (!options)
96 options = {};
97
92 let sourceTransformers = [rewriteRequires]; 98 let sourceTransformers = [rewriteRequires];
93 if (extraExports) 99 if (options.extraExports)
94 sourceTransformers.push(addExports(extraExports)); 100 sourceTransformers.push(addExports(options.extraExports));
95 101
96 // This module loads itself into a sandbox, keeping track of the require 102 // This module loads itself into a sandbox, keeping track of the require
97 // function which can be used to load further modules into the sandbox. 103 // function which can be used to load further modules into the sandbox.
98 return SandboxedModule.require("./_common", { 104 return SandboxedModule.require("./_common", {
99 globals: globals, 105 globals: Object.assign({}, globals, options.globals),
kzar 2016/10/05 11:36:51 (Cool, never heard of Object.assign() before.)
100 sourceTransformers: sourceTransformers 106 sourceTransformers: sourceTransformers
101 }).require; 107 }).require;
102 }; 108 };
103 109
104 exports.require = require; 110 exports.require = require;
OLDNEW
« no previous file with comments | « no previous file | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld