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

Support for JSX is not working for DEBUG mode #174

Closed
sachin-agarwal-by opened this issue May 16, 2021 · 10 comments
Closed

Support for JSX is not working for DEBUG mode #174

sachin-agarwal-by opened this issue May 16, 2021 · 10 comments

Comments

@sachin-agarwal-by
Copy link

I am using Jest-Runner with Create-React-APP and when I am debugging test case for example abcs.test.js its saying Support for the experimental syntax 'jsx' isn't currently enabled... Can you please help. I am not using babel in my project. How to fix this.

@firsttris firsttris reopened this Jun 2, 2021
@firsttris
Copy link
Owner

firsttris commented Jun 2, 2021

hey @sachin-agarwal-by, thx for reporting. i was able to reproduce your issue.

@firsttris firsttris changed the title Support for jsx is not enabled Support for JSX is not working for DEBUG mode Jun 2, 2021
@firsttris
Copy link
Owner

image

@sachin-agarwal-by
Copy link
Author

when can we expect tgis to fix otherwise this extension is no use for tsx code

@firsttris
Copy link
Owner

i found that its not at all related to my extension rather missing configuration.

you need to add a babel.config.js

// babel.config.js
module.exports = {
    presets: [
      ["@babel/preset-env", { targets: { node: "current" } }],
      "babel-preset-react-app",
    ],
  };

and also a jest.config.js

module.exports = {
  transform: {
    '\\.(js|ts|jsx|tsx)$': 'babel-jest',
    '\\.(jpg|jpeg|png|gif|ico|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|webmanifest|xml)$':
      '<rootDir>/jest/fileTransformer.js'
  },
  moduleNameMapper: {
    '\\.(css)$': 'identity-obj-proxy'
  },
}

image

@sachin-agarwal-by
Copy link
Author

I am not using babel but still do we need to add babel.config.js ?

@firsttris
Copy link
Owner

i tested with Create-React-App

@sachin-agarwal-by
Copy link
Author

great , thanks a lot for looking again.. I will try .

@hyluo1
Copy link

hyluo1 commented Oct 8, 2021

module.exports = {
  transform: {
    '\\.(js|ts|jsx|tsx)$': 'babel-jest',
    '\\.(jpg|jpeg|png|gif|ico|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|webmanifest|xml)$':
      '<rootDir>/jest/fileTransformer.js'
  },
  moduleNameMapper: {
    '\\.(css)$': 'identity-obj-proxy'
  },
}

image

What is a <rootDir>/jest/fileTransformer.js?
I can't run debug without it

@Bamboleyla
Copy link

@firsttris I use a project created with the help of the CRA, Just is configured automatically and is missing by default fileTransformer.js , a react-app-env.d.ts file is created in its place.

//react-app-env.d.ts

/// <reference types="react-scripts" />

This file references TypeScript types declarations that are specific to projects started with Create React App.

These type declarations add support for importing resource files such as bmp, gif, jpeg, jpg, png, webp, and svg. That means that the following import will work as expected without errors:

import logo from './logo.svg';

It also adds support for importing CSS Modules. This relates to import of files with .module.css,.module.scss, and .module.sass extensions.

All tests work fine using the standard command from package.json:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test ",   
  },

Your solution forces to create babel.config.js, jest.config.js, and fileTransformer.js . In which you need to describe the handlers for each imported extension, as well as modules. It's long and difficult.

Maybe there is another way? Without fileTransformer.js ?

@PhilippeRoy
Copy link

Hope this helps some, I got debug to work for CRA in vscode by doing the following: #315

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

5 participants