Skip to content
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

Jasmine html web page reports wrong line numbers #1598

Closed
DamienCassou opened this issue Sep 6, 2018 · 6 comments
Closed

Jasmine html web page reports wrong line numbers #1598

DamienCassou opened this issue Sep 6, 2018 · 6 comments
Labels

Comments

@DamienCassou
Copy link
Contributor

Our project has a tests.html webpage which loads jasmine.js, jasmine-html.js, boot.js and our test suite. When a test fails, I get a stack trace with columns, line numbers and filenames. This is fine except that the line numbers are shifted: there is a difference between the line number as reported by Jasmine and the correct line number in the file.

My project uses webpack and cheap-eval-source-map.

Expected Behavior

Jasmine should report:

TypeError: Cannot read property 'getPeriodType' of undefined
    at <Jasmine>
    at SomeModel._someMethod (webpack-internal:///./js/SomeModel.js:106:18)

Current Behavior

Jasmine instead reports:

TypeError: Cannot read property 'getPeriodType' of undefined
    at <Jasmine>
    at SomeModel._someMethod (webpack-internal:///./js/SomeModel.js:112:18)

Note that line number (112) is not the same as expected one (106).

Your Environment

  • Version used: 3.2.0
  • Environment name and version: Chromium 68
  • Operating System and version: Linux desktop
  • Link to your project: private
  • Technology stack:
    • webpack: 4.3.0
@DamienCassou
Copy link
Contributor Author

I've just tried launching the same test suite with karma and I got the wrong line numbers as well.

@slackersoft
Copy link
Member

Jasmine doesn't currently have a good story around using sourcemaps for your tests (see #491), so it's possible that this is causing some of the confusion in the stack traces that Jasmine prints/reports.

I would still like to get a better solution for this, but I'm not sure of the right approach at this point in time.

Hope this helps. Thanks for using Jasmine!

@DamienCassou
Copy link
Contributor Author

When Jasmine was displaying the stacktrace in terms of minified files, I was happily using sourcemapped-stacktrace. Then we updated Jasmine and got rid of sourcemapped-stacktrace because Jasmine did the job of looking into the source maps. Unfortunately, the lines numbers became slightly wrong. What about letting sourcemapped-stacktrace do the work for Jasmine?

@slackersoft
Copy link
Member

Jasmine just asks the thrown error for its stack (see https://github.com/jasmine/jasmine/blob/master/src/core/StackTrace.js), and doesn't currently do anything to try to resolve sourcemapped files. My best guess is that another dependency also got updated that changed the way sourcemaps interact with stacktraces in your codebase.

Hope this helps.

slackersoft pushed a commit that referenced this issue May 15, 2019
DamienCassou added a commit to DamienCassou/jasmine-line-number-bug that referenced this issue Aug 19, 2019
@DamienCassou
Copy link
Contributor Author

DamienCassou commented Aug 19, 2019

I've just created the smallest project reproducing this issue.

How to reproduce:

  1. clone the git project or create the files below
  2. run npx webpack --config webpack.jasmine.config.js inside the project directory
  3. open the tests.html within a web browser (using file://)
  4. Jasmine correctly says "Expected 2 to equal 3"
  • Expected: Jasmine shows a stacktrace indicating that the problem is on line 8 (the line containing expect)
  • Actual: Jasmine says that the problem is on line 10 (which only contains });.

Note: if you remove the useless import line at the beginning oftests.js, the line number becomes right.

package.json

All the dependencies are the latest as of today:

{
  "name": "jasmine-line-number-bug",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "jasmine-core": "^3.4.0",
    "webpack": "^4.39.2",
    "webpack-cli": "^3.3.7"
  }
}

tests.html

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Client Tests</title>
    <link rel="stylesheet" type="text/css" href="./node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
    <script type="text/javascript" src="./node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
    <script type="text/javascript" src="./node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
    <script type="text/javascript" src="./node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>

    <script src="./build/jasmine.latest.js"></script>
  </head>
  <body>
  </body>
</html>

tests.js

import {add} from './util';

describe('line numbers', () => {
	it('should be the same', () => {
		let expected = 3;
		let actual = 1+1;

		expect(actual).toEqual(expected);
	});
});

util.js

export function add(a,b) {
	return a+b;
}

webpack.jasmine.config.js

const path = require('path');

let config = {
	entry: './tests.js',
	mode: 'development',
	output: {
		filename: 'jasmine.latest.js',
		path: path.resolve(__dirname, 'build')
	}
};

module.exports = config;

@sgravrock
Copy link
Member

I'm going to close this in favor of #491, which I believe it's a duplicate of. Thanks again for the repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants