-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
92 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
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
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,43 @@ | ||
import ansi from 'ansi-escape-sequences' | ||
|
||
/* TODO: Factor out node-specific code to enable isomorphism */ | ||
|
||
class TestRunner { | ||
tests | ||
|
||
constructor (tests) { | ||
this.tests = tests | ||
} | ||
|
||
async * run () { | ||
for (const test of this.tests) { | ||
console.log(`${ansi.format(test.metadata.file || '', ['magenta'])} ${test.name}`) | ||
try { | ||
await test.run() | ||
yield test | ||
} catch (err) { | ||
console.log(`${ansi.format(test.metadata.file || '', ['magenta'])} ${test.name} - ${ansi.format('Failed', ['red'])}`) | ||
/* Crash the process */ | ||
throw err | ||
} | ||
} | ||
} | ||
|
||
/* not used by start() */ | ||
async runAll () { | ||
const result = [] | ||
for await (const test of this.run()) { | ||
result.push(test) | ||
} | ||
return result | ||
} | ||
} | ||
|
||
export default TestRunner | ||
|
||
/* | ||
- test other people's projects | ||
- Interchangeable logger | ||
- interchangeable iterators, what else can be interchanged? | ||
- TestRunner has no concept of "skip", if you want to skip a test don't pass it in - same could apply to only. TestRunnerCli handles them. | ||
*/ |
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
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,23 @@ | ||
import TestRunner from 'test-runner' | ||
import { strict as a } from 'assert' | ||
|
||
/* Node.js version 12 compatible - no module-level await. */ | ||
|
||
/* Cli loads and runs a test file, test passes */ | ||
async function cliPass () { | ||
const runner = new TestRunner() | ||
runner.cli(['./test/fixture/one.js']) | ||
} | ||
|
||
/* Cli loads and runs a test file, test fails.. `.cli()` handles and sets exitCode. */ | ||
async function cliFail () { | ||
const runner = new TestRunner() | ||
await runner.cli(['./test/fixture/two.js']) | ||
a.equal(process.exitCode, 1) | ||
process.exitCode = 0 | ||
} | ||
|
||
Promise.all([ | ||
cliPass(), | ||
cliFail() | ||
]) |
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