Last active
July 21, 2017 09:42
-
-
Save mrodalgaard/8961e8760e6c408350f9 to your computer and use it in GitHub Desktop.
Atom custom test runner with Mocha and Coverage
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
fs = require 'fs' | |
path = require 'path' | |
Mocha = require 'mocha' | |
coffeeCoverage = require 'coffee-coverage' | |
{allowUnsafeEval, allowUnsafeNewFunction} = require 'loophole' | |
module.exports = (args) -> | |
# Fixes CSP eval restriction | |
allowUnsafeEval -> | |
# TODO: Just use first test path for now | |
testPath = args.testPaths[0] | |
mocha = new Mocha( | |
ui: 'bdd' | |
reporter: 'html' | |
) | |
coffeeCoverage.register( | |
instrumentor: 'istanbul' | |
basePath: path.join(testPath, '..') | |
# basePath: path.join(testPath) | |
exclude: ['/spec', '/node_modules', '/.git'] | |
coverageVar: coffeeCoverage.findIstanbulVariable() | |
writeOnExit: path.join(testPath, '..', 'coverage/coverage-coffee.json') | |
initAll: true | |
) | |
applicationDelegate = args.buildDefaultApplicationDelegate() | |
# Force spec window to start in development mode (Fixed in Atom 1.3.0-beta6) | |
win = applicationDelegate.getCurrentWindow() | |
if win.getUrl().indexOf('devMode%22%3Atrue') is -1 | |
console.log 'Spec window not in devMode, redirecting...' | |
return win.loadUrl win.getUrl().replace('devMode%22%3Afalse', 'devMode%22%3Atrue') | |
# Create element for mocha reporter | |
element = document.createElement 'div' | |
element.id = 'mocha' | |
document.body.appendChild element | |
# Build atom global | |
window.atom = args.buildAtomEnvironment({ | |
applicationDelegate, window, document | |
configDirPath: process.env.ATOM_HOME | |
enablePersistence: false | |
}) | |
for file in fs.readdirSync(testPath) | |
if file.substr(-7) is '.coffee' | |
mocha.addFile path.join(testPath, file) | |
# Run tests and return a promise | |
new Promise((resolve, reject) -> | |
mocha.run((failures) -> | |
resolve(failures) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment