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

'before' and 'after' run in later suites even with '--bail' #690

Closed
AndrewRayCode opened this issue Dec 13, 2012 · 16 comments
Closed

'before' and 'after' run in later suites even with '--bail' #690

AndrewRayCode opened this issue Dec 13, 2012 · 16 comments

Comments

@AndrewRayCode
Copy link

I don't think this should be the case? Shouldn't it skip everything else, including befores and afters?

$ mocha --version
1.7.0

$ cat testing/a.js
describe('Initial test', function() {
    before(function() {
        console.log('initial before');
    });

    describe('test will fail', function() {

        it('will fail', function() {
            throw new Error('failed');
        });
    });

    after(function() {
        console.log('calling after');
    });
});

$ cat testing/b.js 
describe('Second test', function() {
    before(function() {
        console.log('second before');
    });

    describe('second test does not matter', function() {

        it('this test should not run', function() {
            throw new Error('I do not matter');
        });
    });

    after(function() {
        console.log('calling second after');
    });
});


$ mocha --bail testing/

initial before
․calling after
second before // SHOULD NEVER BE CALLED
calling second after // SHOULD NEVER BE CALLED

✖ 1 of 2 tests failed:

1) Initial test test will fail will fail:
    Error: failed
@tj
Copy link
Contributor

tj commented Dec 15, 2012

it should work for that test-case and then bail, which is the result that I get

@AndrewRayCode
Copy link
Author

What are "it" and "that" ?

@tj
Copy link
Contributor

tj commented Dec 16, 2012

if a test case fails afterEach for that case only should execute, but subsequent test cases / hooks should not

@AndrewRayCode
Copy link
Author

Ok, well it seems like they are. I just did an npm install -g mocha and I'm still seeing the same behavior, the second test before / after hooks are getting called. I'm on Mac OSX.

$ mocha --version
1.7.4

$ node --version
v0.8.1

any ideas?

@AndrewRayCode
Copy link
Author

no ideas?

@tj
Copy link
Contributor

tj commented Jan 1, 2013

no ideas, works fine for me on osx and node 0.8.x

@chakrit
Copy link

chakrit commented Feb 20, 2013

I can reproduce this and I have other problems with before/after running/not running/ran out of order too (that's why I was looking at this issue)

Running the code OP posted above produce the exact same result (before/after ran even when it shouldn't)

https://gist.github.com/chakrit/4992989

$ mocha --version
1.8.1
$ node --version
v0.8.20
$ uname -a
Darwin 12.2.1 Darwin Kernel Version 12.2.1: Thu Oct 18 12:13:47 PDT 2012; root:xnu-2050.20.9~1/RELEASE_X86_64 x86_64

@chakrit
Copy link

chakrit commented Feb 20, 2013

Just tried cat a.js b.js > c.js && rm a.js b.js -- both tests in a single file. Still produce the same output.

@ultraflynn
Copy link

Just confirming that this test case still exhibits the same behaviour:

$ mocha --version
1.8.1
 initial before
.calling after
second before
calling second after


  × 1 of 2 tests failed:

  1) Initial test test will fail will fail:
     Error: failed
...

@AndrewRayCode
Copy link
Author

Wanna take another look at this @visionmedia ?

@pkyeck
Copy link

pkyeck commented Mar 21, 2013

+1
running into the same "problems" while testing a suite with multiple files

mocha -t 10000 -R 'spec' -b *.js

mocha 1.8.2

@chakrit
Copy link

chakrit commented May 7, 2013

Confirming this still happens with 1.9.0. Also tests are still running out of order. I wish I'd have proper test case to file a separate issue :/

In case anyone want to test this out, you can clone this gist: https://gist.github.com/chakrit/5530541 and run mocha --bail test.js

@AndrewRayCode
Copy link
Author

Interestingly, the rules of open source software say that at month 6 of inaction by @visionmedia, we are required to form a picket line outside of his place of residence to induce shame.

@chakrit
Copy link

chakrit commented May 7, 2013

Would love to fix this myself with a PR but not feeling like diving into a foreign codebase right now :(

@tj
Copy link
Contributor

tj commented May 23, 2013

3f2d701

@tj tj closed this as completed May 23, 2013
@AndrewRayCode
Copy link
Author

when is this going to be released??

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.

5 participants