Created
October 11, 2019 22:26
-
-
Save lorenzofox3/f98b1d8586bd512605d676f58cba5e0a to your computer and use it in GitHub Desktop.
test runner with `only` feature
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 {report} from './tester.js'; | |
report(); |
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
{ | |
"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" | |
} | |
} |
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 {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'); | |
}); |
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 {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