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

"craco test" does not respect babel plugins #50

Closed
Dakkers opened this issue Dec 5, 2018 · 6 comments
Closed

"craco test" does not respect babel plugins #50

Dakkers opened this issue Dec 5, 2018 · 6 comments

Comments

@Dakkers
Copy link
Contributor

Dakkers commented Dec 5, 2018

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);
});
@patricklafrance
Copy link
Contributor

patricklafrance commented Dec 5, 2018

Hi @Dakkers

I tried to run the test with a react-mobx observer (as a decorator) using the "@babel/plugin-proposal-decorators" plugin with the legacy option and it works fine.

Have you changed your npm test script to call craco instead of CRA?

"scripts": {
    "test": "craco test"
}

@Dakkers
Copy link
Contributor Author

Dakkers commented Dec 6, 2018

yes, I have done that, hence also mentioning directly running the executable also is not working 😿

@patricklafrance
Copy link
Contributor

Can you setup a gtihub repository that reproduce the problem?

@stam
Copy link

stam commented 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.

@patricklafrance
Copy link
Contributor

Thank you @stam

@patricklafrance
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants