-
-
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
Fix 1604: Add support for async skip() #1618
Conversation
Thanks Dan, Looks good. but there's an issue with the global suite. beforeEach(function() {
this.skip()
})
it('should never run this test', function() {
throw new Error('never thrown')
})
describe('Should run this suite', function() {
it('run this test case', function() {
// ..
})
}) I get the following: - should never run this test
Should run this suite
✓ run this test case
1 passing (10ms)
1 pending but with this one: beforeEach(function(done) {
var hook = this
setTimeout(function() {
hook.skip()
})
})
it('should never run this test', function() {
throw new Error('never thrown')
})
describe('Should run this suite', function() {
it('run this test case', function() {
// ..
})
}) I get the following: - "before each" hook
0 passing (9ms)
1 pending let me know if something isn't clear. |
Looks like you found a bug with the existing skip() behavior with your first example: describe('suite', function() {
beforeEach(function() {
console.log('hook');
this.skip();
});
it('should never run this test', function() {
throw new Error('never thrown');
});
describe('Should run this suite', function() {
it('should never run this test', function() {
throw new Error('never thrown');
});
});
});
// Result
$ mocha test.js
hook
․hook
․
0 passing (6ms)
1 pending
1 failing We should probably open a second issue for that. As for the second example, I'll get a fix ready, thanks! :) |
@a8m Fixed! // test.js
beforeEach(function(done) {
var hook = this
setTimeout(function() {
hook.skip()
})
})
it('should never run this test', function() {
throw new Error('never thrown')
})
describe('Should run this suite', function() {
it('run this test case', function() {
// ..
})
});
// output
$ ./bin/mocha --reporter spec test.js
- should never run this test
Should run this suite
✓ run this test case
1 passing (10ms)
1 pending The above output matches what you'd get using the synchronous skip. It's probably worth discussing whether or not asynchronously skipping a test is functionality we'd like to support. Could be a rabbit hole. :) What do you think @boneskull ? |
What's the benefit of async skipping a test vs delayed suite definition? Besides maybe cleaner? |
That may be the only reason - it might look cleaner. The same applies to using skip() from a synchronous spec. describe('suite', function() {
var someCondition = getConditionValue();
// In conditional block, which isn't ideal as it
// won't show up as pending
if (someCondition) {
it('test', function() {
assert(true);
});
}
// Handling the spec so that it'll show as pending
var test = (someCondition) ? it : it.skip;
test('test', function() {
assert(true);
});
// Using skip()
it('test', function() {
if (!someCondition) return this.skip();
assert(true);
});
}); I don't personally rely on this functionality. But if we see value in a synchronous |
If it's well tested, I wouldn't mind using it. Btw, not picky concretely with this case, as there are many more existing tests in this style, but I personally prefer making tests which must all pass. e.g., for this case, ideally I would run mocha inside mocha, asserting the quantity of skipped tests or which tests were skipped. The problem with this is the I don't really like having tests that are expected to be skipped, since if they suddenly start passing one does not notice unless he/she reads carefully the |
Completely agree! Full integration tests for some cases would be nice. You could execute mocha and check its output, kinda like https://github.com/danielstjules/buddy.js/blob/master/spec/integration/buddySpec.js If we were to pursue running mocha in mocha, it would be better to also rely on the last known good release of mocha, rather than using |
I think the existing behavior of I guess the real reason I'm not sure about async skip is that you're relying on there not being other issues, outside the currently running spec. E.g. if an exception is thrown from some random timeout and wrongly attributed to a spec that would be skipped. It becomes more difficult to reason about. I haven't experienced this scenario, but it seems common among those having trouble with their tests (or codebase). $ cat test.js
setTimeout(function() {
throw new Error('ohno!');
}, 100);
it('test', function(done) {
setTimeout(function() {
this.skip();
}.bind(this), 100);
});
danielstjules:~/git/mocha (issue-1604 =)
$ ./bin/mocha --reporter spec test.js
1) test
0 passing (105ms)
1 failing
1) test:
Uncaught Error: ohno!
at null._onTimeout (test.js:2:9) |
True. Actually, I started creating tests for async errors ending up in other suites, but the |
Tested. works good @danielstjules .
Agree, but at least 'async' aligned to behave the same way as 'non-async'. |
Thanks @a8m! @dasilvacontin I'm going to add some "integration" tests for this, under a new test directory. |
@dasilvacontin Got some quick integration tests running. @travisjeffery @boneskull Mind taking a look? :) |
lgtm! |
LGTM |
before we merge it i just wanna think about whether we should add it, or just say used a delayed suite. considering pretty much no one in the thread has said they'd actually use this and since exceptions are a downside |
Though I don't personally use Edit: Happy to discuss. :) I was certainly on the fence with the idea at first, though I guess I'm more supportive of it now. Looking at #332 and #946 I think it was a popular request |
Since the integration tests are a bit slower, and the acceptance tests are ran against the jsapi, I've moved them into their own directory. This way |
@mochajs/mocha Any thoughts? :) |
Couldn't look at it, but damn, those tests are sexy. I'd rather let this be merged by either @travisjeffery or @boneskull too. Besides, @travisjeffery said he wanted to taco about it. |
I fully agree with you! |
Even if this doesn't get merged, I could use the helper for the tests I was doing for |
@danielstjules Does this make |
I don't think so, though there's some overlap in the problems that they can solve. |
@boneskull To achieve dynamic skip-like functionality using defer, I believe you end up having to resort to roughly the same logic as I mentioned in #1618 (comment) |
@boneskull were you looking for additional details for this PR? |
2f458ab
to
2952eca
Compare
@mochajs/mocha If there's interest in bringing this into 2.3.0, I'll do another quick rebase. It would offer some additional flexibility, solving the problem discussed in #1480 (comment) |
@danielstjules big 👍 as far as I'm concerned. And don't worry too much about being quick to catch 2.3.0, I think it'll be an other week before we publish the release, and we're discussing merging some breaking changes as well and bumping it up to 3.0.0 instead - see #1782 |
@jbnicolai if we do release the major, we need to create a new milestone and retarget everything targeted to v3.0.0 to v4.0.0. then we can rebase branch v3.0.0 into master. cc @mochajs/mocha anyway, it looks like this needs rebasing (again), so whoever does that can merge it |
@boneskull Rebased. Should I target 2.3.0, or is master fine? |
@danielstjules sorry, didn't see this one. we can release it in 2.3.1 if you wish |
@boneskull Did you mean 2.3.0? If so, I can rebase again and get things ready to merge :) Doesn't look like 2.3.0 has been tagged yet https://www.npmjs.com/package/mocha |
@danielstjules I'm about to tag v2.3.0 |
I'm jumping through hoops to get functionality similar to async skip() in the node_redis test-suite, would love this feature. |
I'll pick this back up - should be pretty easy to get it working with latest master. However, I'm not sure when a realistic date would be for another minor release. |
What's blocking this from merging? This doesn't appear to have made it to 2.3 nor 2.4.
What is a "delayed suite"? The only mention of "delay" I can find in the docs is delaying the root suite, which, I can't imagine any use cases for async skipping tests that would be solved by that. And yes, my use case does require skipping an async test, I'm testing an interaction between my code and Is there any help I can offer to get this merged? |
I think @danielstjules just needs to clean it up a bit, but I'm not sure. perhaps he can comment. |
(the tests for this PR aren't actually passing, so something is broken) |
This solution doesn't work anymore after a patch release changing how some error handling was done, haven't been able to come up with an alternative yet. |
This is for #1604