Snippets are tiny notes I've collected for easy reference.
Fixing "Unexpected string" errors with CoffeeScript 1.7 and Mocha 1.17
Recently I've been running into the following error when testing CoffeeScript files using Mocha:
(exports, require, module, __filename, __dirname) { should = require 'should'
^^^^^^^^
SyntaxError: Unexpected string
The fix is described here on the mocha site.
coffee-script is no longer supported out of the box. CS and similar transpilers may be used by mapping the file extensions (for use with --watch) and the module name. For example --compilers coffee:coffee-script with CoffeeScript 1.6- or --compilers coffee:coffee-script/register with CoffeeScript 1.7+.
In other words, to fix the problem change the argument:
--compilers coffee:coffee-script
on your Mocha command line to:
--compilers coffee:coffee-script/register
Published 11 Feb 2014
Snippets are tiny notes I've collected for easy reference.