Last active
February 13, 2020 01:14
-
-
Save Lokua/bf574cf37cc13d78625b6fcd9303b700 to your computer and use it in GitHub Desktop.
Barebones testing and test-runner for node >= 13
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
{ | |
"scripts": { | |
"test": "node ./path-to/test-runner.mjs" | |
} | |
} |
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 { inspect } from 'util' | |
export default function test(name, fn) { | |
try { | |
fn() | |
} catch (error) { | |
console.error(name, inspect(error, false, null, true)) | |
} | |
} |
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 fs from 'fs' | |
import path from 'path' | |
walkSync(`${process.cwd()}/src`).forEach(filename => { | |
if (filename.endsWith('.spec.mjs')) { | |
import(filename) | |
} | |
}) | |
// https://gist.github.com/kethinov/6658166#gistcomment-1921157 | |
function walkSync(dir, fileList = []) { | |
fs.readdirSync(dir).forEach(file => { | |
if (fs.statSync(path.join(dir, file)).isDirectory()) { | |
fileList = walkSync(path.join(dir, file), fileList) | |
} else { | |
fileList.push(path.join(dir, file)) | |
} | |
}) | |
return fileList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment