Skip to content

Instantly share code, notes, and snippets.

@blackcoat
Last active August 31, 2017 09:22
Show Gist options
  • Save blackcoat/3927320 to your computer and use it in GitHub Desktop.
Save blackcoat/3927320 to your computer and use it in GitHub Desktop.
Sample Mocha test runner in CoffeeScript
# 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'
]...
@blackcoat
Copy link
Author

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 expects window to exist. If you are using window to store values globally, you can use global or even process within Node. If you need to emulate window within Node, you could try jsdom or start up your Meteor app within a headless browser like Zombie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment