Skip to content

Commit c01735e

Browse files
committed
migrate WatchTestCases
1 parent 075fcc3 commit c01735e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

test/WatchTestCases.test.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
/* global beforeAll expect fit */
12
"use strict";
23

3-
require("should");
44
const path = require("path");
55
const fs = require("fs");
66
const vm = require("vm");
7-
const Test = require("mocha/lib/test");
87
const mkdirp = require("mkdirp");
98
const checkArrayExpectation = require("./checkArrayExpectation");
9+
const async = require("async");
1010

1111
const Stats = require("../lib/Stats");
1212
const webpack = require("../lib/webpack");
@@ -61,7 +61,7 @@ describe("WatchTestCases", () => {
6161
tests: fs.readdirSync(path.join(casesPath, cat)).filter((folder) => folder.indexOf("_") < 0).sort()
6262
};
6363
});
64-
before(() => {
64+
beforeAll(() => {
6565
let dest = path.join(__dirname, "js");
6666
if(!fs.existsSync(dest))
6767
fs.mkdirSync(dest);
@@ -90,7 +90,6 @@ describe("WatchTestCases", () => {
9090
});
9191
before(() => remove(tempDirectory));
9292
it("should compile", function(done) {
93-
this.timeout(45000);
9493
const outputDirectory = path.join(__dirname, "js", "watch", category.name, testName);
9594

9695
let options = {};
@@ -154,17 +153,15 @@ describe("WatchTestCases", () => {
154153
});
155154
if(checkArrayExpectation(path.join(testDirectory, run.name), jsonStats, "error", "Error", done)) return;
156155
if(checkArrayExpectation(path.join(testDirectory, run.name), jsonStats, "warning", "Warning", done)) return;
157-
let exportedTests = 0;
156+
let exportedTests = [];
158157

159158
function _it(title, fn) {
160-
const test = new Test(title, fn);
161-
run.suite.addTest(test);
162-
exportedTests++;
163-
return test;
159+
exportedTests.push(fit(title, fn, 45000));
164160
}
165161

166162
const globalContext = {
167-
console: console
163+
console: console,
164+
expect: expect
168165
};
169166

170167
function _require(currentDirectory, module) {
@@ -183,14 +180,14 @@ describe("WatchTestCases", () => {
183180
content = fs.readFileSync(p, "utf-8");
184181
}
185182
if(options.target === "web" || options.target === "webworker") {
186-
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, window) {" + content + "\n})", globalContext, p);
183+
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect, window) {" + content + "\n})", globalContext, p);
187184
} else {
188-
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})", p);
185+
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect) {" + content + "\n})", p);
189186
}
190187
const m = {
191188
exports: {}
192189
};
193-
fn.call(m.exports, _require.bind(null, path.dirname(p)), m, m.exports, path.dirname(p), p, _it, run.name, jsonStats, state, globalContext);
190+
fn.call(m.exports, _require.bind(null, path.dirname(p)), m, m.exports, path.dirname(p), p, _it, run.name, jsonStats, state, expect, globalContext);
194191
return module.exports;
195192
} else if(testConfig.modules && module in testConfig.modules) {
196193
return testConfig.modules[module];
@@ -206,7 +203,7 @@ describe("WatchTestCases", () => {
206203
if(testConfig.noTests) return process.nextTick(done);
207204
_require(outputDirectory, testConfig.bundlePath || "./bundle.js");
208205

209-
if(exportedTests < 1) return done(new Error("No tests exported by test case"));
206+
if(exportedTests.length < 1) return done(new Error("No tests exported by test case"));
210207
runIdx++;
211208
if(runIdx < runs.length) {
212209
run = runs[runIdx];
@@ -220,9 +217,13 @@ describe("WatchTestCases", () => {
220217
watching.close();
221218
process.nextTick(done);
222219
}
220+
async.waterfall(
221+
exportedTests.map(test => (callback) => test.execute(callback, true)),
222+
done
223+
);
223224
});
224225
}, 300);
225-
});
226+
}, 45000);
226227
});
227228
});
228229
});

0 commit comments

Comments
 (0)