-
-
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
Allow skip from test context for #332 #946
Conversation
Copied from my comment on the referenced issue regarding concerns with this PR as a first draft: One part that feels a little ugly at the moment is that calling
|
|
||
function Pending(message) { | ||
this.constructor.prototype.__proto__ = Error.prototype; | ||
Error.captureStackTrace(this, this.constructor); |
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.
we should be able to get away with leaving all this stuff out since we're catching anyway
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.
Yeah, perhaps this was gold-plating on my part. I’ll add a commit to remove it. What are your thoughts on how it behaves in afterEach
(and in general)?
we already have a way to skip test with the xit apis so this would be inconsistent with those. and inside the test you could just use a return statement. |
I'm sorry, but I'm not quite sure how the existing At best, they seem to be a temporary measure — akin to commenting out a test while trying something out. In #332 you mention the need for use cases, as there are a lot of +1's on the thread. In my mind, @grampajoe gives the best example. Simply adding a So currently, users need to do one of the following: // Option 1: just don't run the tests.
// Not as bad as reporting a pass, but doesn't give the full picture.
if (frobulation_supported()) {
describe('tests dependent on frobulation', function () {
});
}
// Option 2: Come up with their own way to mark these tests as skipped.
// A little clunky, not very readable or portable.
var describe_frobulation = (frobulation_supported() ? describe : describe.skip);
describe_frobulation('tests dependent on frobulation', function () {
}); The proposed change would mean users could do this: describe('tests dependent on frobulation', function () {
before(function () {
if (frobulation_not_supported()) this.skip();
});
}); Or even: this.skipIf(frobulation_not_supported()); Unless you would suggest a different way to address these concerns with the existing API? |
alright, i see. seems strange but lots of people want it. i'm not sure if this is the best way, but something will happen shortly. |
I wasn't sure either, but I'd welcome any feedback on the PR. |
This would be a nice feature to add. We ran into the need to skip a test if a condition in one of the environments the test suite is run in Sounds like this patch, so +1 from me. |
Easy, already implemented:
|
@sukima thanks for the suggestion, but this does not seem to work when this.pending needs to be set in an asynchronous function. |
I have an immediate need for this too. I wish to skip tests if a particular transient network service isn't available, I don't want it to fail everything, but just run if they're available. |
👍 great feature, it's irritating that this isn't part of the base library |
@travisjeffery probably concerns with inconsistencies. Do you suggest an edit on the implementation? |
@travisjeffery I'm going to reopen this one to get it back on the table, please close again if you have a different solution. |
@starsquare could you please rebase on top of master? |
Rebased, and all looks good. |
Great thx. |
@travisjeffery Please let me know if this is OK to merge; it wasn't clear if you had something else in the works. |
35c1580
to
64dfc0b
Compare
alright sounds good, just need to update the pr so we've got a clean merge. and we're g2g |
Rebased off current master. |
👍 |
Needs rebasing again. I will merge if you rebase. Sorry for the hassle. |
Rebased again, no issues or conflicts 😄 |
Thanks! |
Allow skip from test context for #332
any chances to see new version with this feature included soon? |
Hi! I can't get this to work with webdriver.io (see below example). Also, was this reverted? This feature doesn't seem to be present in the current version of mocha??
|
This was merged in 6402fff so is present in 2.2.0+. Any more information on the error? May be worth filing a separate issue. |
@maggiesavovska what's the actual error? Is the test timing out, or is it something else? |
I just experienced this: async.js it('should be skipped async', function (done) {
const self = this
setTimeout(function () {
self.skip()
}, 1000)
}) $ mocha test/async.js
1) should be skipped async
0 passing (1s)
1 failing
1) should be skipped async:
Error: the object {
"message": [undefined]
"uncaught": true
} was thrown, throw an Error :) |
@dasilvacontin + @cmbuckley: Please forget what I said about webdriver.io. I think it's a general issue. I get the same as @dasilvacontin (uncaught error with undefined message). I actually was only able to get this to work at all by modifying the current version of mocha so I'm guessing this feature is somehow broken due to recent changes (regardless of whether its used with webdriver.io promise or not). |
Hi, sorry to be a bug, but were you able to confirm that this feature isn't currently working? I really need this for the project I'm working on now. Thanks! |
Well, I can confirm @dasilvacontin 's code is throwing that error |
Is this a regression? Did we ever have this support for async tests? |
Opening a PR to get some feedback for this implementation.