Last active
November 22, 2020 20:32
-
-
Save mrbalihai/da5c4c09e8df5095cb3f9e4ded9326e7 to your computer and use it in GitHub Desktop.
Poor man's NodeJS test runner
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
import * as assert from 'assert'; | |
test('1 should equal 1', () => { | |
assert.equal(1, 1); | |
}); | |
test('async 1 should equal 1', async () => { | |
await new Promise(r => setTimeout(r, 1000)); | |
assert.equal(1, 1); | |
}); |
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
import { join } from 'path'; | |
const tests = []; | |
const test = (name, fn) => | |
tests.push({ name, fn }); | |
const run = async () => { | |
const files = process.argv.slice(2); | |
await Promise.all(files.map(async (f) => await import(join(process.cwd(), f)))); | |
tests.forEach(async t => { | |
try { | |
await t.fn(); | |
console.log('PASSED', t.name); | |
} catch (e) { | |
console.error('FAILED', t.name); | |
console.error(e.stack); | |
} | |
}); | |
} | |
global.test = test; | |
global.it = test; | |
run(); |
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
node test-runner.js *-test.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment