stack traces report incorrect line numbers using coffee-script test files with mocha, chai
See original GitHub issueNot sure if this is due to an issue with Mocha or Chai, but I believe it isn’t, since running Mocha alone on the test file reports the line number correctly.
package.json
{
"dependencies": {
"chai": "^1.9.1",
"coffee-script": "^1.7",
"mocha": "1.21.3",
"protractor": "^1.0.0"
}
}
source-maps-test.coffee
exports.config =
baseUrl: 'http://localhost'
framework: 'mocha'
rootElement: 'html'
allScriptsTimeout: 15000
specs: [
'source-maps-test.coffee'
]
seleniumServerJar: null
seleniumPort: null
seleniumAddress: null
mochaOpts:
compilers: 'coffee:coffee-script/register'
source-maps-test.coffee
chai = require 'chai'
expect = chai.expect
describe 'when using coffee-script files', ->
it 'reports the correct line number of the error', ->
expect("the line number of this error").to.equal 6 # but it reports 10
output from ‘protractor source-maps-test-config.coffee’
Starting selenium standalone server...
Selenium standalone server started at http://192.168.1.11:57696/wd/hub
1) when using coffee-script files reports the correct line number of the error
0 passing (19ms)
1 failing
1) when using coffee-script files reports the correct line number of the error:
AssertionError: expected 'the line number of this error' to equal 6
at Context.<anonymous> (/Users/grockit/workspace/source-maps-test/source-maps-test.coffee:10:57)
at /Users/grockit/workspace/source-maps-test/node_modules/protractor/node_modules/selenium-webdriver/testing/index.js:131:24
at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/grockit/workspace/source-maps-test/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1539:20)
at webdriver.promise.ControlFlow.runEventLoop_ (/Users/grockit/workspace/source-maps-test/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1404:8)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
at Context.ret (/Users/grockit/workspace/source-maps-test/node_modules/protractor/node_modules/selenium-webdriver/testing/index.js:129:14)
at Test.Runnable.run (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runnable.js:214:15)
at Runner.runTest (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:373:10)
at /Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:451:12
at next (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:298:14)
at /Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:308:7
at next (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:246:23)
at Object._onImmediate (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:275:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
output from ‘mocha --compilers coffee:coffee-script/register source-maps-test.coffee’:
when using coffee-script files
1) reports the correct line number of the error
0 passing (5ms)
1 failing
1) when using coffee-script files reports the correct line number of the error:
AssertionError: expected 'the line number of this error' to equal 6
at Context.<anonymous> (/Users/grockit/workspace/source-maps-test/source-maps-test.coffee:6:48)
at callFn (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runnable.js:247:21)
at Test.Runnable.run (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runnable.js:240:7)
at Runner.runTest (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:373:10)
at /Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:451:12
at next (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:298:14)
at /Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:308:7
at next (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:246:23)
at Object._onImmediate (/Users/grockit/workspace/source-maps-test/node_modules/mocha/lib/runner.js:275:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How to get mocha with chai assert to report file/line number?
It shows a stack trace, but all the line numbers are wrong. Perhaps it has something to do with using coffee-script as the...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
simple, flexible, fun. Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun....
Read more >CoffeeScript
Compile a .coffee script into a .js JavaScript file of the same name. -t, --transpile, Pipe the CoffeeScript compiler's ...
Read more >ljve-source-map-support - npm package - Snyk
Fixes stack traces for files with source maps For more information about how to use ... npm i snyk -g && snyk test...
Read more >Changelog - Node Tap
catch invalid test point IDs when a trailing plan is used; pragmas keys can contain uppercase characters, numbers, - and _; treat tests...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s it really.
npm install coffee-errors --save
, then in our protractor-conf file, we haveThat’s enough to fix line numbers in all test exceptions.
I’m going to close this as infeasible - we don’t want Protractor to duplicate build pipelines, so we won’t be including custom configurations for different compilers. Solutions like
coffee-errors
are the right way to go.