Last active
August 31, 2017 09:22
-
-
Save blackcoat/3927320 to your computer and use it in GitHub Desktop.
Sample Mocha test runner in CoffeeScript
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
# Required to run commands in the shell | |
# @see http://nodejs.org/api/child_process.html | |
{spawn} = require 'child_process' | |
# A basic command runner | |
run = (cmd, args) -> | |
console.log cmd, args.join ' ' | |
spawn cmd, args, stdio: 'inherit' | |
# Set up default arguments for running our Mocha tests. | |
# The first argument passed to Mocha is the location of our | |
# test files. Meteor expects our specs to be located in the | |
# "tests" folder, which differs from Mocha's default test | |
# location (i.e. "test"). | |
# @see http://docs.meteor.com/#structuringyourapp | |
# @see http://stackoverflow.com/questions/11785917/where-should-unit-tests-be-placed-in-meteor | |
mocha_args = [ | |
'tests', | |
'--recursive', | |
'--compilers', 'coffee:coffee-script', | |
'--require', 'chai', | |
'--ui', 'bdd', | |
'--colors', | |
] | |
# Standard test runner with complete spec-style output | |
task 'test', 'runs the Mocha test suite', -> | |
run 'mocha', mocha_args.concat ['--reporter', 'spec']... | |
# Our watchful test runner to use during development and refactoring | |
task 'test:watch', 'runs the Mocha test suite whenever a file on the project is changed', -> | |
run 'mocha', mocha_args.concat [ | |
'--reporter', 'min', | |
'--watch' | |
]... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, how am I just seeing this!?!?
Yes, you are correct: NodeJS does not have any sense of the
window
object, causing issues when running tests against Meteor code that expectswindow
to exist. If you are usingwindow
to store values globally, you can useglobal
or evenprocess
within Node. If you need to emulatewindow
within Node, you could try jsdom or start up your Meteor app within a headless browser like Zombie.