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

root-level hooks are not being called #39

Closed
tsdaita opened this issue Jun 17, 2016 · 4 comments
Closed

root-level hooks are not being called #39

tsdaita opened this issue Jun 17, 2016 · 4 comments

Comments

@tsdaita
Copy link

tsdaita commented Jun 17, 2016

Mocha's root level hooks, ie having before/beforeEach in a different file outside of the describe are not getting called.

tests/sample.js

require('./base');

describe('An afterEach hook', function () {
  afterEach(function () {
    console.log('afterEach run!');
  });

  before(function () {
    console.log('before run!');
  });

  describe('in some nested contexts', function () {
    before(function () {
      console.log('nested before run!');
    });

    it('runs after this block', function () {
      console.log('nested it run!');
    });

    it('runs again after this block', function () {
      console.log('second nested it run!');
    });
  });
});

tests/base.js

before(function hello() {
  console.log('base : before run!');
});

When executing through mocha the before function from base is called

%:mocha runtime/tests/sample.js
base : before run!
An afterEach hook
before run!
in some nested contexts
nested before run!
nested it run!
✓ runs after this block
afterEach run!
second nested it run!
✓ runs again after this block
afterEach run!

2 passing (9ms)

but executing the same through mocha-parallel it seems to ignore the file.

%: node_modules/.bin/mocha-parallel-tests tests/
An afterEach hook
before run!
nested before run!
in some nested contexts
nested it run!
afterEach run!
✓ runs after this block
second nested it run!
✓ runs again after this block
afterEach run!

2 passing (27ms)

@1999
Copy link
Collaborator

1999 commented Jun 17, 2016

Thanks for posting issue. Will take a look at it soon.

@1999
Copy link
Collaborator

1999 commented Jun 24, 2016

Seems interesting: if you move your base.js code into sampe.js, everything works fine.
#40

1999 pushed a commit to 1999/mocha-parallel-tests that referenced this issue Jun 24, 2016
@1999 1999 closed this as completed in cd99750 Jun 24, 2016
@1999
Copy link
Collaborator

1999 commented Jun 24, 2016

mocha-parallel-tests=0.5.1 has the fix @tsdaita

@tsdaita
Copy link
Author

tsdaita commented Jun 29, 2016

Hi,
Apologies for the late response. Thanks for taking a look and fixing it.
Appears this is partially fixed. When passing the individual file ( node_modules/.bin/mocha-parallel-tests tests/sample.js) it seems to work.
But if we give just the dir path (either node_modules/.bin/mocha-parallel-tests tests/ or node_modules/.bin/mocha-parallel-tests tests/*.js) it does not seem to call the root level hooks.

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

No branches or pull requests

2 participants