Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
floer32 opened this issue Jan 21, 2013 · 1 comment

Comments

@floer32
Copy link

floer32 commented Jan 21, 2013

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.

@samlecuyer
Copy link

Closing, since there's a PR for this.

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

No branches or pull requests

2 participants