Skip to content

Instantly share code, notes, and snippets.

@lorenzofox3
Created October 11, 2019 22:26
Show Gist options
  • Save lorenzofox3/f98b1d8586bd512605d676f58cba5e0a to your computer and use it in GitHub Desktop.
Save lorenzofox3/f98b1d8586bd512605d676f58cba5e0a to your computer and use it in GitHub Desktop.
test runner with `only` feature
import {report} from './tester.js';
report();
{
"name": "only",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node -r esm -r ./spec.js ./index.js",
"test:only": "ONLY=true npm t"
},
"author": "",
"license": "ISC",
"devDependencies": {
"esm": "^3.2.25",
"zora": "^3.0.3"
}
}
import {test} from './tester.js';
test('should not run', t=> {
t.fail('do not run');
});
test('should run #only', t=> {
t.ok(true, 'I ran');
});
test('should not run either', t=> {
t.fail('do not run');
});
import {createHarness} from 'zora';
const harness = createHarness();
export const test = (desc, fn) => {
if(process.env.ONLY && desc.includes('#only') === false){
return harness.skip(desc, fn);
}
return harness.test(desc, fn);
};
export const report = async () => {
try {
await harness.report();
} catch (e) {
console.error(e);
process.exit(1);
} finally {
process.exit(harness.pass ? 0 : 1);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment