Skip to content

@angular/cli upgrade breaks karma/jasmine sourcemap reporting #14457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mbenna opened this issue May 17, 2019 · 2 comments · Fixed by #14466
Closed

@angular/cli upgrade breaks karma/jasmine sourcemap reporting #14457

mbenna opened this issue May 17, 2019 · 2 comments · Fixed by #14466

Comments

@mbenna
Copy link

mbenna commented May 17, 2019

🐞 Bug report

Command (mark with an x)

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

Is this a regression?

Yes. Sourcemaps in karma/jasmine worked fine up to and including@angular/cli 8.0.0.beta.9, but from beta.10 to current (rc.4 today) sourcemaps no longer work.

Description

Example working output from beta.9:

Expected true to be falsy.
  at UserContext.<anonymous> (src/app/app.component.spec.ts:32:18)

Example broken output from beta.10+:

Error: Expected true to be falsy.
  at <Jasmine>
  at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/main.js:304:22)
  at ZoneDelegate.invoke (http://localhost:9877/_karma_webpack_/polyfills.js:3325:26)
  at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhos...

🔬 Minimal Reproduction

  • Follow https://angular.io/guide/quickstart and create a new app.
  • ng test and ensure test passes.
  • add to app.component.spec.ts:
    it('should fail', () => {
      expect(true).toBeFalsy();
    });
    
  • run ng test again and note you get a line number such as at UserContext.<anonymous> (src/app/app.component.spec.ts:32:18)
  • ng update --next --all --force to update to something more recent than 8.0.0.beta.10
  • repeat ng test and note line numbers no longer help you find your spec in app.component.ts. Instead you see something like this:
    Error: Expected true to be falsy.
      at <Jasmine>
      at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/main.js:304:22)
      at ZoneDelegate.invoke (http://localhost:9877/_karma_webpack_/polyfills.js:3325:26)
      at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke 
    (http://localhos...
    

🔥 Exception or Error

n/a

🌍 Your Environment

ng version:

Angular CLI: 8.0.0-rc.4
Node: 12.1.0
OS: win32 x64
Angular: 8.0.0-rc.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0-rc.4
@angular-devkit/build-angular     0.800.0-rc.4
@angular-devkit/build-optimizer   0.800.0-rc.4
@angular-devkit/build-webpack     0.800.0-rc.4
@angular-devkit/core              8.0.0-rc.4
@angular-devkit/schematics        8.0.0-rc.4
@ngtools/webpack                  8.0.0-rc.4
@schematics/angular               8.0.0-rc.4
@schematics/update                0.800.0-rc.4
rxjs                              6.5.2
typescript                        3.5.0-rc
webpack                           4.30.0

Anything else relevant?

Not that I know of.

@mbenna
Copy link
Author

mbenna commented May 18, 2019

fwiw, I also added this to one of my spec files to help catch the problem during my test suite rather than manually noticing it has broken:

	it('source maps should work in karma / jarmine', () => {
		const err = new Error('spec')
		let shouldFail = false
		shouldFail = shouldFail || / firefox\//i.test(navigator.userAgent) // doesn't work in firefox
		shouldFail = shouldFail || / edge\//i.test(navigator.userAgent) // doesn't work in edge
		// console.log(`navigator.userAgent = ${navigator.userAgent}`)
		// Edge: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"
		if (err.stack.match(/\/src\/app\/app.component.spec.ts:3[0-9]:[0-9]+/)) {
			if (shouldFail) {
				fail(`Sweet! Source maps are now working in this browser!`)
			}
		} else {
			if (!shouldFail) {
				fail(`source maps don't seem to be working! Probably a recent node_module upgrade broke them.`)
			}
		}
		// console.log(`stack = ${err.stack}`)
		// // It should look something like this:
		// stack = Error: spec
		// at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/webpack:/src/app/app.component.spec.ts:44:15)
		// at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)
	})

@alan-agius4 alan-agius4 self-assigned this May 19, 2019
mgechev pushed a commit that referenced this issue May 21, 2019
…rma webpack plugin

`sourceMap` option can be either a boolean or an object,we need to normalize it before trying to get the `script` value.

Fixes #14457
mgechev pushed a commit that referenced this issue May 21, 2019
…rma webpack plugin

`sourceMap` option can be either a boolean or an object,we need to normalize it before trying to get the `script` value.

Fixes #14457
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.