diff --git a/packages/common/.babelrc b/packages/common/.babelrc index 207f0fc65..c95368205 100644 --- a/packages/common/.babelrc +++ b/packages/common/.babelrc @@ -7,6 +7,9 @@ "transform-regenerator", "transform-object-rest-spread", "transform-async-to-generator", - "transform-flow-strip-types" + "transform-flow-strip-types", + ["babel-plugin-transform-builtin-extend", { + "globals": ["Error", "Array"] + }] ] } diff --git a/packages/common/package.json b/packages/common/package.json index 1c905c961..c3fb007fd 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -45,6 +45,7 @@ "babel-loader": "^6.2.7", "babel-plugin-syntax-async-functions": "^6.13.0", "babel-plugin-transform-async-to-generator": "^6.16.0", + "babel-plugin-transform-builtin-extend": "^1.1.0", "babel-plugin-transform-flow-strip-types": "^6.21.0", "babel-plugin-transform-object-rest-spread": "^6.16.0", "babel-plugin-transform-regenerator": "^6.16.1", diff --git a/packages/common/src/errors.js b/packages/common/src/errors.js index 3cbc5e64c..215ea6a81 100644 --- a/packages/common/src/errors.js +++ b/packages/common/src/errors.js @@ -9,6 +9,7 @@ export class AccountsError extends Error { epochTime: number; constructor(message: string, loginInfo?: PasswordLoginUserType, errorCode?: string | number) { + console.log(message); super(message); this.epochTime = Date.now(); diff --git a/packages/common/src/errors.spec.js b/packages/common/src/errors.spec.js index 127e0b0c9..64cd3cc11 100644 --- a/packages/common/src/errors.spec.js +++ b/packages/common/src/errors.spec.js @@ -26,26 +26,21 @@ describe('AccountsError class', () => { } }); + it('should be able to serialize into a string', () => { + try { + throws(); + } catch (e) { + expect(e.serialize()).toBe( + // eslint-disable-next-line prefer-template + '{"message":"Validation Error",' + + '"loginInfo":{"username":"user"},' + + '"errorCode":"ACCOUNTS:1",' + + '"epochTime":' + e.epochTime + '}', + ); + } + }); - // NB: For some reason it seems jest have different Error class - // it retain fields but our tests fail - // it('should be able to serialize into a string', () => { - // try { - // throws(); - // } catch (e) { - // expect(e.serialize()).toBe( - // '{"message": "Validation Error", ' + - // '"loginInfo": { "username": "user" }, ' + - // '"errorCode": "ACCOUNTS:1" }' - // ); - // } - // }); - // - // it('should be easily distinguished from other errors', () => { - // try { - // throws(); - // } catch (e) { - // expect(e instanceof AccountsError).toBeTruthy(); - // } - // }); + it('should be easily distinguished from other errors', () => { + expect(throws).toThrowError(AccountsError); + }); });