diff --git a/src/utils/requestUtils.ts b/src/utils/requestUtils.ts index d69275c3..baa4b501 100644 --- a/src/utils/requestUtils.ts +++ b/src/utils/requestUtils.ts @@ -5,7 +5,7 @@ import { log } from '../io'; import * as models from '../models'; import { toBoolean, toNumber } from './convertUtils'; import { parseMimeType } from './mimeTypeUtils'; -import { isString, toMultiLineString } from './stringUtils'; +import { isString, toMultiLineArray, toMultiLineString } from './stringUtils'; export function isHttpRequestMethod(method: string | undefined): method is models.HttpMethod { if (method) { @@ -274,6 +274,15 @@ export function requestLoggerFactory( } else if ([models.TestResultStatus.ERROR, models.TestResultStatus.FAILED].includes(testResult.status)) { const errorMessage = testResult.error ? ` (${testResult.error?.displayMessage})` : ''; message = chalk`{red ${models.testSymbols.error} ${testResult.message || 'Test failed'}${errorMessage}}`; + + if ( + !options?.useShort && + testResult.status === models.TestResultStatus.ERROR && + testResult.error?.error.stack + ) { + const linesOfStack = toMultiLineArray(testResult.error.error.stack).slice(0, 3); + message = toMultiLineString([message, ...linesOfStack]); + } } log(message); } diff --git a/src/utils/testUtils.ts b/src/utils/testUtils.ts index 745e041a..96ddc47b 100644 --- a/src/utils/testUtils.ts +++ b/src/utils/testUtils.ts @@ -31,7 +31,7 @@ export function testFactoryAsync( try { await testMethod(testResult); } catch (err) { - setErrorInTestResult(testResult, err); + setErrorInTestResult(testResult, err, TestResultStatus.ERROR); if (options.ignoreErrorFile && testResult.error?.errorType) { testResult.error.displayMessage = `${testResult.error.errorType}: ${testResult.error.message}`; } @@ -41,8 +41,8 @@ export function testFactoryAsync( }; } -function setErrorInTestResult(testResult: TestResult, err: unknown) { - testResult.status = TestResultStatus.FAILED; +function setErrorInTestResult(testResult: TestResult, err: unknown, status = TestResultStatus.FAILED) { + testResult.status = status; if (isError(err)) { testResult.error = parseError(err); } else {