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

Debug Tests in Visual Studio Code #46

Open
@Vikaskumargd

Description

@Vikaskumargd

Is there a way to debug tests in vs code?

Activity

changed the title [-]Debug Tests[/-] [+]Debug Tests in Visual Studio Code[/+] on Jul 23, 2017
gbatterbee

gbatterbee commented on Aug 13, 2017

@gbatterbee

did you find a way to do this?

Vikaskumargd

Vikaskumargd commented on Aug 13, 2017

@Vikaskumargd
Author

No , all of them were failed attempts. 😔

Vikaskumargd

Vikaskumargd commented on Sep 10, 2017

@Vikaskumargd
Author

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

gbatterbee

gbatterbee commented on Sep 10, 2017

@gbatterbee
gbatterbee

gbatterbee commented on Sep 10, 2017

@gbatterbee
Vikaskumargd

Vikaskumargd commented on Sep 10, 2017

@Vikaskumargd
Author

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

gbatterbee

gbatterbee commented on Sep 10, 2017

@gbatterbee
Vikaskumargd

Vikaskumargd commented on Sep 10, 2017

@Vikaskumargd
Author

nope this doesn't work for me :(

Vikaskumargd

Vikaskumargd commented on Sep 10, 2017

@Vikaskumargd
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

gbatterbee commented on Sep 11, 2017

@gbatterbee
Vikaskumargd

Vikaskumargd commented on Sep 13, 2017

@Vikaskumargd
Author

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

Vikaskumargd

Vikaskumargd commented on Sep 19, 2017

@Vikaskumargd
Author

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

gbatterbee commented on Sep 21, 2017

@gbatterbee

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

jednano

jednano commented on Feb 23, 2018

@jednano

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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jednano@Vikaskumargd@gbatterbee

        Issue actions

          Debug Tests in Visual Studio Code · Issue #46 · microsoft/TypeScript-React-Starter