Skip to content

Commit 3abb6e7

Browse files
committed
jest: more fixes for running tests well
1 parent 81d91d7 commit 3abb6e7

6 files changed

Lines changed: 28 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"fix": "npm run lint -- --fix",
108108
"pretty-files": "prettier \"lib/**.*\" \"bin/**.*\" \"hot/**.*\" \"buildin/**.*\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" --write",
109109
"schema-lint": "node --no-deprecation --max-old-space-size=4096 --harmony node_modules/.bin/jest --testMatch '<rootDir>/test/*.lint.js'",
110-
"benchmark": "node --no-deprecation --max-old-space-size=4096 --harmony node_modules/.bin/jest --testMatch '<roorDir>/test/*.benchmark.js'",
110+
"benchmark": "node --no-deprecation --max-old-space-size=4096 --harmony node_modules/.bin/jest --testMatch '<rootDir>/test/*.benchmark.js'",
111111
"cover": "npm run cover:init && npm run cover:all && npm run cover:report",
112112
"cover:init": "rimraf coverage",
113113
"cover:all": "node --no-deprecation --max-old-space-size=4096 --harmony node_modules/.bin/jest --coverage",

test/ConfigTestCases.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ describe("ConfigTestCases", () => {
193193
} else {
194194
fn = vm.runInThisContext(
195195
"(function(require, module, exports, __dirname, __filename, it, expect) {" +
196+
"global.expect = expect;" +
196197
content +
197198
"\n})",
198199
p
@@ -244,8 +245,9 @@ describe("ConfigTestCases", () => {
244245
return done(new Error("No tests exported by test case"));
245246

246247
describe("exported tests", () => {
247-
exportedTests.forEach(({ title, fn, timeout }) =>
248-
it(title, fn, timeout)
248+
exportedTests.forEach(
249+
({ title, fn, timeout }) =>
250+
fn ? it(title, fn, timeout) : it.skip(title, () => {})
249251
);
250252
done();
251253
});

test/HotTestCases.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ describe("HotTestCases", () => {
135135
const p = path.join(outputDirectory, module);
136136
const fn = vm.runInThisContext(
137137
"(function(require, module, exports, __dirname, __filename, it, expect, NEXT, STATS) {" +
138+
"global.expect = expect;" +
138139
fs.readFileSync(p, "utf-8") +
139140
"\n})",
140141
p
@@ -162,8 +163,9 @@ describe("HotTestCases", () => {
162163
return done(new Error("No tests exported by test case"));
163164

164165
describe("exported tests", () => {
165-
exportedTests.forEach(({ title, fn, timeout }) =>
166-
it(title, fn, timeout)
166+
exportedTests.forEach(
167+
({ title, fn, timeout }) =>
168+
fn ? it(title, fn, timeout) : it.skip(title, () => {})
167169
);
168170
done();
169171
});

test/StatsTestCases.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe("StatsTestCases", () => {
2929
}
3030
};
3131
if (fs.existsSync(path.join(base, testName, "webpack.config.js"))) {
32-
options = require(path.join(base, testName, "webpack.config.js"));
32+
options = require(
33+
path.join(base, testName, "webpack.config.js")
34+
);
3335
}
3436
(Array.isArray(options) ? options : [options]).forEach(options => {
3537
if (!options.context) options.context = path.join(base, testName);
@@ -70,13 +72,11 @@ describe("StatsTestCases", () => {
7072
});
7173
c.run((err, stats) => {
7274
if (err) return done(err);
73-
7475
if (/error$/.test(testName)) {
7576
expect(stats.hasErrors()).toBe(true);
7677
} else if (stats.hasErrors()) {
7778
return done(new Error(stats.toJson().errors.join("\n\n")));
7879
}
79-
8080
let toStringOptions = {
8181
context: path.join(base, testName),
8282
colors: false
@@ -86,15 +86,13 @@ describe("StatsTestCases", () => {
8686
toStringOptions = options.stats;
8787
if (toStringOptions === null || typeof toStringOptions !== "object")
8888
toStringOptions = Stats.presetToOptions(toStringOptions);
89-
9089
hasColorSetting = typeof options.stats.colors !== "undefined";
9190
if (!toStringOptions.context)
9291
toStringOptions.context = path.join(base, testName);
9392
}
9493
if (Array.isArray(options) && !toStringOptions.children) {
9594
toStringOptions.children = options.map(o => o.stats);
9695
}
97-
9896
let actual = stats.toString(toStringOptions);
9997
expect(typeof actual).toBe("string");
10098
if (!hasColorSetting) {
@@ -117,7 +115,6 @@ describe("StatsTestCases", () => {
117115
"$1 Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT"
118116
);
119117
}
120-
121118
actual = actual
122119
.replace(/\r\n?/g, "\n")
123120
.replace(/[\t ]*Version:.+\n/g, "")

test/TestCases.template.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,14 @@ const describeCases = config => {
200200

201201
function _it(title, fn) {
202202
exportedTests.push({ title, fn, timeout: 5000 });
203-
// TODO: is this necessary in 'jest'?
204-
// WORKAROUND for a v8 bug
205-
// Error objects retrain all scopes in the stacktrace
206-
// test._trace = test._trace.message;
207203
}
208204

209205
function _require(module) {
210206
if (module.substr(0, 2) === "./") {
211207
const p = path.join(outputDirectory, module);
212208
const fn = vm.runInThisContext(
213209
"(function(require, module, exports, __dirname, it, expect) {" +
210+
"global.expect = expect;" +
214211
fs.readFileSync(p, "utf-8") +
215212
"\n})",
216213
p
@@ -237,14 +234,15 @@ const describeCases = config => {
237234
throw new Error("No tests exported by test case");
238235

239236
describe("exported tests", () => {
240-
exportedTests.forEach(({ title, fn, timeout }) =>
241-
it(title, fn, timeout)
237+
exportedTests.forEach(
238+
({ title, fn, timeout }) =>
239+
fn ? it(title, fn, timeout) : it.skip(title, () => {})
242240
);
243241
done();
244242
});
245243
});
246244
},
247-
30000
245+
40000
248246
);
249247
});
250248
});

test/WatchTestCases.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe("WatchTestCases", () => {
245245
} else {
246246
fn = vm.runInThisContext(
247247
"(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect) {" +
248+
"global.expect = expect;" +
248249
content +
249250
"\n})",
250251
p
@@ -296,13 +297,6 @@ describe("WatchTestCases", () => {
296297
if (exportedTests.length < 1)
297298
return done(new Error("No tests exported by test case"));
298299

299-
describe("exported tests", () => {
300-
exportedTests.forEach(({ title, fn, timeout }) =>
301-
it(title, fn, timeout)
302-
);
303-
done();
304-
});
305-
306300
runIdx++;
307301
if (runIdx < runs.length) {
308302
run = runs[runIdx];
@@ -317,6 +311,16 @@ describe("WatchTestCases", () => {
317311
}, 1500);
318312
} else {
319313
watching.close();
314+
315+
describe("exported tests", () => {
316+
exportedTests.forEach(
317+
({ title, fn, timeout }) =>
318+
fn
319+
? it(title, fn, timeout)
320+
: it.skip(title, () => {})
321+
);
322+
});
323+
320324
process.nextTick(done);
321325
}
322326
}

0 commit comments

Comments
 (0)