From 7b9a72d6294d07674be9d8a9a23fd513843d7512 Mon Sep 17 00:00:00 2001 From: Cameron Little Date: Sun, 16 Aug 2020 12:23:59 +0200 Subject: [PATCH] Hacky fix for each test location with jest-circus --- e2e/__tests__/locationInResults.test.ts | 8 ++++---- packages/jest-circus/src/utils.ts | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/e2e/__tests__/locationInResults.test.ts b/e2e/__tests__/locationInResults.test.ts index 39e2b0dfbe36..25808059c29c 100644 --- a/e2e/__tests__/locationInResults.test.ts +++ b/e2e/__tests__/locationInResults.test.ts @@ -45,12 +45,12 @@ it('adds correct location info when provided with flag', () => { }); expect(assertions[3].location).toEqual({ - column: 22, + column: isJestCircusRun() ? 1 : 22, line: 24, }); expect(assertions[4].location).toEqual({ - column: 22, + column: isJestCircusRun() ? 1 : 22, line: 24, }); @@ -72,12 +72,12 @@ it('adds correct location info when provided with flag', () => { }); expect(assertions[8].location).toEqual({ - column: isJestCircusRun() ? 25 : 24, + column: isJestCircusRun() ? 3 : 24, line: 41, }); expect(assertions[9].location).toEqual({ - column: isJestCircusRun() ? 25 : 24, + column: isJestCircusRun() ? 3 : 24, line: 41, }); }); diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index 82b4b78e52d4..ea32144d32be 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -300,7 +300,11 @@ export const makeSingleTestResult = ( let location = null; if (includeTestLocationInResult) { const stackLine = test.asyncError.stack.split('\n')[1]; - const parsedLine = stackUtils.parseLine(stackLine); + let parsedLine = stackUtils.parseLine(stackLine); + if (parsedLine?.file?.includes('/jest-each/')) { + const stackLine = test.asyncError.stack.split('\n')[4]; + parsedLine = stackUtils.parseLine(stackLine); + } if ( parsedLine && typeof parsedLine.column === 'number' &&