Skip to content

Commit

Permalink
Add more automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplemachine committed Mar 28, 2018
1 parent e3fabef commit b93e8a6
Showing 1 changed file with 117 additions and 1 deletion.
118 changes: 117 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ async function runTests(){
console.log(`Running ${allTests.length} tests...`);
for(let test of allTests){
try{
console.log(`Running test "${test.name}"...`);
canary.removeAllTests();
canary.reset();
canary.silent();
await test();
}catch(error){
console.log("Error while running test:");
console.log(`Error while running test "${test.name}":`);
console.log(error);
process.exit(1);
}
Expand Down Expand Up @@ -45,6 +46,7 @@ addTest(
assert(simpleFailingTest.getErrors().length === 1);
assert(simpleFailingTest.getErrors()[0] instanceof canary.Error);
assert(simpleFailingTest.getErrors()[0].message === "Simple test failure");
assert(canary.getStatusString() === "failed");
}
);

Expand All @@ -69,6 +71,120 @@ addTest(
assert(simpleFailingTest.getErrors().length === 1);
assert(simpleFailingTest.getErrors()[0] instanceof canary.Error);
assert(simpleFailingTest.getErrors()[0].message === "Simple test failure");
assert(canary.getStatusString() === "failed");
}
);

addTest(
async function allPassingTests(){
// Set up the test
const syncPassingTest = canary.test("Synchronous passing test", function(){
// do nothing
});
const asyncPassingTest = canary.test("Asynchronous passing test", async function(){
// do nothing
});
let nestedSyncPassingTest;
let nestedAsyncPassingTest;
const passingTestGroup = canary.group("Example test group", function(){
nestedSyncPassingTest = canary.test("Nested synchronous passing test", function(){
// do nothing
});
nestedAsyncPassingTest = canary.test("Nested asynchronous passing test", async function(){
// do nothing
});
});
// Run canary
await canary.run();
// Verify correct results
assert(syncPassingTest.success);
assert(asyncPassingTest.success);
assert(passingTestGroup.success);
assert(nestedSyncPassingTest.success);
assert(nestedAsyncPassingTest.success);
assert(canary.success);
}
);

addTest(
async function verifyTestsRunInOrder(){
// Set up the test
let counter = 0;
const firstTest = canary.test("First test (synchronous)", function(){
assert(counter === 0);
counter++;
});
const secondTest = canary.test("Second test (asynchronous)", async function(){
assert(counter === 1);
counter++;
});
const thirdTest = canary.test("Third test (synchronous)", function(){
assert(counter === 2);
counter++;
});
const fourthTest = canary.test("Fourth test (asynchronous)", async function(){
assert(counter === 3);
counter++;
});
// Run canary
await canary.run();
// Verify correct results
assert(firstTest.success);
assert(secondTest.success);
assert(thirdTest.success);
assert(fourthTest.success);
assert(canary.success);
assert(counter === 4);
}
);

addTest(
async function testGroupVsTestSeriesBehavior(){
// Set up the test
let counter = 0;
const testGroup = canary.group("Failing test group", function(){
this.test("First test (passing)", function(){
// do nothing
});
this.test("Second test (failing)", function(){
throw new Error("Example test failure");
});
this.test("Third test (should not be skipped)", function(){
throw new Error("Test should not be skipped");
});
});
const testSeries = canary.series("Failing test series", function(){
this.test("First test (passing)", function(){
// do nothing
});
this.test("Second test (failing)", function(){
throw new Error("Example test failure");
});
this.test("Third test (should be skipped)", function(){
throw new Error("Test should be skipped");
});
});
// Run canary
await canary.run();
// Verify correct results
// All tests in the test group ran
assert(testGroup.failed);
assert(!testGroup.aborted);
assert(testGroup.getChildren().length === 3);
assert(testGroup.getChildren()[0].success);
assert(testGroup.getChildren()[1].aborted);
assert(testGroup.getChildren()[2].aborted);
assert(testGroup.getFailedChildren().length === 2);
// Tests after the first failing test in a series were not attempted
assert(testSeries.aborted);
assert(testSeries.getChildren().length === 3);
assert(testSeries.getChildren()[0].success);
assert(testSeries.getChildren()[1].aborted);
assert(!testSeries.getChildren()[2].attempted);
assert(testSeries.getFailedChildren().length === 1);
// Root test group is marked as failed (but not as aborted)
assert(canary.failed);
assert(!canary.aborted);
}
);

Expand Down

0 comments on commit b93e8a6

Please sign in to comment.