Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created July 18, 2018 17:04
Show Gist options
  • Save Kashkovsky/19ae675ac0985163cd0048800f503f3c to your computer and use it in GitHub Desktop.
Save Kashkovsky/19ae675ac0985163cd0048800f503f3c to your computer and use it in GitHub Desktop.
Debug typescript jest tests in VS Code
/** .vscode/launch.json */
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
"-i"
],
"preLaunchTask": "ts",
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceRoot}/dist/**/*"
]
}
,]
}
/** Jest configuration section */
...
"jest": {
"roots": [
"<rootDir>/dist"
],
"transform": {
"^.+\\.tsx?$": "ts-jest" // install ts-jest to be able to set breakpoints in tsx files
},
"testRegex": "(/__tests__/.*|(\\.|/)(spec))\\.js$",
"moduleFileExtensions": [
"js"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"setupTestFrameworkScriptFile": "<rootDir>/buildScripts/testSetup.js",
"testEnvironment": "<rootDir>/buildScripts/environment.js"
}
...
/** .vscode/tasks.json */
{
"version": "2.0.0",
"tasks": [
{
"label": "ts",
"type": "typescript",
"tsconfig": "wwwroot/App/reactApp/tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
/** React adapter for Enzyme */
const Enzyme = require("enzyme");
const ReactSixteenAdapter = require("enzyme-adapter-react-16");
Enzyme.configure({ adapter: new ReactSixteenAdapter() });
/** [optional] extends main tsconfig, sets output directory */
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment