Skip to content

Commit

Permalink
Fix StitchError stack traces in node
Browse files Browse the repository at this point in the history
* Add `babel-plugin-transform-builtin-extend`
* Subclassing builtin types needs special treatment by babel
  * Without this plugin, in a node environment, a subclass of Error does not actually behave like a true subclass, which manifests itself via a missing stacktrace when a StitchError is thrown

More details [here](babel/babel#3083)
  • Loading branch information
UnicodeSnowman committed Nov 14, 2017
1 parent 4841bf0 commit 98a85a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"node": "6"
},
"useBuiltins": "usage",
}]
}],
],
"plugins": [
"transform-async-to-generator",
"babel-plugin-add-module-exports",
"version-transform"
"version-transform",
["babel-plugin-transform-builtin-extend", { globals: ["Error"] }]
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"babel-loader": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-preset-env": "^1.6.1",
"conventional-changelog-cli": "^1.3.1",
"eslint": "^3.19.0",
Expand Down
9 changes: 9 additions & 0 deletions test/errors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StitchError } from '../src/errors';

describe('StitchError', () => {
it('reports a full stack trace', () => {
const err = new StitchError("Oh noes!");
expect(err.toString()).toEqual('StitchError: Oh noes!');
expect(err.stack.length).toBeGreaterThan(err.toString().length);
});
});

0 comments on commit 98a85a9

Please sign in to comment.