Skip to content

Commit b2c54f1

Browse files
committed
migrate away from forced tests to a beforeAll hook
1 parent 47a16eb commit b2c54f1

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

test/HotTestCases.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ describe("HotTestCases", () => {
2323
describe(category.name, () => {
2424
category.tests.forEach((testName) => {
2525
describe(testName, () => {
26-
it(testName + " should compile", (done) => {
26+
let exportedTests = [];
27+
beforeAll(() => new Promise((resolve, reject) => {
28+
const done = (err) => {
29+
if(err) return reject(err);
30+
resolve();
31+
};
2732
const testDirectory = path.join(casesPath, category.name, testName);
2833
const outputDirectory = path.join(__dirname, "js", "hot-cases", category.name, testName);
2934
const recordsPath = path.join(outputDirectory, "records.json");
@@ -66,10 +71,9 @@ describe("HotTestCases", () => {
6671
});
6772
if(checkArrayExpectation(testDirectory, jsonStats, "error", "Error", done)) return;
6873
if(checkArrayExpectation(testDirectory, jsonStats, "warning", "Warning", done)) return;
69-
let exportedTests = [];
7074

7175
function _it(title, fn) {
72-
exportedTests.push(fit(title, fn));
76+
exportedTests.push({ title, fn, timeout: 5000 });
7377
}
7478

7579
function _next(callback) {
@@ -98,12 +102,12 @@ describe("HotTestCases", () => {
98102
}
99103
_require("./bundle.js");
100104
if(exportedTests.length < 1) return done(new Error("No tests exported by test case"));
101-
async.waterfall(
102-
exportedTests.map(test => (callback) => test.execute(callback, true)),
103-
done
104-
);
105+
done();
105106
});
106-
});
107+
}));
108+
109+
it(testName + " should compile", () => {});
110+
exportedTests.forEach(({ title, fn, timeout }) => it(title, fn, timeout));
107111
});
108112
});
109113
});

test/WatchTestCases.test.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,19 @@ describe("WatchTestCases", () => {
7878
describe(category.name, () => {
7979
category.tests.forEach((testName) => {
8080
describe(testName, () => {
81-
const tempDirectory = path.join(__dirname, "js", "watch-src", category.name, testName);
81+
const tempDirectory = path.join(__dirname, "js", "watch-src", category.name, `${testName}-${Math.random().toPrecision(21).slice(2)}`);
8282
const testDirectory = path.join(casesPath, category.name, testName);
8383
const runs = fs.readdirSync(testDirectory).sort().filter((name) => {
8484
return fs.statSync(path.join(testDirectory, name)).isDirectory();
85-
}).map((name) => {
86-
return {
87-
name: name,
88-
suite: describe(name, () => {})
85+
}).map((name) => ({ name }));
86+
87+
let exportedTests = [];
88+
89+
beforeAll(() => new Promise((resolve, reject) => {
90+
const done = (err) => {
91+
if(err) return reject(err);
92+
resolve();
8993
};
90-
});
91-
beforeAll(() => {
92-
remove(tempDirectory);
93-
});
94-
it("should compile", function(done) {
9594
const outputDirectory = path.join(__dirname, "js", "watch", category.name, testName);
9695

9796
let options = {};
@@ -155,10 +154,9 @@ describe("WatchTestCases", () => {
155154
});
156155
if(checkArrayExpectation(path.join(testDirectory, run.name), jsonStats, "error", "Error", done)) return;
157156
if(checkArrayExpectation(path.join(testDirectory, run.name), jsonStats, "warning", "Warning", done)) return;
158-
let exportedTests = [];
159157

160158
function _it(title, fn) {
161-
exportedTests.push(fit(title, fn, 45000));
159+
exportedTests.push({ title, fn, timeout: 45000 });
162160
}
163161

164162
const globalContext = {
@@ -193,7 +191,7 @@ describe("WatchTestCases", () => {
193191
return module.exports;
194192
} else if(testConfig.modules && module in testConfig.modules) {
195193
return testConfig.modules[module];
196-
} else return require(module);
194+
} else return require.requireActual(module);
197195
}
198196

199197
let testConfig = {};
@@ -219,13 +217,16 @@ describe("WatchTestCases", () => {
219217
watching.close();
220218
process.nextTick(done);
221219
}
222-
async.waterfall(
223-
exportedTests.map(test => (callback) => test.execute(callback, true)),
224-
done
225-
);
226220
});
227221
}, 300);
228-
}, 45000);
222+
}), 45000);
223+
224+
it(testName + " should compile", () => {});
225+
exportedTests.forEach(({ title, fn, timeout }) => it(title, fn, timeout));
226+
227+
afterAll(() => {
228+
remove(tempDirectory);
229+
});
229230
});
230231
});
231232
});

0 commit comments

Comments
 (0)