Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Debug Tests in Visual Studio Code #46

Open
Vikaskumargd opened this issue Jul 11, 2017 · 14 comments
Open

Debug Tests in Visual Studio Code #46

Vikaskumargd opened this issue Jul 11, 2017 · 14 comments

Comments

@Vikaskumargd
Copy link

Is there a way to debug tests in vs code?

@Vikaskumargd Vikaskumargd changed the title Debug Tests Debug Tests in Visual Studio Code Jul 23, 2017
@gbatterbee
Copy link

did you find a way to do this?

@Vikaskumargd
Copy link
Author

No , all of them were failed attempts. 😔

@Vikaskumargd
Copy link
Author

Hi @gbatterbee , do you find any solution for this?

@gbatterbee
Copy link

gbatterbee commented Sep 10, 2017 via email

@gbatterbee
Copy link

gbatterbee commented Sep 10, 2017 via email

@Vikaskumargd
Copy link
Author

@gbatterbee Are you able to run debug test on simple CRA app?

@gbatterbee
Copy link

gbatterbee commented Sep 10, 2017 via email

@Vikaskumargd
Copy link
Author

nope this doesn't work for me :(

@Vikaskumargd
Copy link
Author

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "runtimeArgs": [
        "--inspect-brk",
        "test"
      ],
      "args": [
        "--runInBand",
        "--no-cache",
        "--env=jsdom"
      ],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

this config start the debugger and ran the test but never hit the breakpoint

@gbatterbee
Copy link

gbatterbee commented Sep 11, 2017 via email

@Vikaskumargd
Copy link
Author

Vikaskumargd commented Sep 13, 2017

Thanks @gbatterbee
please let me know the config when you'll available.

@Vikaskumargd
Copy link
Author

Vikaskumargd commented Sep 19, 2017

giphy-downsized

  1. Update react-scripts-ts (to v2.7.0).
  2. Update Node.js (to v8.5.0)
  3. Use this config in launch.json (VS code)
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Debug CRA Tests",
        "type": "node",
        "request": "launch",
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts-ts",
        "runtimeArgs": [
          "--inspect-brk",
          "test"
        ],
        "args": [
          "--runInBand",
          "--no-cache",
          "--env=jsdom"
        ],
        "cwd": "${workspaceRoot}",
        "protocol": "inspector",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen"
      }
    ]
  }
  1. From Typescript <2.5.0 to >=2.5.0

Version 2.5.0 introduces a new config file for jest, that is necessary for the tests to run. If you were previously running a version older than v2.5.0 and upgraded to v2.5.0 or newer, you need to manually add the new file, or else you'll get an error similar to this when trying to run your tests:

Test suite failed to run

{
    "messageText": "Cannot read file 'C:\\[project]\\tsconfig.test.json': ENOENT: no such file or directory, open 'C:\\[project]\\tsconfig.test.json'.",
    "category": 1,
    "code": 5012
}

To fix this, create a new file in the root of the project called tsconfig.test.json, and paste the content of this file into it. Everything should work now. For more info, please see this issue.

@gbatterbee
Copy link

This makes me a very happy person :D
Thanks for sharing @Vikaskumargd

@jednano
Copy link

jednano commented Feb 23, 2018

Moving test to the runtimeArgs didn't work for me. --inspect-brk didn't get rid of that deprecation warning either, so this is what worked for me...

{
	"version": "0.2.0",
	"configurations": [
		{
		  "name": "Debug CRA Tests",
		  "type": "node",
		  "request": "launch",
		  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts-ts",
		  "args": [
			  "test",
			 "--runInBand",
			 "--no-cache",
			 "--env=jsdom"
		  ],
		  "cwd": "${workspaceRoot}",
		  "protocol": "inspector",
		  "console": "integratedTerminal",
		  "internalConsoleOptions": "neverOpen"
		}
	]
}

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

No branches or pull requests

3 participants