Note that there are some explanatory texts on larger screens.

plurals
  1. POExporting the same object that is required confuses mocha
    primarykey
    data
    text
    <p>I'm working on a node app that uses mocha to run unit tests. </p> <p>When I run this command:</p> <pre><code>mocha --compilers coffee:coffee-script --reporter spec ./test/unit/*-test.coffee </code></pre> <p>I get this error:</p> <pre><code>ERROR: Unknown option --compilers </code></pre> <p>It seems mocha is confused, because it definitely has a compilers option. This error started happening when I added a new file to the project. It's the only output I can get mocha to generate. --debug does nothing.</p> <p>Let's say I have a package called person installed. I want to configure this package globally so that I can import the configured object anywhere in my project. To do that, I import person, configure it as a driver, and then export it again.</p> <p>However, when I import it (either in Car.coffee or Car-test.coffee), mocha fails with the above error. </p> <p>Driver.coffee</p> <pre><code>driver = require 'person' driver.setSkill "Drive" module.exports = driver </code></pre> <p>Car.coffee</p> <pre><code>driver = require './driver' ... </code></pre> <p>Car-test.coffee</p> <pre><code>driver = require '../../src/driver' ... </code></pre> <p>Note that this works fine if I'm just compiling with coffee and running the node project. There's no issue importing it there. But when I run with mocha, it fails if I import the file.</p> <p>I can't really pinpoint the error. It seems just like a bug in mocha, but maybe I'm doing something "bad" by exporting the same object that I import, and node is just more forgiving?</p> <p>I'm using the latest version of mocha (1.13.0). Thanks!</p> <p><strong>Edit:</strong></p> <p>This doesn't fix the error, and is not ideal syntax-wise:</p> <pre><code>person = require 'person' class driver constructor: -&gt; person.setSkill "Drive" @person = person module.exports = driver </code></pre> <p>Note that simply wrapping it in a plain object doesn't work.</p> <p><strong>Edit 2:</strong></p> <p>Here's something else that doesn't work:</p> <p>configure-driver.coffee</p> <pre><code>configureDriver = (person) -&gt; person.setSkill "Drive" module.exports = configureDriver </code></pre> <p>car.coffee</p> <pre><code>driver = require('./configure-driver')(require 'person') </code></pre> <p>Mocha throws the same error as before.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload