-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to run some automated tests
Needs more tests! but this is a very good start
- Loading branch information
1 parent
68ce0d5
commit b93d3fd
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,3 @@ typings/ | |
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Project-specific | ||
*test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
docs/ | ||
*mkdocs.yml | ||
*test.js | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,8 @@ | |
"name": "Timo Rüppell", | ||
"email": "timo.ruppell@mapita.fi" | ||
} | ||
] | ||
], | ||
"scripts": { | ||
"test": "node test.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const canary = require("./canary"); | ||
const assert = require("assert"); | ||
|
||
// Extremely basic test runner to test the test runner | ||
const allTests = []; | ||
function addTest(test){ | ||
allTests.push(test); | ||
} | ||
async function runTests(){ | ||
console.log(`Running ${allTests.length} tests...`); | ||
for(let test of allTests){ | ||
try{ | ||
canary.removeAllTests(); | ||
canary.reset(); | ||
canary.silent(); | ||
await test(); | ||
}catch(error){ | ||
console.log("Error while running test:"); | ||
console.log(error); | ||
process.exit(1); | ||
} | ||
} | ||
console.log("All tests ran successfully!"); | ||
process.exit(0); | ||
} | ||
|
||
addTest( | ||
async function simpleSynchronousTests(){ | ||
// Set up the test | ||
const simplePassingTest = canary.test("Example passing test", function(){ | ||
// do nothing | ||
}); | ||
const simpleSkippedTest = canary.test("Example skipped test", function(){ | ||
this.ignore(); | ||
}); | ||
const simpleFailingTest = canary.test("Example failing test", function(){ | ||
throw new Error("Simple test failure"); | ||
}); | ||
// Run canary | ||
await canary.run(); | ||
// Verify correct results | ||
assert(simplePassingTest.success); | ||
assert(simpleSkippedTest.skipped); | ||
assert(simpleFailingTest.aborted); | ||
assert(simpleFailingTest.getErrors().length === 1); | ||
assert(simpleFailingTest.getErrors()[0] instanceof canary.Error); | ||
assert(simpleFailingTest.getErrors()[0].message === "Simple test failure"); | ||
} | ||
); | ||
|
||
addTest( | ||
async function simpleAsynchronousTests(){ | ||
// Set up the test | ||
const simplePassingTest = canary.test("Example passing test", async function(){ | ||
// do nothing | ||
}); | ||
const simpleSkippedTest = canary.test("Example skipped test", async function(){ | ||
this.ignore(); | ||
}); | ||
const simpleFailingTest = canary.test("Example failing test", async function(){ | ||
throw new Error("Simple test failure"); | ||
}); | ||
// Run canary | ||
await canary.run(); | ||
// Verify correct results | ||
assert(simplePassingTest.success); | ||
assert(simpleSkippedTest.skipped); | ||
assert(simpleFailingTest.aborted); | ||
assert(simpleFailingTest.getErrors().length === 1); | ||
assert(simpleFailingTest.getErrors()[0] instanceof canary.Error); | ||
assert(simpleFailingTest.getErrors()[0].message === "Simple test failure"); | ||
} | ||
); | ||
|
||
runTests(); |