Skip to content

Commit

Permalink
fix and improve
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Oct 11, 2022
1 parent a39810a commit 7e73efd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/jest-circus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ const test: Global.It = (() => {
) => void,
timeout?: number,
failing?: boolean,
error?: Error,
asyncError?: Error,
) => {
const asyncError = error || new ErrorWithStack(undefined, testFn);
asyncError = asyncError || new ErrorWithStack(undefined, testFn);

try {
testName = convertDescriptorToString(testName);
Expand Down
1 change: 1 addition & 0 deletions packages/jest-console/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class BufferedConsole extends Console {
if (!(error instanceof AssertionError)) {
throw error;
}
// https://github.com/facebook/jest/pull/13422#issuecomment-1273396392
this._log('assert', error.toString().replace(/:\n\n.*\n/gs, ''));
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/jest-console/src/CustomConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class CustomConsole extends Console {
if (!(error instanceof AssertionError)) {
throw error;
}
// https://github.com/facebook/jest/pull/13422#issuecomment-1273396392
this._logError('assert', error.toString().replace(/:\n\n.*\n/gs, ''));
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/jest-each/src/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ export default function bind<EachCallback extends Global.TestCallback>(
);
} catch (e: any) {
const err = new Error(e.message);
err.stack = error.stack?.replace(/^Error: /s, e.message);
err.name = '';

// @ts-expect-error: CIRCUS
if (typeof global.it !== 'undefined') {
err.stack = error.stack?.replace(/^Error: /s, e.message);
} else {
err.stack = error.stack;
}

return cb(title, () => {
throw err;
Expand Down

0 comments on commit 7e73efd

Please sign in to comment.