-
Notifications
You must be signed in to change notification settings - Fork 49
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
Does not work with jest #10
Comments
Hi, sorry about that, and thanks for letting me know! Sorry I haven't tried the Unfortunately I'm not able to reproduce this issue. I've started a new app with If you could please fork this POC repo: https://github.com/FormAPI/craco-antd-test-poc Then please make the minimum changes that can reproduce the issue, and send a PR. I can take a look and see if I can get it working. Thanks! |
Sounds like it might be related to this issue in craco: dilanx/craco#50 But that was fixed in I don't really understand the commit that fixes the issue, but it seems like I have to do some extra steps to get Less working with Jest. |
i too am experiencing this issue. was debating whether to open an issue in this repo or the main craco repo. anyway, from looking at your poc, my guess is that youre not experiencing the issue bc youre importing |
@mlg87 is right, thanks! Change Since the doc from Hope this helps! |
yea, just cloned your poc and tried some scenarios
|
i ended up just using |
Ah I see, I'll change this to use an @mlg87 Using Sorry for the delay on this issue, I've added this to my todo list and should be able to get to it soon. |
Hi, Thanks for the hard work! Any update? |
@ExiaSR Very sorry, I haven't had any time to tackle this yet, but I've added a ticket to my todo list and should get to it in the next few weeks. In the meantime, it would be awesome if you or someone else has time to look into it and contribute a PR. But I'm not sure how much effort it will take |
Hi @ndbroadbent I am pretty new to all those config. I did some research last night, and try out
Unfortunately, none of them working. I end up fallback to My temporary workaround is opt-out from Note: the downside is we can't test styling from
const CracoLessPlugin = require('craco-less');
const ENV = process.env.NODE_ENV;
const babelPlugins = [
[
'babel-plugin-import',
{ libraryName: 'antd', libraryDirectory: 'es', style: true }
],
[
'babel-plugin-styled-components',
{ displayName: true }
]
];
const babelTestPlugins = [];
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
modifyVars: {
'@primary-color': '#4a4a4a',
},
javascriptEnabled: true
},
},
},
],
babel: { plugins: ENV === 'test' ? babelTestPlugins : babelPlugins }
}; |
Hi everyone, I've created a test-app directory, and a puppeteer test that builds the production assets, serves them, opens up the page in Chrome, and checks that the CSS overrides are working properly. It also clicks a button to make sure that a counter state increments. I've also reproduced this test issue when I run Some help would be appreciated, but I'll keep trying to figure it out! |
The save question troubles me. but it occurs from a react ui based antd. ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import '../../sty |
Hi everyone, I just wanted to reiterate that I'm still looking for help with this issue, and a PR would be greatly appreciated! I've just released It would be great if someone has the time to look at the test React/Antd app (under |
I had the same problem: Test suite failed to run
/Users/yassinedamil/code/YassineDM/libradiet/libradiet-app/node_modules/antd/es/spin/style/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/index.less';
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
10 | import PrivateRoute from '../shared/routes/PrivateRoute'
11 |
> 12 | // The `useTranslation()` hook in children components
| ^
13 | // will trigger a `Suspense` if not ready.
14 | export default () => (
15 | <Suspense fallback={<Spin tip="Loading..." />}>
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (src/components/app/App.jsx:12:1) In craco.config.js: const CracoAntDesignPlugin = require('craco-antd')
module.exports = {
plugins: [{ plugin: CracoAntDesignPlugin }]
} In package.json: {
"dependencies": {
"@craco/craco": "^5.2.1",
"antd": "^3.19.2",
"craco-antd": "^1.11.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
}
} Some help would be much appreciated... |
This can be resolved by setting jest to transform any modules that need it, by adding it to the jest: {
configure(config) {
config.transformIgnorePatterns = [
"/node_modules/(?!antd|rc-pagination|rc-calendar|rc-tooltip)/.+\\.js$",
];
return config;
},
}, There might be a better solution, but this works for me, as it was just an extension of a fix I needed for the same issue with At this stage I'm just doing initial setup of antd, so caveat that I haven't actually seriously tested this beyond making sure my current simple tests pass! It's also a fairly blunt fix, as it means antd and deps needs to be transformed as part of tests, which can add a good 10+ seconds to the initial cycle. |
This change uses AntD code from `lib/` instead of `es/`, using transpiled code as Jest will not transpile included code from `node_modules`. Styles are also not included. There is no change for built time, which continues to use the module code and pull styles. Fixes DocSpring#10 Fixes DocSpring#24
Has this issue been fixed now that PR #31 has landed and been released? |
It works with This is a breaking change in the newest PR. There should be an option to use |
I am using antd/es and unable to unit test using react-scripts |
Testing w/o coverage works great. |
Curious why only function syntax works, not the object syntax?
|
You have to add the following to your package.json :
|
Use
craco test
results in the error:Problem resolved when I changed back to
react-scripts test
.BTW,
craco start
works fine.Env
"craco-antd": "^1.9.3",
"@craco/craco": "^3.2.3",
"antd": "^3.11.6",
"react-scripts": "^2.1.1"
Thank you!
The text was updated successfully, but these errors were encountered: