don't wrap in error

This commit is contained in:
Simon Knott 2024-08-23 13:01:30 +02:00
parent e4b1dc95dc
commit 314a67fa73
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
3 changed files with 7 additions and 8 deletions

View file

@ -289,8 +289,7 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
const step = testInfo._addStep(stepInfo); const step = testInfo._addStep(stepInfo);
const reportStepError = (unknownError: unknown) => { const reportStepError = (jestError: Error | unknown) => {
const jestError = unknownError instanceof Error ? unknownError : new Error(String(unknownError));
const error = isExpectError(jestError) ? new ExpectError(jestError, customMessage, stackFrames) : jestError; const error = isExpectError(jestError) ? new ExpectError(jestError, customMessage, stackFrames) : jestError;
step.complete({ error }); step.complete({ error });
if (this._info.isSoft) if (this._info.isSoft)

View file

@ -30,7 +30,7 @@ import type { Attachment } from './testTracing';
import type { StackFrame } from '@protocol/channels'; import type { StackFrame } from '@protocol/channels';
export interface TestStepInternal { export interface TestStepInternal {
complete(result: { error?: Error, attachments?: Attachment[] }): void; complete(result: { error?: Error | unknown, attachments?: Attachment[] }): void;
stepId: string; stepId: string;
title: string; title: string;
category: 'hook' | 'fixture' | 'test.step' | 'expect' | 'attach' | string; category: 'hook' | 'fixture' | 'test.step' | 'expect' | 'attach' | string;
@ -267,7 +267,7 @@ export class TestInfoImpl implements TestInfo {
step.endWallTime = Date.now(); step.endWallTime = Date.now();
if (result.error) { if (result.error) {
if (!(result.error as any)[stepSymbol]) if (typeof result.error === 'object' && !(result.error as any)?.[stepSymbol])
(result.error as any)[stepSymbol] = step; (result.error as any)[stepSymbol] = step;
const error = serializeError(result.error); const error = serializeError(result.error);
if (data.boxedStack) if (data.boxedStack)
@ -324,13 +324,13 @@ export class TestInfoImpl implements TestInfo {
this.status = 'interrupted'; this.status = 'interrupted';
} }
_failWithError(error: Error) { _failWithError(error: Error | unknown) {
if (this.status === 'passed' || this.status === 'skipped') if (this.status === 'passed' || this.status === 'skipped')
this.status = error instanceof TimeoutManagerError ? 'timedOut' : 'failed'; this.status = error instanceof TimeoutManagerError ? 'timedOut' : 'failed';
const serialized = serializeError(error); const serialized = serializeError(error);
const step = (error as any)[stepSymbol] as TestStepInternal | undefined; const step: TestStepInternal | undefined = typeof error === 'object' ? (error as any)?.[stepSymbol] : undefined;
if (step && step.boxedStack) if (step && step.boxedStack)
serialized.stack = `${error.name}: ${error.message}\n${stringifyStackFrames(step.boxedStack).join('\n')}`; serialized.stack = `${(error as Error).name}: ${(error as Error).message}\n${stringifyStackFrames(step.boxedStack).join('\n')}`;
this.errors.push(serialized); this.errors.push(serialized);
this._tracing.appendForError(serialized); this._tracing.appendForError(serialized);
} }

View file

@ -243,5 +243,5 @@ test('should propagate promise rejections', { annotation: { type: 'issue', descr
` `
}); });
expect(result.output).toContain('Error: some error'); expect(result.output).toContain('some error');
}); });