-
Notifications
You must be signed in to change notification settings - Fork 331
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
Add Jest support #173
Comments
any progress on this? |
No, as I don't need this right now, I just want to try it when I have time/motivation to do so. PRs are welcome. |
Do you want to include jest in For example:
// Exclude css and svg from test
jest.mock('../src/react.svg', () => 'react-svg')
jest.mock('../src/App.css', () => 'app-css')
import renderer from 'react-test-renderer'
import React from 'react'
import App from '../src/App'
const renderedApp = renderer.create(<App />)
describe('Renders without errors', () => {
it('Renders correctly', () => {
expect(renderedApp.toJSON()).toMatchSnapshot()
})
})
{
"presets": ["es2015", "react"]
} And 4 more modules: |
For future reference, adding jest to a nwb app is straightforward. Check out this gist for a walkthrough. |
Thanks for the research and examples @rakannimer - my preferred approach (long-term) would be to turn both the current Karma/Mocha setup and Jest integration into testing plugins which follow the nwb approach of generating config (configurable via We can then make testing a question when creating a new project, install the appropriate plugin and generate skeleton tests. Last time I checked, the only thing which seemed to be missing to support this was that you couldn't pass Babel config directly to Jest, rather it had to be in a |
@insin Ran into that last issue you mentioned. Here is how you can do it. You may also be able to use the transform option, but it's been awhile since I've touched this stuff... http://facebook.github.io/jest/docs/configuration.html#transform-object-string-string |
@loklaan ooh, that looks good. Any hacking goes as long as it can stay under the hood. |
In case this helps someone else landing here, here's how I got it to work: ./jest.transform.jsmodule.exports = require('babel-jest').createTransformer({
presets: ['es2015', 'react', 'stage-1'], // or whatever you need
}); "jest" entry in
|
I'm keen to chip away at this one. Would be great to grab some scope from you. So from the looks of it, the intended experience goes like:
I think this would involve:
|
@loklaan thanks for looking at this and the other stuff you're doing. I've made you a collaborator so you can have at it, as I'm at a bit of a low ebb time/motivation-wise at the moment.
|
@insin Cheers! Good to know where you're at motivation wise at the moment – I'll try not to drag you into stuff. I've carved out time for this next week, but I could be testing ideas on the weekend too. |
@loklaan update... I used configure package.json with:
one problem encountered is:
|
@dearfrankg We'll resolve this by sharing the babel config with jest. This coming Friday is devoted to getting Jest into nwb. 💥 Should have something ready to test for the weekend. |
@dearfrankg Just re-read your comment - sorry, you were referring to non-code files and I missed that. We'll do something internally, similar to the suggestion made on "Using Jest with Webpack" page. |
Not this Friday, but Monday* |
This worked for me :
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"coverage": "jest --coverage",
"coverage:watch": "jest --coverage --watch",
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)(\\?.*)?$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
}
}
module.exports = 'test-file-stub'; and i use it with storyshots :
import initStoryshots from 'storyshots';
initStoryshots(); Now all |
Looking forward for Jest on nwb! In the meantime, anyone has an example of how the setup with Jest would look like? Or a step by step on what to do, and why? I haven't done much with Jest before, a bit of this is going over my head. |
It looks promising 👍 |
@revolunet Adding a For example This is what I did: jest.transform.js module.exports = require('babel-jest').createTransformer({
presets: ["es2015", "react"],
plugins: ["transform-object-rest-spread"],
}); jest.config.js "transform": {
"^.+\\.js$": "<rootDir>/jest.transform.js"
}, package.json scripts": {
"test": "jest --config jest.config.json --no-cache",
"test:coverage": "npm test --coverage",
"test:watch": "npm test --server",
} Solution found here |
@ntwcklng
in the |
@baixiaoji |
@ntwcklng
why it load the css file? |
Install yarn add jest-css-modules --dev Add it to your "moduleNameMapper": {
"\\.(css)$": "<rootDir>/node_modules/jest-css-modules"
} It resolves css parsing problems for me |
@xuopled
|
Do you use special config for your jest? |
I don't know what is the special config,but I add the
then has the early err
|
Try to follow the documentation: |
If you use css modules, maybe this issue can help you: jestjs/jest#1220 |
Hey @baixiaoji you should head over to the Reactiflux community for hands on help with Jest problems. Everyone here has been very helpful so far, but it's not on-topic. Cheers! |
Hey just to let everyone know, I can no longer put time into implementing this issue (through #292). I don't want this to come off negative to nwb, because it's actually great. So, to be open about the reason...
If anyone here would like to pick up the issue (I still think it would be very very cool for nwb), then reply in this thread or in #292. I could give some pointers, and insin can get some eyes on whos showing interest. 👍 peace out |
Jest got good
Thinking this should be added as a question when creating an app.
The text was updated successfully, but these errors were encountered: