-
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
8 changed files
with
72 additions
and
161 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 |
---|---|---|
@@ -1,48 +1,5 @@ | ||
#!/usr/bin/env node | ||
import TestRunner from 'test-runner' | ||
import path from 'path' | ||
import Test from '../lib/test.js' | ||
import ansi from 'ansi-escape-sequences' | ||
import Cli from '../lib/cli.js' | ||
|
||
// process.on('uncaughtException', (err, origin) => { | ||
// console.error(`\nAn ${origin} was thrown, possibly in a separate tick.\n`) | ||
// console.error(err) | ||
// process.exit(1) | ||
// }) | ||
// process.on('unhandledRejection', (reason, promise) => { | ||
// console.error('\nAn unhandledRejection was thrown. Please ensure the rejecting promise is returned from the test function.\n') | ||
// console.error(reason) | ||
// process.exit(1) | ||
// }) | ||
|
||
const config = { | ||
files: process.argv.slice(2) | ||
} | ||
const tests = [] | ||
|
||
function createTests (arr, map, file) { | ||
for (const [name, testFn] of map) { | ||
const test = new Test(name, testFn) | ||
test.data.file = file | ||
tests.push(test) | ||
} | ||
} | ||
|
||
for (const file of config.files) { | ||
const testModule = await import(path.resolve(file)) | ||
if (testModule?.skip?.size) { | ||
for (const [name] of testModule.skip) { | ||
console.log(`- ${ansi.format(name, ['grey'])}`) | ||
} | ||
} | ||
if (testModule?.only?.size) { | ||
createTests(tests, testModule.only, file) | ||
} else if (testModule?.test?.size) { | ||
createTests(tests, testModule.test, file) | ||
} | ||
} | ||
|
||
const runner = new TestRunner(tests) | ||
for await (const test of runner.run()) { | ||
console.log(`${ansi.format('✔', ['green'])} ${ansi.format(test.data.file, ['magenta'])} ${test.name}`) | ||
} | ||
const cli = new Cli() | ||
await cli.start(process.argv.slice(2)) |
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,42 @@ | ||
import TestRunner from 'test-runner' | ||
import path from 'path' | ||
import Test from './test.js' | ||
import ansi from 'ansi-escape-sequences' | ||
|
||
class Cli { | ||
async start (argv) { | ||
const config = { | ||
files: argv | ||
} | ||
const tests = [] | ||
|
||
function createTests (arr, map, file) { | ||
for (const [name, testFn] of map) { | ||
const test = new Test(name, testFn) | ||
test.data.file = file | ||
tests.push(test) | ||
} | ||
} | ||
|
||
for (const file of config.files) { | ||
const testModule = await import(path.resolve(file)) | ||
if (testModule?.skip?.size) { | ||
for (const [name] of testModule.skip) { | ||
console.log(`- ${ansi.format(name, ['grey'])}`) | ||
} | ||
} | ||
if (testModule?.only?.size) { | ||
createTests(tests, testModule.only, file) | ||
} else if (testModule?.test?.size) { | ||
createTests(tests, testModule.test, file) | ||
} | ||
} | ||
|
||
const runner = new TestRunner(tests) | ||
for await (const test of runner.run()) { | ||
console.log(`${ansi.format('✔', ['green'])} ${ansi.format(test.data.file, ['magenta'])} ${test.name}`) | ||
} | ||
} | ||
} | ||
|
||
export default Cli |
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,15 @@ | ||
import TestRunner from 'test-runner' | ||
import Test from '../lib/test.js' | ||
import { strict as a } from 'assert' | ||
|
||
{ /* Sync tess passes, storing the result */ | ||
const actuals = [] | ||
const test1 = new Test('one', function one () { | ||
actuals.push('one') | ||
return 'one' | ||
}) | ||
const runner = new TestRunner([test1]) | ||
await runner.runAll() | ||
a.equal(test1.result, 'one') | ||
a.deepEqual(actuals, ['one']) | ||
} |