Skip to content

Instantly share code, notes, and snippets.

@boneskull
Created June 27, 2016 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boneskull/eef8c05c4227a5829a3fa2ab9cdbebc4 to your computer and use it in GitHub Desktop.
Save boneskull/eef8c05c4227a5829a3fa2ab9cdbebc4 to your computer and use it in GitHub Desktop.
canonical example of babel (es2015) and Mocha with source map support
export default function foo (str = 'bar') {
if (str === 'baz') {
throw new Error('baz is not allowed');
}
return str;
}
import foo from '.';
import {ok} from 'assert';
describe('foo()', () => {
it('should return "baz" (which should fail)', () => {
ok(foo() === 'baz');
});
it('should print a valid stack trace', () => {
foo('baz');
});
});
{
"name": "mocha-sourcemaps",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --require source-map-support --require babel-register index.spec.js"
},
"keywords": [],
"author": "Christopher Hiller <boneskull@boneskull.com> (https://boneskull.com/)",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"mocha": "^2.5.3",
"source-map-support": "^0.4.0"
},
"babel": {
"presets": [
"es2015"
]
}
}
@boneskull
Copy link
Author

Output:

$ npm test

> mocha-sourcemaps@0.0.0 test /Users/boneskull/tmp/mocha-sourcemaps
> mocha --require source-map-support --require babel-register index.spec.js



  foo()
    1) should return "baz" (which should fail)
    2) should print a valid stack trace


  0 passing (215ms)
  2 failing

  1) foo() should return "baz" (which should fail):

      AssertionError: false == true
      + expected - actual

      -false
      +true

      at Context.<anonymous> (index.spec.js:6:5)

  2) foo() should print a valid stack trace:
     Error: baz is not allowed
      at foo (index.js:3:11)
      at Context.<anonymous> (index.spec.js:10:5)

@thmsobrmlr
Copy link

@boneskull Thanks for the example. Here is what I get when using markdown reporter with a passing test: https://gist.github.com/thomas88/6cae8efc5795bd6e60f469d9bf84b692.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment