|
1 | | -var should = require("should"); |
2 | | -var path = require("path"); |
3 | | -var fs = require("fs"); |
4 | | -var vm = require("vm"); |
5 | | -var Test = require("mocha/lib/test"); |
6 | | -var checkArrayExpectation = require("./checkArrayExpectation"); |
| 1 | +"use strict"; |
7 | 2 |
|
8 | | -var Stats = require("../lib/Stats"); |
9 | | -var webpack = require("../lib/webpack"); |
| 3 | +const should = require("should"); |
| 4 | +const path = require("path"); |
| 5 | +const fs = require("fs"); |
| 6 | +const vm = require("vm"); |
| 7 | +const Test = require("mocha/lib/test"); |
| 8 | +const checkArrayExpectation = require("./checkArrayExpectation"); |
10 | 9 |
|
11 | | -describe("TestCases", function() { |
12 | | - var casesPath = path.join(__dirname, "cases"); |
13 | | - var categories = fs.readdirSync(casesPath); |
14 | | - categories = categories.map(function(cat) { |
| 10 | +const Stats = require("../lib/Stats"); |
| 11 | +const webpack = require("../lib/webpack"); |
| 12 | + |
| 13 | +describe("TestCases", () => { |
| 14 | + const casesPath = path.join(__dirname, "cases"); |
| 15 | + let categories = fs.readdirSync(casesPath); |
| 16 | + categories = categories.map((cat) => { |
15 | 17 | return { |
16 | 18 | name: cat, |
17 | | - tests: fs.readdirSync(path.join(casesPath, cat)).filter(function(folder) { |
18 | | - return folder.indexOf("_") < 0; |
19 | | - }) |
| 19 | + tests: fs.readdirSync(path.join(casesPath, cat)).filter((folder) => folder.indexOf("_") < 0) |
20 | 20 | }; |
21 | 21 | }); |
22 | 22 | [{ |
@@ -94,27 +94,25 @@ describe("TestCases", function() { |
94 | 94 | new webpack.optimize.UglifyJsPlugin(), |
95 | 95 | new webpack.NamedModulesPlugin() |
96 | 96 | ] |
97 | | - }].forEach(function(config) { |
98 | | - describe(config.name, function() { |
99 | | - categories.forEach(function(category) { |
| 97 | + }].forEach((config) => { |
| 98 | + describe(config.name, () => { |
| 99 | + categories.forEach((category) => { |
100 | 100 | describe(category.name, function() { |
101 | 101 | this.timeout(30000); |
102 | | - category.tests.filter(function(test) { |
103 | | - var testDirectory = path.join(casesPath, category.name, test); |
104 | | - var filterPath = path.join(testDirectory, "test.filter.js"); |
| 102 | + category.tests.filter((test) => { |
| 103 | + const testDirectory = path.join(casesPath, category.name, test); |
| 104 | + const filterPath = path.join(testDirectory, "test.filter.js"); |
105 | 105 | if(fs.existsSync(filterPath) && !require(filterPath)(config)) { |
106 | | - describe.skip(test, function() { |
107 | | - it('filtered'); |
108 | | - }); |
| 106 | + describe.skip(test, () => it("filtered")); |
109 | 107 | return false; |
110 | 108 | } |
111 | 109 | return true; |
112 | | - }).forEach(function(testName) { |
113 | | - var suite = describe(testName, function() {}); |
114 | | - it(testName + " should compile", function(done) { |
115 | | - var testDirectory = path.join(casesPath, category.name, testName); |
116 | | - var outputDirectory = path.join(__dirname, "js", config.name, category.name, testName); |
117 | | - var options = { |
| 110 | + }).forEach((testName) => { |
| 111 | + const suite = describe(testName, () => {}); |
| 112 | + it(testName + " should compile", (done) => { |
| 113 | + const testDirectory = path.join(casesPath, category.name, testName); |
| 114 | + const outputDirectory = path.join(__dirname, "js", config.name, category.name, testName); |
| 115 | + const options = { |
118 | 116 | context: casesPath, |
119 | 117 | entry: "./" + category.name + "/" + testName + "/index", |
120 | 118 | target: "async-node", |
@@ -145,43 +143,41 @@ describe("TestCases", function() { |
145 | 143 | }] |
146 | 144 | }, |
147 | 145 | plugins: (config.plugins || []).concat(function() { |
148 | | - this.plugin("compilation", function(compilation) { |
149 | | - ["optimize", "optimize-modules-basic", "optimize-chunks-basic", "after-optimize-tree", "after-optimize-assets"].forEach(function(hook) { |
150 | | - compilation.plugin(hook, function() { |
151 | | - compilation.checkConstraints(); |
152 | | - }); |
| 146 | + this.plugin("compilation", (compilation) => { |
| 147 | + ["optimize", "optimize-modules-basic", "optimize-chunks-basic", "after-optimize-tree", "after-optimize-assets"].forEach((hook) => { |
| 148 | + compilation.plugin(hook, () => compilation.checkConstraints()); |
153 | 149 | }); |
154 | 150 | }); |
155 | 151 | }) |
156 | 152 | }; |
157 | | - webpack(options, function(err, stats) { |
| 153 | + webpack(options, (err, stats) => { |
158 | 154 | if(err) return done(err); |
159 | | - var statOptions = Stats.presetToOptions("verbose"); |
| 155 | + const statOptions = Stats.presetToOptions("verbose"); |
160 | 156 | statOptions.colors = false; |
161 | 157 | fs.writeFileSync(path.join(outputDirectory, "stats.txt"), stats.toString(statOptions), "utf-8"); |
162 | | - var jsonStats = stats.toJson({ |
| 158 | + const jsonStats = stats.toJson({ |
163 | 159 | errorDetails: true |
164 | 160 | }); |
165 | 161 | if(checkArrayExpectation(testDirectory, jsonStats, "error", "Error", done)) return; |
166 | 162 | if(checkArrayExpectation(testDirectory, jsonStats, "warning", "Warning", done)) return; |
167 | | - var exportedTest = 0; |
| 163 | + let exportedTest = 0; |
168 | 164 |
|
169 | 165 | function _it(title, fn) { |
170 | | - var test = new Test(title, fn); |
| 166 | + const test = new Test(title, fn); |
171 | 167 | suite.addTest(test); |
172 | 168 | exportedTest++; |
173 | 169 | return test; |
174 | 170 | } |
175 | 171 |
|
176 | 172 | function _require(module) { |
177 | 173 | if(module.substr(0, 2) === "./") { |
178 | | - var p = path.join(outputDirectory, module); |
179 | | - var fn = vm.runInThisContext("(function(require, module, exports, __dirname, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p); |
180 | | - var module = { |
| 174 | + const p = path.join(outputDirectory, module); |
| 175 | + const fn = vm.runInThisContext("(function(require, module, exports, __dirname, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p); |
| 176 | + const m = { |
181 | 177 | exports: {} |
182 | 178 | }; |
183 | | - fn.call(module.exports, _require, module, module.exports, outputDirectory, _it); |
184 | | - return module.exports; |
| 179 | + fn.call(m.exports, _require, m, m.exports, outputDirectory, _it); |
| 180 | + return m.exports; |
185 | 181 | } else return require(module); |
186 | 182 | } |
187 | 183 | _require("./bundle.js"); |
|
0 commit comments