Catch error caused by exporting an `undefined` suite, print helpful message when caught #261

Closed
hangtwenty opened this Issue Jan 21, 2013 · 1 comment

2 participants

@hangtwenty

On the website with the documentation for Vows - http://vowsjs.org - there is a sequence of examples that is illuminating, but can lead to problems when you're following its example in your own project (for the first time).

There are a two main ways to run your tests.

First, you can call run() on a suite, then execute with node. In a line:

vows.describe('foo').addBatch({}).run(); // test.js

Then you run it with node test.js.

Second, you can export your suite(s) and use vows to run it. The documentation demonstrates two variations on this:

exports.suite = vows.describe('bar').addBatch({});
vows.describe('baz').addBatch({}).export(module);

Then you can run it with vows.

But you encounter a pitfall if you are trying out the different ways and you accidentally mix them like so:

exports.suite = vows.describe('foo').addBatch({}).run();

When you try to run the test with vows, you get the following error message:

/home/m/.nvm/v0.8.16/lib/node_modules/vows/bin/vows:574
        obj[s]._filename = cwdname(f);
                             ^
TypeError: Cannot set property '_filename' of undefined

Speaking as someone new to Vows (and Node.js in general), this error is rather confusing until you look under the hood. Of course, the issue is actually simple: run() doesn't have a return value. That means exports.suite is being set to undefined, and then an exception gets thrown when importSuites (in bin/vows) tries to set a property on this object.

I can't imagine I'm the only one this has happened to, so perhaps this error could be caught by the bin/vows script, with an instructive suggestion that might illuminate the solution for a new user.

If you think this mistake seems too obvious, imagine it's your first time dealing with a snippet like this:

exports.suite = vows.describe('foo').addBatch({
    // More
    // than
    // a
    // screenful
    // of
    // code
    // ...
}).run();

It's a mistake that's easy to miss when you're first picking up Vows.

@hangtwenty hangtwenty added a commit to hangtwenty/vows that referenced this issue Jan 21, 2013
@hangtwenty hangtwenty Add instructive error message to `importSuites` that could help new u…
…sers.

Fixes issue #261.
e9fb10d
@samlecuyer

Closing, since there's a PR for this.

@samlecuyer samlecuyer closed this Nov 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment