Last active
September 29, 2016 05:19
-
-
Save mtavkhelidze/29fec2b2e7ab01098438f399ea1e6c53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* mocha_runner.js — Simple Mocha Runner for ES6 | |
* | |
* Test your ES6 code with Mocha | |
* | |
* In package.json: "test": "babel-node run_mocha.js" | |
* | |
* Written by Misha Tavkhelidze <[email protected]> | |
* | |
* Copyright (c) 2016 Misha Tavkhelidze | |
*/ | |
// This can be put in a separate config file and then imported. | |
const conf = { | |
test: { | |
dirs: [ | |
'test', | |
'src' | |
], | |
extensions: [ | |
'.js' | |
], | |
// remove or leave empty to match all | |
pattern: '.spec' | |
} | |
}; | |
'use strict'; | |
import d_tree from 'directory-tree'; | |
import _ from 'lodash'; | |
import path from 'path'; | |
import Mocha from 'mocha'; | |
const find_files = item => { | |
if(_.isObject(item)) { | |
if(_.isArray(item.children)) | |
return item.children.reduce((a, b) => a.concat(find_files(b)), []); | |
if(item.path.includes(const.test.pattern)) | |
return [item]; | |
} | |
return []; | |
}; | |
const file_list = (root, dirs) => { | |
return dirs.map(dir => path.join(root, dir)) | |
.reduce((a, b) => a.concat(find_files( | |
d_tree(b, conf.test.extensions) | |
)), []) | |
.map(file => file.path); | |
}; | |
// this is the path npm is run from | |
const root = path.resolve('.'); | |
const files = file_list(root, conf.test.dirs); | |
const mocha = new Mocha(); | |
files.map(f => mocha.addFile(f)); | |
mocha.run(() => {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment