Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove message from node assert stack traces
  • Loading branch information
SimenB committed Apr 23, 2018
commit 849ecd93a87385094de4cd7d3c3e8fdd136c9a15
12 changes: 6 additions & 6 deletions integration-tests/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ exports[`not throwing Error objects 5`] = `
10 |


at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/during_tests.test.js:7:1

● Boolean thrown during test
Expand All @@ -159,7 +159,7 @@ exports[`not throwing Error objects 5`] = `
14 | });


at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/during_tests.test.js:11:1

● undefined thrown during test
Expand All @@ -175,7 +175,7 @@ exports[`not throwing Error objects 5`] = `
19 | });


at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/during_tests.test.js:16:1

● Object thrown during test
Expand All @@ -198,7 +198,7 @@ exports[`not throwing Error objects 5`] = `
24 | });


at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/during_tests.test.js:21:1

● Error during test
Expand Down Expand Up @@ -391,7 +391,7 @@ exports[`works with async failures 1`] = `
29 |
30 | setTimeout(done, 10);

at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/async_failures.test.js:27:1

"
Expand Down Expand Up @@ -794,7 +794,7 @@ exports[`works with node assert 1`] = `
69 |


at packages/jest-jasmine2/build/jasmine/Spec.js:79:20
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/node_assertion_error.test.js:66:1

● assert.doesNotThrow
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ test('works with node assert', () => {
const specificErrorMessage = `Message:
Got unwanted exception.
err!
err!
`;

expect(summary).toContain(specificErrorMessage);
Expand All @@ -80,7 +79,6 @@ test('works with node assert', () => {
const specificErrorMessage = `Message:
Got unwanted exception.
Actual message: "err!"
Actual message: "err!"
`;

expect(summary).toContain(specificErrorMessage);
Expand Down
13 changes: 8 additions & 5 deletions packages/jest-jasmine2/src/assert_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ const assertMatcherHint = (operator: ?string, operatorName: string) => {
};

function assertionErrorMessage(error: AssertionError, options: DiffOptions) {
const {expected, actual, message, operator, stack} = error;
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const negator =
typeof operator === 'string' &&
(operator.startsWith('!') || operator.startsWith('not'));
const hasCustomMessage = !error.generatedMessage;
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this replace is what I think needs to land in Jest 22

.replace(/AssertionError(.*)/g, '');

if (operatorName === 'doesNotThrow') {
return (
Expand All @@ -104,7 +107,7 @@ function assertionErrorMessage(error: AssertionError, options: DiffOptions) {
chalk.reset(`Instead, it threw:\n`) +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
stack.replace(/AssertionError(.*)/g, '')
trimmedStack
);
}

Expand All @@ -115,7 +118,7 @@ function assertionErrorMessage(error: AssertionError, options: DiffOptions) {
chalk.reset(`Expected the function to throw an error.\n`) +
chalk.reset(`But it didn't throw anything.`) +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
stack.replace(/AssertionError(.*)/g, '')
trimmedStack
);
}

Expand All @@ -128,7 +131,7 @@ function assertionErrorMessage(error: AssertionError, options: DiffOptions) {
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
(diffString ? `\n\nDifference:\n\n${diffString}` : '') +
stack.replace(/AssertionError(.*)/g, '')
trimmedStack
);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/jest-jasmine2/src/jasmine/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/* @flow */
/* eslint-disable sort-keys */

import {AssertionError} from 'assert';

import ExpectationFailed from '../expectation_failed';

import expectationResultFactory from '../expectation_result_factory';

import assertionErrorMessage from '../assert_support';

export default function Spec(attrs: Object) {
this.resultCallback = attrs.resultCallback || function() {};
this.id = attrs.id;
Expand Down Expand Up @@ -137,8 +141,7 @@ Spec.prototype.onException = function onException(error) {
return;
}

if (error instanceof require('assert').AssertionError) {
const assertionErrorMessage = require('../assert_support').default;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lazy loading of deps anyways

if (error instanceof AssertionError) {
error = assertionErrorMessage(error, {expand: this.expand});
}

Expand Down