Change failedTests to live on the testList.

Since tests themselves already keep track of their failure, and the test
list (i.e. the `TestList` class) tracks other concepts of grouped tests,
such as "all tests", "filtered tests", etc. (like a `TestList` class
would!) I believe it makes sense for it to also maintain a collection of
"failed tests"... (in list form, of course!)

This will allow the `Run.runTest` logic to move into `run.js` file without
needing to pass back a separate `failed` variable in the event of a
failure, since that is already being tracked through the  `notifyFailed`
facility.
This commit is contained in:
Jesse Rosenberger
2017-11-23 20:02:20 +02:00
parent 204270694c
commit 0ab298dd34

View File

@@ -291,6 +291,7 @@ class TestList {
tagsToSkip = (tagsToSkip || []);
testState = (testState || null); // optional
this.allTests = allTests;
this.failedTests = [];
this.skippedTags = tagsToSkip;
this.skipCounts = {};
this.testState = testState;
@@ -341,6 +342,8 @@ class TestList {
// Mark the file that this test lives in as having failures.
this.fileInfo[test.file].hasFailures = true;
this.failedTests.push(test);
// Mark that the specific test failed.
test.failed = true;
@@ -561,7 +564,6 @@ export function runTests(options) {
testList.startTime = new Date;
let totalRun = 0;
const failedTests = [];
const totalTries = (options.retries || 0) + 1;
@@ -658,7 +660,6 @@ export function runTests(options) {
Console.rawError(" => Test threw exception: " + failure.stack + "\n");
}
failedTests.push(test);
testList.notifyFailed(test, failure);
} else {
Console.error(
@@ -679,21 +680,22 @@ export function runTests(options) {
Console.error(testList.generateSkipReport());
if (testList.filteredTests.length === 0) {
const failureCount = testList.failedTests.length;
if (!totalRun) {
Console.error("No tests run.");
return 0;
} else if (failedTests.length === 0) {
} else if (!failureCount) {
let disclaimers = '';
if (testList.filteredTests.length < testList.allTests.length) {
if (totalRun < testList.allTests.length) {
disclaimers += " other";
}
Console.error("All" + disclaimers + " tests passed.");
return 0;
} else {
const failureCount = failedTests.length;
Console.error(failureCount + " failure" +
(failureCount > 1 ? "s" : "") + ":");
failedTests.forEach((test) => {
testList.failedTests.forEach((test) => {
Console.rawError(" - " + test.file + ": " + test.name + "\n");
});
return 1;