Skip to content

Cannot debug tests in Karma for projects generated with version CLI 6.1 or 6.2 - no source maps? #12282

Closed
@AmadejBukorovic

Description

@AmadejBukorovic

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node: v8.11.4
npm: 5.5.1
ng: 6.1.5 and 6.2.2
Chrome 69.0.3497.92
Windows 10 Version 1803 (OS Build 17134.285)

Repro steps

ng new TestKarmaDebugger
cd TestKarmaDebugger
ng test

Desired functionality

I'd like to be able to debug Jasmine tests inside the Karma runner (via the browser) - in previous versions of Angular CLI, I could click on the DEBUG button in the upper right corner of the initial Karma page, which navigated to Karma's debug.html, that included the source maps from the webpack source, enabling me to debug tests inside the browser.

On the tested 6.x versions, this isn't the case. It seems there are no source maps included when in debug mode? I've tested this with the freshly generated projects and didn't include any other NPM modules. So I'm talking about the default state of a project generated with Angular CLI.

Mention any other details that might be useful

It seems that adding the sourceMap property with the value of true, to the "test" architect node in angular.json, resolves this issue to some extent.

Example snippet from angular.json:

"test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "sourceMap": true
          }
        },

From my observations, it solves the behavior for projects generated with Angular CLI 6.1.x, as I can find the source files under the webpack source map in Chrome, while the situation on a project generated with Angular CLI 6.2.2 is different. When the debug page of Karma is loaded, the source files are under the 'localhost:9876' source map and there is no webpack source map included?

image

I'm also unable to predict if such a configuration change has any repercussions on running tests when not debugging or when generation code coverage reports, so I'd like some feedback if this is the recommended way of solving the issue?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions