Skip to content

Instantly share code, notes, and snippets.

@Lokua
Last active February 13, 2020 01:14
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 Lokua/bf574cf37cc13d78625b6fcd9303b700 to your computer and use it in GitHub Desktop.
Save Lokua/bf574cf37cc13d78625b6fcd9303b700 to your computer and use it in GitHub Desktop.
Barebones testing and test-runner for node >= 13
{
"scripts": {
"test": "node ./path-to/test-runner.mjs"
}
}
import { inspect } from 'util'
export default function test(name, fn) {
try {
fn()
} catch (error) {
console.error(name, inspect(error, false, null, true))
}
}
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