Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't format node assert errors when there's no 'assert' module #4376

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/jest-circus/src/format_node_assert_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,22 @@ module.exports = (event: Event, state: State) => {
switch (event.name) {
case 'test_failure':
case 'test_success': {
let assert;
try {
// Use indirect require so that Metro Bundler does not attempt to
// bundle `assert`, which does not exist in React Native.
// eslint-disable-next-line no-useless-call
assert = require.call(null, 'assert');
} catch (error) {
// We are running somewhere where `assert` isn't available, like a
// browser or React Native. Since assert isn't available, presumably
// none of the errors we get through this event listener will be
// `AssertionError`s, so we don't need to do anything.
break;
}

event.test.errors = event.test.errors.map(error => {
return error instanceof require('assert').AssertionError
return error instanceof assert.AssertionError
? assertionErrorMessage(error, {expand: state.expand})
: error;
});
Expand Down