Skip to content

Instantly share code, notes, and snippets.

@mrbalihai
Last active November 22, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbalihai/da5c4c09e8df5095cb3f9e4ded9326e7 to your computer and use it in GitHub Desktop.
Save mrbalihai/da5c4c09e8df5095cb3f9e4ded9326e7 to your computer and use it in GitHub Desktop.
Poor man's NodeJS test runner
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);
});
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();
node test-runner.js *-test.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment