Skip to content

Commit

Permalink
add option to debug unit tests with VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
rosemcc committed Jul 29, 2020
1 parent 1e4729f commit df4bac4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
{
"name": "Debug tests in Chrome",
"type": "chrome",
"request": "attach",
"address": "localhost",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceFolder}",
"pathMapping": {
"/_karma_webpack_": "${workspaceFolder}"
}
}
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.
`npm run test -- --code-coverage`. The code coverage report is generated and stored in the `coverage/` folder. Coverage thresholds are set at 80% for all files. Less than 80% coverage will generate errors to warn you.
To change any of the test configurations, see [karma.conf.js](karma.conf.js).

To run unit tests with VSCode debugging enabled, run `ng test --browsers ChromeDebug`, wait for Karma to open up Chrome and run the tests. Leave it running and then in VSCode debug tab, select 'Debug tests in Chrome' from the launch dropdown. VSCode will attach to the Karma process and you can now put in breakpoints and debug your unit tests.

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
Expand Down
8 changes: 7 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ module.exports = function (config) {
singleRun: false,
restartOnFileChange: true,
failOnEmptyTestSuite: false,
codeCoverage: true
codeCoverage: true,
customLaunchers: {
ChromeDebug: {
base: 'Chrome',
flags: ['--remote-debugging-port=9222']
}
}
});
};

0 comments on commit df4bac4

Please sign in to comment.