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

Jest and ES6 keyword import #1346

Closed
mrnagydavid opened this issue Dec 6, 2018 · 6 comments
Closed

Jest and ES6 keyword import #1346

mrnagydavid opened this issue Dec 6, 2018 · 6 comments

Comments

@mrnagydavid
Copy link

Expected Behavior

Jest runs the test without having to compile the (test) code to ES5.

Actual Behavior

Jest does not run the test because it fails on the import keyword.

Test suite failed to run 
      ● Test suite failed to run
    /tmp/5bf052071b655e0012853b18/environment/1c863b03-a0dc-4bb2-b5b4-aa4886ba50ca/index.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import {
                                                                                             ^^^^^^
    SyntaxError: Unexpected token import
      at ScriptTransformer._transformAndBuildScript (../../components/testers/jest/bit.envs/0.0.34/node_modules/jest-runtime/build/script_transformer.js:316:17)

Steps to Reproduce the Problem

  1. Create a component to upload to bit.
  2. Create a test file that imports the tested function with import instead of require
  3. Import bit component jest as tester (which includes babel)
  4. After bit add <component> run bit test or bit tag

Specifications

  • Bit version: 13.0.4
  • Node version: 11.1.0
  • npm / yarn version: 1.12.3
  • Platform: MacOS
  • Bit compiler (include version): -
  • Bit tester (include version): jest@0.0.34

Or at least how can I remove the tester from the project? I added it with bit import, but bit remove does not seem to work.

@GiladShoham
Copy link
Member

@mrnagydavid Thanks for reporting this.
Currently in bit, a tester will run on the compiled files. So the best way to solve the issue is probably to add a bit compiler to your project, like babel or webpack, read more here.

If you want to remove the tester, you can edit the bit.json file in the root of your workspace and remove the tester entry.

In the future we will add an option to run the tester on the source files in case your tester run's build himself.

I'm closing this, since this is the expected behaviour.
Let us know if you need any further help.

@ArtemKorchunov
Copy link

Adding compiler does not help me, and the one strange thing that I faced was that tests run successfully in local with the command bit test ui/add-button but fails remotely

Actual behavior

  ● Test suite failed to run

/workspace/environment/47aab6bb-1257-47bf-bc96-7213ffb5d536/addButton.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
                                                                                         ^^^^^^

SyntaxError: Unexpected token import
  
  at ScriptTransformer._transformAndBuildScript (../../components/testers/jest/bit.envs/22.4.3/node_modules/jest-runtime/build/script_transformer.js:316:17)`

Steps to reproduce

  1. Create a component to upload to bit.
  2. Create a test file that imports the tested function with import instead of require
  3. Import bit component jest as tester (which includes babel)
  4. Import bit component react as compiler (which includes babel)
  5. Export component

Specifications

  • Bit version: 14.0.4
  • Node version: 10.15.2
  • npm / yarn version: 6.11.3 / 1.17.3
  • Platform: Linux
  • Bit compiler (include version): react@1.0.2
  • Bit tester (include version): jest@22.4.3

@GiladShoham GiladShoham reopened this Sep 25, 2019
@GiladShoham
Copy link
Member

Hi, I'm re-open this issue.
Can you please create a simple repo / bit collection to reproduce this issue?
We are working on a new piece of tech which will make all the compilers / testers to be much more stable between the local and the remote.
This involves also re-writing all of our compilers and testers.
So it will take some time.
But we might solve this issue specifically on the existing version.

@ArtemKorchunov
Copy link

ArtemKorchunov commented Sep 25, 2019

@VCuzmin
Copy link

VCuzmin commented Oct 21, 2020

I've come across this issue too. This is because you might have compiled your code into ES modules and Jest just doesn't have ES6 support. Take a look over here: jestjs/jest#4842

@itaymendel
Copy link
Contributor

resolved in v15

We'll start rolling out v15 of Bit this week, please reach out to me privately on the public slack community for a sneak peek and getting early access to it.

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

No branches or pull requests

6 participants