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

Converting mocha tests to jest #2316

Closed
wants to merge 3 commits into from
Closed

Converting mocha tests to jest #2316

wants to merge 3 commits into from

Conversation

anilreddykatta
Copy link
Contributor

Converting mocha tests to jest
Fix for #2294

@gaearon
Copy link
Contributor

gaearon commented May 22, 2017

I don’t think this worked, judging by CI logs:

+ node_modules/.bin/jest integration/env.test.js integration/syntax.test.js integration/webpack.test.js
No tests found
In C:\Users\appveyor\AppData\Local\Temp\1\tmp.gpf6MqNoCa\test-kitchensink
  91 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 29 matches
  testPathIgnorePatterns: \\node_modules\\ - 91 matches

Copy link
Contributor

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix it to run the tests.

@anilreddykatta
Copy link
Contributor Author

@gaearon This is weird. I can see tests passing in travis.
screen shot 2017-05-22 at 11 13 45 am

In Appveyor it is showing that there are no tests.
screen shot 2017-05-22 at 11 15 30 am

am I missing something?

@gaearon
Copy link
Contributor

gaearon commented May 22, 2017

Maybe integration/*.test.js doesn't match cross platform?

Maybe we could either change the pattern to be cross platform, or just cd into that directory and run Jest there without a pattern.

@anilreddykatta
Copy link
Contributor Author

@gaearon Small insights will be very helpful. I tried both going to the directory and executing tests. I can observe from attached screenshots that files have been detected but not somehow tests in them. This is only happening in Windows, on Mac & Linux tests are running!

@gaearon
Copy link
Contributor

gaearon commented Jun 1, 2017

On the CI, I see this command:

node_modules/.bin/jest integration/*.test.*

As I mentioned earlier it might not work on Windows because of / in the path.

Can you try instead cd'ing into integration and then run ../node_modules/.bin/jest *.test.*?

@anilreddykatta
Copy link
Contributor Author

@gaearon OK. Let me try that. Thank you very much!

@gaearon
Copy link
Contributor

gaearon commented Jun 27, 2017

import() syntax is failing:

 FAIL  src/features/syntax/Promises.test.js
  ● Test suite failed to run
    /tmp/tmp.wJjoN2bfHW/test-kitchensink/src/features/syntax/Promises.test.js:16
        return import('./Promises').then(function (_ref) {var Promises = _ref.default;
               ^^^^^^
    SyntaxError: Unexpected token import
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at handle (node_modules/worker-farm/lib/child/index.js:41:8)
      at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3)
      at emitTwo (events.js:106:13)

Seems like we need to configure Jest to handle it? Why does it work with Mocha?

@Timer
Copy link
Contributor

Timer commented Jun 27, 2017

@gaearon it was most likely due to mocha handling NODE_ENV differently when calling babel-register.

I suspect the issue here is that we are setting NODE_ENV=development when Jest needs our babel preset when ran with NODE_ENV=test (to add the plugin to compile import() to require).

@gaearon
Copy link
Contributor

gaearon commented Jun 27, 2017

So what do we need to do? This almost works.

@Timer
Copy link
Contributor

Timer commented Jun 27, 2017

We probably just need to switch the NODE_ENV=test for the tests, or make our preset detect that it's running inside of Jest. The latter is probably the best.

@gaearon
Copy link
Contributor

gaearon commented Jan 10, 2018

This is fairly close, but it now fails due to CSS/image imports. Can we point them to our mocks to fix this?

@bugzpodder bugzpodder mentioned this pull request Jun 2, 2018
@Timer
Copy link
Contributor

Timer commented Sep 21, 2018

Completed via #4550.

@Timer Timer closed this Sep 21, 2018
@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants