diff --git a/test/HotTestCases.test.js b/test/HotTestCases.test.js index 32b5057ec7a..bb9e4d31ac6 100644 --- a/test/HotTestCases.test.js +++ b/test/HotTestCases.test.js @@ -109,7 +109,7 @@ describe("HotTestCases", () => { function _next(callback) { fakeUpdateLoaderOptions.updateIndex++; compiler.run((err, stats) => { - if (err) return done(err); + if (err) return callback(err); const jsonStats = stats.toJson({ errorDetails: true }); @@ -120,7 +120,7 @@ describe("HotTestCases", () => { "error", "errors" + fakeUpdateLoaderOptions.updateIndex, "Error", - done + callback ) ) { return; @@ -132,12 +132,12 @@ describe("HotTestCases", () => { "warning", "warnings" + fakeUpdateLoaderOptions.updateIndex, "Warning", - done + callback ) ) { return; } - if (callback) callback(jsonStats); + callback(null, jsonStats); }); } diff --git a/test/WatchTestCases.test.js b/test/WatchTestCases.test.js index b425f099a8a..95255c29872 100644 --- a/test/WatchTestCases.test.js +++ b/test/WatchTestCases.test.js @@ -7,6 +7,7 @@ const vm = require("vm"); const mkdirp = require("mkdirp"); const rimraf = require("rimraf"); const checkArrayExpectation = require("./checkArrayExpectation"); +const createLazyTestEnv = require("./helpers/createLazyTestEnv"); const { remove } = require("./helpers/remove"); const Stats = require("../lib/Stats"); @@ -140,6 +141,7 @@ describe("WatchTestCases", () => { let triggeringFilename; let lastHash = ""; const currentWatchStepModule = require("./helpers/currentWatchStep"); + let compilationFinished = done; currentWatchStepModule.step = run.name; copyDiff(path.join(testDirectory, run.name), tempDirectory, true); @@ -156,13 +158,15 @@ describe("WatchTestCases", () => { aggregateTimeout: 1000 }, (err, stats) => { - if (err) return done(err); + if (err) return compilationFinished(err); if (!stats) - return done(new Error("No stats reported from Compiler")); + return compilationFinished( + new Error("No stats reported from Compiler") + ); if (stats.hash === lastHash) return; lastHash = stats.hash; if (run.done && lastHash !== stats.hash) { - return done( + return compilationFinished( new Error( "Compilation changed but no change was issued " + lastHash + @@ -178,7 +182,7 @@ describe("WatchTestCases", () => { } if (waitMode) return; run.done = true; - if (err) return done(err); + if (err) return compilationFinished(err); const statOptions = Stats.presetToOptions("verbose"); statOptions.colors = false; mkdirp.sync(outputDirectory); @@ -196,7 +200,7 @@ describe("WatchTestCases", () => { jsonStats, "error", "Error", - done + compilationFinished ) ) return; @@ -206,17 +210,11 @@ describe("WatchTestCases", () => { jsonStats, "warning", "Warning", - done + compilationFinished ) ) return; - const exportedTests = []; - - function _it(title, fn) { - exportedTests.push({ title, fn, timeout: 45000 }); - } - const globalContext = { console: console, expect: expect @@ -271,7 +269,7 @@ describe("WatchTestCases", () => { m.exports, path.dirname(p), p, - _it, + run.it, run.name, jsonStats, state, @@ -298,22 +296,26 @@ describe("WatchTestCases", () => { // empty } - if (testConfig.noTests) return process.nextTick(done); + if (testConfig.noTests) + return process.nextTick(compilationFinished); _require( outputDirectory, testConfig.bundlePath || "./bundle.js" ); - if (exportedTests.length < 1) - return done(new Error("No tests exported by test case")); + if (run.getNumberOfTests() < 1) + return compilationFinished( + new Error("No tests exported by test case") + ); - const continueStep = () => { + run.it("should compile the next step", done => { runIdx++; if (runIdx < runs.length) { run = runs[runIdx]; waitMode = true; setTimeout(() => { waitMode = false; + compilationFinished = done; currentWatchStepModule.step = run.name; copyDiff( path.join(testDirectory, run.name), @@ -326,26 +328,9 @@ describe("WatchTestCases", () => { done(); } - }; - - // Run the tests - const asyncSuite = describe(`WatchTestCases ${ - category.name - } ${testName} step ${run.name}`, () => { - exportedTests.forEach( - ({ title, fn, timeout }) => - fn - ? fit(title, fn, timeout) - : fit(title, () => {}).pend("Skipped") - ); }); - // workaround for jest running clearSpies on the wrong suite (invoked by clearResourcesForRunnable) - asyncSuite.disabled = true; - jasmine - .getEnv() - .execute([asyncSuite.id], asyncSuite) - .then(continueStep, done); + compilationFinished(); } ); }, 300); @@ -353,6 +338,16 @@ describe("WatchTestCases", () => { 45000 ); + for (const run of runs) { + const { it: _it, getNumberOfTests } = createLazyTestEnv( + jasmine.getEnv(), + 10000, + run.name + ); + run.it = _it; + run.getNumberOfTests = getNumberOfTests; + } + afterAll(() => { remove(tempDirectory); }); diff --git a/test/helpers/createLazyTestEnv.js b/test/helpers/createLazyTestEnv.js index ad6134ff709..ad77365ba13 100644 --- a/test/helpers/createLazyTestEnv.js +++ b/test/helpers/createLazyTestEnv.js @@ -1,8 +1,11 @@ -module.exports = (env, globalTimeout = 2000) => { - const suite = env.describe("exported tests", () => { - // this must have a child to be handled correctly - env.it("should run the exported tests", () => {}); - }); +module.exports = (env, globalTimeout = 2000, nameSuffix = "") => { + const suite = env.describe( + nameSuffix ? `exported tests ${nameSuffix}` : "exported tests", + () => { + // this must have a child to be handled correctly + env.it("should run the exported tests", () => {}); + } + ); let numberOfTests = 0; const beforeAndAfterFns = () => { let currentSuite = suite; diff --git a/test/hotCases/update.js b/test/hotCases/update.js index e85933acc2b..d6993d2cc3f 100644 --- a/test/hotCases/update.js +++ b/test/hotCases/update.js @@ -1,7 +1,8 @@ module.exports = function(done, options, callback) { - return function(stats) { + return function(err, stats) { + if (err) return done(err); module.hot.check(options || true).then(() => { - if(callback) + if (callback) callback(stats); }).catch((err) => { done(err);