question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with jest

See original GitHub issue

Use craco test results in the error:

Test suite failed to run

    /Users/xxx/sources/proj/node_modules/antd/es/card/style/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/index.less';
                                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^

    SyntaxError: Unexpected string

      10 |   AutoComplete,
      11 |   message,
    > 12 |   Select
         | ^
      13 | } from "antd";
      14 | import axios from "axios";

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”

// craco.config.js

const CracoAntDesignPlugin = require("craco-antd");

module.exports = {
  plugins: [
    {
      plugin: CracoAntDesignPlugin,
      options: {
        customizeTheme: {
          "@primary-color": "#8440bd"
        }
      }
    }
  ]
};

Thank you!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

14reactions
c-spencercommented, Jun 20, 2019

This can be resolved by setting jest to transform any modules that need it, by adding it to the craco.config.js jest section:

  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 monaco-editor. I’m not sure if it can be fixed by default, as it relies on a config override callback, but it can at least be documented.

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.

4reactions
mlg87commented, Jan 4, 2019

yea, just cloned your poc and tried some scenarios

  1. test script is react-scripts test passes with import Button from 'antd/lib/button'
  2. test script is craco test passes with import Button from 'antd/lib/button'
  3. test script is react-scripts test passes with import { Button } from 'antd'
  4. test script is craco test fails with import { Button } from 'antd'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​. Try using the debugging support built into...
Read more >
npm test/ jest not working - Stack Overflow
When I do npm test /jest, I am getting the following error: > @ test /Users/suparnasoman/Downloads/create-react-app-master > node packages/react ...
Read more >
Troubleshooting · Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why #. Try using the debugging support built...
Read more >
Fetch do not work on Jest · Issue #2071 · facebook/jest - GitHub
This test is inside a react native project, I have a very long timeout. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; .
Read more >
Should you use jest as a testing library? - Backend Cafe
jest is a great testing framework, and it works well for frontend applications, but you could face some issues if your dependencies rely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found