-
Notifications
You must be signed in to change notification settings - Fork 1.4k
prevent nested tests #948 #961
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
prevent nested tests #948 #961
Conversation
lib/runner.js
Outdated
| var macroArgIndex; | ||
|
|
||
| if (this.hasBegunRunning) { | ||
| throw new Error('Cannot have nested tests or hooks'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also happen with:
test(async t => {
// stuff
});
setImmediate(() => {
test(t => {
// not allowed!
});
});The message should include something about declaring tests async.
All tests and hooks must be declared synchronously in your test file, and cannot be nested within other tests.
Add a second one that tests what I talked about above, and I think you are covered. // test
var r = new Runner();
r.test(() => Promise.resolve());
r.run()
t.throws(() => {
r.test(() => {});
}, {message: ...})
One of the best first PR's I have seen. Very good job. 🎉 |
|
also I didn't know what type of error to throw |
|
Ok, I will add that test and also tweak the error message and the second test |
|
Ok I'm gone with those changes. Let me know if there is anything else I need to change. |
|
👍 great job! |
|
thanks! |
|
LGTM |
lib/runner.js
Outdated
|
|
||
| this.results = []; | ||
| this.tests = new TestCollection(); | ||
| this.hasBegunRunning = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use isRunning instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't name it isRunning because it isn't reset to false after the tests are done running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I don't like hasBegunRunning either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasStarted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with that then.
|
Ok, I changed the property name. |
|
Also should we mention in the docs somewhere that you shouldn't have embedded tests or hooks. And also that we have no alternative to describe. |
|
Thanks @asafigan!
That probably belongs in a "transitioning from mocha/tape" recipe. Not sure it belongs in the core docs. |
|
woot! first contribution! 🎉 |
|
Awesome work @asafigan! |
|
Super first PR. Thanks @asafigan! Keep 'em coming ;) |

This is my first pull request so any feedback is welcome.
fixes #948
Added a test in the runner test file which expects an error to be thrown when test is called in a test. I don't know if this is the right file to put this test, but it seem like a good place since my solution only changed the runner.js file.
My solution was to add a new property to runner called 'hasBegunRunning' which is set to true in the run method. The chaining function checks this property and throws an error when it is true.
I don't know if this is a good solution but it is simple and it works. Also, I don't know if I need more tests for this pull request.