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

Add filename to Mocha.Test objects #950

Closed
lambdabaa opened this issue Aug 14, 2013 · 14 comments · Fixed by #1174
Closed

Add filename to Mocha.Test objects #950

lambdabaa opened this issue Aug 14, 2013 · 14 comments · Fixed by #1174

Comments

@lambdabaa
Copy link

I would like for the mocha runner to send my custom reporter the names of the containing files along with tests. How would people feel about a patch that made test objects aware of the file in which they are declared?

@lightsofapollo
Copy link
Contributor

In both node and the browser we can do this by throwing then catching an error:

try {
 throw new Error();
} catch(e) {
  e;
}

@tomruggs
Copy link

👍

@spollack
Copy link

spollack commented Oct 3, 2013

I think it would be great to have the filename in the test object.

@jroper
Copy link

jroper commented Feb 27, 2014

Filename in test object would be quite useful - imagine a large project with thousands of tests, how do you know, from looking at the name of the test suite, which file contains the one that failed? It may not always be intuitive especially when projects get large with many people working on them. If the test is asynchronous, the stack trace might not contain the test filename.

It would also be very useful for tooling, for example some tools, when a test fails, lets you click on the failed test to take you to that test. Without a test name, it can't implement this.

@jroper
Copy link

jroper commented Feb 27, 2014

Btw, this works around the issue, if you're programatically using mocha:

mocha.suite.on("post-require", function(ctx, file) {
    // Add the filename to any first level suites that don't have a filename defined
    mocha.suite.suites.forEach(function(suite) {
       if (suite.filename === undefined) {
           suite.filename = file;
       }
    });
});

@tj
Copy link
Contributor

tj commented Mar 3, 2014

@jroper :( write little modules and build apps with those!

@jroper
Copy link

jroper commented Mar 4, 2014

I agree, but I'm not the one writing the apps, I'm the one writing the build tool (https://github.com/sbt/sbt-mocha-plugin). I'm just anticipating what people are going to complain to me about.

@EragonJ
Copy link

EragonJ commented Mar 14, 2014

👍 for this feature ! This would be really useful if we want to put more details in customized reporter.

@evanxd
Copy link

evanxd commented Mar 21, 2014

Yes, would like to have this feature.
Then we could have a reporter could show file name of the failed test case and could find the test files to fix much more easily.

@lambdabaa
Copy link
Author

@visionmedia Thoughts? The patch is nice and small :)

@tj tj closed this as completed in #1174 Mar 28, 2014
@EragonJ
Copy link

EragonJ commented Mar 29, 2014

@visionmedia @gaye ++

@laggingreflex
Copy link

This is good, but would be even better to have access to the filename in after/before hooks as well.. maybe the file could be attached to runner instead of test?

@lambdabaa
Copy link
Author

@laggingreflex 55f01bc

@AakankshaDC
Copy link

Will filename be displayed when run mocha -u exports --recursive test --reporter json on command line? Do I need to change something in my arguments to enable it?

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

Successfully merging a pull request may close this issue.

10 participants