serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

Jest - Debug usage with WebStorm

Open Vadorequest opened this issue 4 years ago • 9 comments

Webstorm natively supports debugging tests (single test, multiple tests, whole file) with jest. But since this plugin requires to invoke tests using serverless-bundle script, it's somewhat incompatible with WebStorm's native way of running tests and results with "Jest encountered an unexpected token" because it can't understand ES6 import/export (it's not running jest through webpack/babel)

What's the recommended way to configure WebStorm with serverless-bundle? Or is there any known workaround? (I believe it's possible to configure webstorm to run tests through serverless-bundle, but haven't figured out how yet)

image

image

Vadorequest avatar Jul 25 '19 08:07 Vadorequest

Oh that's interesting. We use a similar approach to Create React App. Do you have any experience with using WebStorm with Create React App?

jayair avatar Jul 25 '19 17:07 jayair

I don't, but looking at my code I see I use react-app-rewired, which does also something quite similar, see:

  • https://github.com/timarney/react-app-rewired/blob/master/scripts/test.js
  • https://github.com/timarney/react-app-rewired/blob/master/bin/index.js

Vadorequest avatar Jul 25 '19 19:07 Vadorequest

If they are doing something similar then it might be related to this issue - https://github.com/AnomalyInnovations/serverless-bundle/issues/4. Maybe all the arguments are not being passed in.

Once we fix that, let's give this a try again.

jayair avatar Jul 26 '19 17:07 jayair

any progress on this? running tests with serverless-bundle test in terminal seems medieval

patrykkrawczyk avatar Dec 03 '19 19:12 patrykkrawczyk

@patrykkrawczyk Not right now. I'm not a WebStorm user, so I need some help with this.

jayair avatar Jan 02 '20 19:01 jayair

@Vadorequest, @patrykkrawczyk: The way I worked around this was to:

  1. Add [email protected] as a devDependency to my own project's package.json (optional I think, but otherwise WebStorm wouldn't display the inline test/debug icon in the editor)
  2. Create a jest.config.js file in your project's root that loads the serverless-bundle config:
// jest.config.js
const path = require('path');
const createJestConfig = require('serverless-bundle/scripts/config/createJestConfig');
const relativePath = (relativePath) => path.resolve(__dirname, 'node_modules/serverless-bundle', relativePath);
module.exports = createJestConfig(relativePath, __dirname);
  1. Update your Jest Run/Debug configuration to use the Configuration file from step 2 and the Jest package from serverless-bundle, e.g.: {your-project-root}/node_modules/serverless-bundle/node_modules/jest image

That seemed to do the trick for me.

markisadesignerd avatar Feb 05 '20 04:02 markisadesignerd

Thanks @markisadesignerd - that worked for me in IntelliJ

I had to remove "type": "module" from my package.json but I can live with that. Also I am pointed to my project's node_modules/jest folder.

rmjwilbur avatar Feb 06 '20 04:02 rmjwilbur

@markisadesignerd Thank you for this! I'll link to this in the README.

jayair avatar Feb 08 '20 19:02 jayair

This works fine but I have a problem with debugging not stepping over (only stops on break-points). It's usable but no ideal.

Any lights?

renanwilliam avatar May 08 '21 15:05 renanwilliam