Skip to content


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

hangtwenty opened this Issue · 1 comment

2 participants


On the website with the documentation for Vows - - 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 referenced this issue from a commit in hangtwenty/vows
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.