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.

"craco test" does not respect babel plugins

See original GitHub issue

Here’s my config:

module.exports = function({ env, paths }) {
  return {
    babel: {
      plugins: [
        [
          '@babel/plugin-proposal-decorators',
          {
            // https://babeljs.io/blog/2018/09/17/decorators
            // https://github.com/mobxjs/mobx/issues/1352
            legacy: true
          }
        ]
      ]
    }
  };
};

npm test (or ./node_modules/.bin/craco test) results in the following error:

image

Craco version: 3.2.0 React-Scripts version: 2.1.1

Test file content:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './../App';
import { shallow } from 'enzyme';

const stores = {
};

it('renders without crashing', () => {
  const div = document.createElement('div');
  shallow(<App {...stores}/>, div);
  ReactDOM.unmountComponentAtNode(div);
});

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
stamcommented, Dec 6, 2018

I created an example here: https://github.com/stam/craco-test-example Just the basic CRA 2 with craco + mobx

FAIL src/App.test.js ● Test suite failed to run

SyntaxError: /Users/phnl320029247/Work/craco-test/src/App.js: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (8:3):

   6 |
   7 | class App extends Component {
>  8 |   @observable foo = 'bar';
     |   ^
   9 |
  10 |   render() {
  11 |     return (

  at _class.raise (node_modules/@babel/parser/lib/index.js:3939:15)
  at _class.expectOnePlugin (node_modules/@babel/parser/lib/index.js:5267:18)
  at _class.parseDecorator (node_modules/@babel/parser/lib/index.js:7320:10)
  at _class.parseClassBody (node_modules/@babel/parser/lib/index.js:7891:30)
  at _class.parseClass (node_modules/@babel/parser/lib/index.js:7853:10)
  at _class.parseStatementContent (node_modules/@babel/parser/lib/index.js:7181:21)
  at _class.parseStatement (node_modules/@babel/parser/lib/index.js:7153:17)
  at _class.parseStatement (node_modules/@babel/parser/lib/index.js:1902:57)
  at _class.parseBlockOrModuleBlockBody (node_modules/@babel/parser/lib/index.js:7707:23)
  at _class.parseBlockBody (node_modules/@babel/parser/lib/index.js:7694:10)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.243s Ran all test suites.

Watch Usage: Press w to show more.

0reactions
patricklafrancecommented, Dec 6, 2018

Hey guys

The problem is fixed in version 3.2.1-alpha.0

I am going away for a few days, I will publish it as the latest version when I get back.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"craco test" does not respect babel plugins · Issue #50 - GitHub
I tried to run the test with a react-mobx observer (as a decorator) using the "@babel/plugin-proposal-decorators" plugin with the legacy ...
Read more >
Configuring FBT API with TypeScript and create-react-app.
But in short the Babel plugins will read the code to locate and extract the ... with 'craco' for the scripts 'start', 'build'...
Read more >
Why simple babel plugin breaks jest test? - Stack Overflow
I wrote a simple plugin: export default function() { return { visitor: { Program: { enter() { console.log('Program Entered!
Read more >
Creating and testing a react package with CRA and rollup
rollup-plugin-visualizer: Visualize and analyze your Rollup bundle to see which modules are taking up space. Run this to install babel and the ...
Read more >
less-loader | webpack - JS.ORG
less-loader applies a Less plugin that passes all queries to the webpack resolver if less could not resolve @import . Thus you can...
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