Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 addTestPaths(fs.readdirSync(testPath).map( | 43 addTestPaths(fs.readdirSync(testPath).map( |
44 file => path.join(testPath, file))); | 44 file => path.join(testPath, file))); |
45 } | 45 } |
46 continue; | 46 continue; |
47 } | 47 } |
48 if (path.basename(testPath).startsWith("_")) | 48 if (path.basename(testPath).startsWith("_")) |
49 continue; | 49 continue; |
50 if (path.extname(testPath) == ".js") | 50 if (path.extname(testPath) == ".js") |
51 { | 51 { |
52 if (testPath.split(path.sep).includes("browser")) | 52 if (testPath.split(path.sep).includes("browser")) |
53 { | 53 browserFiles.push(testPath); |
54 browserFiles.push( | |
55 path.relative(path.join(__dirname, "test", "browser"), | |
56 testPath).replace(/\.js$/, "") | |
57 ); | |
58 } | |
59 else | 54 else |
60 unitFiles.push(testPath); | 55 unitFiles.push(testPath); |
61 } | 56 } |
62 } | 57 } |
63 } | 58 } |
64 | 59 |
65 function webpackInMemory(bundleFilename, options) | 60 function webpackInMemory(bundleFilename, options) |
66 { | 61 { |
67 return new Promise((resolve, reject) => | 62 return new Promise((resolve, reject) => |
68 { | 63 { |
69 // Based on this example https://webpack.js.org/api/node/#custom-file-system s | 64 // Based on this example |
65 // https://webpack.js.org/api/node/#custom-file-systems | |
70 let memoryFS = new MemoryFS(); | 66 let memoryFS = new MemoryFS(); |
71 | 67 |
72 options.output = {filename: bundleFilename, path: "/"}; | 68 options.output = {filename: bundleFilename, path: "/"}; |
73 let webpackCompiler = webpack(options); | 69 let webpackCompiler = webpack(options); |
74 webpackCompiler.outputFileSystem = memoryFS; | 70 webpackCompiler.outputFileSystem = memoryFS; |
75 | 71 |
76 webpackCompiler.run((err, stats) => | 72 webpackCompiler.run((err, stats) => |
77 { | 73 { |
78 // Error handling is based on this example | 74 // Error handling is based on this example |
79 // https://webpack.js.org/api/node/#error-handling | 75 // https://webpack.js.org/api/node/#error-handling |
(...skipping 12 matching lines...) Expand all Loading... | |
92 memoryFS.unlinkSync("/" + bundleFilename); | 88 memoryFS.unlinkSync("/" + bundleFilename); |
93 resolve(bundle); | 89 resolve(bundle); |
94 } | 90 } |
95 }); | 91 }); |
96 }); | 92 }); |
97 } | 93 } |
98 | 94 |
99 function runBrowserTests() | 95 function runBrowserTests() |
100 { | 96 { |
101 if (!browserFiles.length) | 97 if (!browserFiles.length) |
102 return Promise.resolve(); | 98 return; |
Wladimir Palant
2017/08/17 13:06:11
Or maybe just change the call below from runBrowse
kzar
2017/08/17 13:26:43
Done.
| |
103 | 99 |
104 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit", | 100 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit", |
105 "examples", "browser", "nodeunit.js"); | 101 "examples", "browser", "nodeunit.js"); |
106 let bundleFilename = "bundle.js"; | 102 let bundleFilename = "bundle.js"; |
107 | 103 |
108 return webpackInMemory(bundleFilename, { | 104 return webpackInMemory(bundleFilename, { |
109 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"), | 105 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"), |
110 module: { | 106 module: { |
111 rules: [{ | 107 rules: [{ |
112 resource: nodeunitPath, | 108 resource: nodeunitPath, |
113 // I would have rathered used exports-loader here, to avoid treating | 109 // I would have rather used exports-loader here, to avoid treating |
114 // nodeunit as a global. Unfortunately the nodeunit browser example | 110 // nodeunit as a global. Unfortunately the nodeunit browser example |
115 // script is quite slopily put together, if exports isn't falsey it | 111 // script is quite slopily put together, if exports isn't falsey it |
116 // breaks! As a workaround we need to use script-loader, which means | 112 // breaks! As a workaround we need to use script-loader, which means |
117 // that exports is falsey for that script as a side-effect. | 113 // that exports is falsey for that script as a side-effect. |
118 use: ["script-loader"] | 114 use: ["script-loader"] |
119 }] | 115 }] |
120 }, | 116 }, |
121 resolve: { | 117 resolve: { |
122 alias: { | 118 alias: { |
123 nodeunit$: nodeunitPath | 119 nodeunit$: nodeunitPath |
124 }, | 120 }, |
125 modules: [path.resolve(__dirname, "lib")] | 121 modules: [path.resolve(__dirname, "lib")] |
126 } | 122 } |
127 }).then(bundle => | 123 }).then(bundle => |
128 { | 124 { |
129 return chromiumProcess(bundle, bundleFilename, browserFiles); | 125 return chromiumProcess( |
126 bundle, bundleFilename, | |
127 browserFiles.map( | |
128 file => path.relative(path.join(__dirname, "test", "browser"), | |
129 file).replace(/\.js$/, "") | |
130 ) | |
131 ); | |
130 }); | 132 }); |
131 } | 133 } |
132 | 134 |
133 if (process.argv.length > 2) | 135 if (process.argv.length > 2) |
134 addTestPaths(process.argv.slice(2), true); | 136 addTestPaths(process.argv.slice(2), true); |
135 else | 137 else |
136 { | 138 { |
137 addTestPaths( | 139 addTestPaths( |
138 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], | 140 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], |
139 true | 141 true |
140 ); | 142 ); |
141 } | 143 } |
142 | 144 |
143 runBrowserTests().catch(error => | 145 Promise.resolve(runBrowserTests()).catch(error => |
144 { | 146 { |
145 console.error("Failed running browser tests"); | 147 console.error("Failed running browser tests"); |
146 console.error(error); | 148 console.error(error); |
147 }).then(() => | 149 }).then(() => |
148 { | 150 { |
149 if (unitFiles.length) | 151 if (unitFiles.length) |
150 nodeunit.reporters.default.run(unitFiles); | 152 nodeunit.reporters.default.run(unitFiles); |
151 }); | 153 }); |
LEFT | RIGHT |