-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Comments
In both node and the browser we can do this by throwing then catching an error: try {
throw new Error();
} catch(e) {
e;
} |
👍 |
I think it would be great to have the filename in the test object. |
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. |
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;
}
});
}); |
@jroper :( write little modules and build apps with those! |
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. |
👍 for this feature ! This would be really useful if we want to put more details in customized reporter. |
Yes, would like to have this feature. |
@visionmedia Thoughts? The patch is nice and small :) |
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 |
Same with the test suites: mochajs/mocha@55f01bc
Same with the test suites: mochajs/mocha@55f01bc
Will filename be displayed when run |
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?
The text was updated successfully, but these errors were encountered: