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

Already on GitHub? Sign in to your account

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

hangtwenty opened this Issue Jan 21, 2013 · 1 comment


None yet
2 participants

hangtwenty 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({});

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:

        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
    // ...

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…

Fixes issue #261.

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