rogeliog / jest-runner-mocha

A Mocha runner for Jest
70 stars 12 forks source link

Jest/Mocha not picking up all tests #10

Closed maximilianschmitt closed 6 years ago

maximilianschmitt commented 6 years ago

Hi!

We're looking to parallelize our mocha-based test suite and we think that going with jest and jest-runner-mocha might be the easiest way to get there.

There is one problem we're running into and that is that Jest/Mocha are not picking up all the tests and so quite a few fail with Your test suite must contain at least one test..

The following types of tests are not being picked up:

1. Tests written with co-mocha in mind

Example (notice the generator function):

it('registers a user', function*() {
  const user = yield createUser()
  expect(yield findUser(user.id)).toEqual(true)
})

We've tried require('co-mocha')(require('mocha')) from our jest config file and also from within jest-runner-mocha but that didn't get us anywhere.

2. Tests that generate the it call dynamically

Example:

testForValidationError("when input is invalid", function() {
  return runRequest(invalidInput)
})

function testForValidationError(description, fn) {
  it(`rejects with validation error ${description}`, function() {
    return fn().then(assertValidationError)
  })
}

What can we do to have Jest/Mocha pick up those tests?

Thanks for your help!

rogeliog commented 6 years ago

Thanks for reporting!

maximilianschmitt commented 6 years ago

Hi @rogeliog, thanks for getting back to me!

Using mocha@4.0.1 by the way.

Any ideas?

ljharb commented 6 years ago

I would very much expect the generator example to fail, since that's a pretty weird hack around mocha, which doesn't have generator support (n.b: generators aren't and can't be coroutines, and combining them with a runner is just faking it)

However, I would also very much expect the dynamic it example to work identically, since that's just moving synchronous code around.

maximilianschmitt commented 6 years ago

I'm sorry, the issue was something completely different:

If a promise is rejected (or an error is thrown) inside a beforeEach or if timeout is exceeded in a beforeEach, you will see Your test suite must contain at least one test. but the actual error will not be reported. I think I should create a separate issue for that?

@ljharb generators did turn out to be working as coroutines with co-mocha, as did the dynamic its, like they should :) thanks!