-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: `JsonReporter` currently serialises `Error` instances using ```js event = Object.assign(event, { message: event.error.message, stack: event.error.stack, }); ``` This places `message` and `stack` as top-level properties, alongside `error` itself, which serialises to `{}`. Presumably the intention was to nest them under `error: {}`? This diff nests the properties under `error`, deprecates the old "flat" versions (removing them will be semver breaking), and also usefully serialise the newer standard `AggregateError.prototype.errors` and `Error.prototype.cause`, where applicable. ``` - **[Feature]** JsonReporter: Print `message`, `stack`, `cause`, and `errors` (where present) under `error` when a reportable event has an `error` property. - **[Deprecation]** JsonReporter: Deprecate printing `message` and `stack` as top-level properties when a reportable event has an `error` property. ``` Reviewed By: GijsWeterings Differential Revision: D59805164 fbshipit-source-id: 84745a788a11623016dd322a07971b56b29e8bb7
- Loading branch information
1 parent
f228acc
commit 95a6063
Showing
2 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import JsonReporter from '../JsonReporter'; | ||
|
||
describe('JsonReporter', () => { | ||
test('prints deeply nested errors', () => { | ||
const mockStream = { | ||
write: jest.fn(), | ||
}; | ||
const reporter = new JsonReporter<{type: 'some_failure', error: Error}>( | ||
mockStream as $FlowFixMe, | ||
); | ||
reporter.update({ | ||
type: 'some_failure', | ||
error: new AggregateError( | ||
[ | ||
new Error('test error'), | ||
new Error('test error with a cause', {cause: new Error('cause')}), | ||
], | ||
'test aggregate error', | ||
), | ||
}); | ||
expect(mockStream.write).toHaveBeenCalled(); | ||
const deserialized = JSON.parse(mockStream.write.mock.calls[0][0]); | ||
expect(deserialized.error).toEqual({ | ||
message: 'test aggregate error', | ||
stack: expect.stringContaining('JsonReporter-test'), | ||
errors: [ | ||
{ | ||
message: 'test error', | ||
stack: expect.stringContaining('JsonReporter-test'), | ||
}, | ||
{ | ||
message: 'test error with a cause', | ||
stack: expect.stringContaining('JsonReporter-test'), | ||
cause: { | ||
message: 'cause', | ||
stack: expect.stringContaining('JsonReporter-test'), | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |