From 7a64497a2e91cf6d271e2397c8669ea4a6f8badb Mon Sep 17 00:00:00 2001 From: Sven Liebig Date: Wed, 17 Oct 2018 07:52:48 +0200 Subject: [PATCH] Adding xit and fit to the test result locations (#6482) --- CHANGELOG.md | 1 + e2e/__tests__/location_in_results.test.js | 37 ++++++++++++++++++++--- e2e/location-in-results/__tests__/test.js | 22 ++++++++++++-- packages/jest-jasmine2/src/index.js | 20 ++++++++++++ 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 494d0b5f05b3..bafd4801eef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - `[jest-jasmine2]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372)) - `[jest-jasmine2]` Pending calls inside async tests are reported as pending not failed ([#6782](https://github.com/facebook/jest/pull/6782)) - `[jest-circus]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372)) +- `[jest-jasmine2]` Add missing testLocationResults for `xit` and `fit`([#6482](https://github.com/facebook/jest/pull/6482)) - `[jest-cli]` Fix unhandled error when a bad revision is provided to `changedSince` ([#7115](https://github.com/facebook/jest/pull/7115)) - `[jest-config]` Moved dynamically assigned `cwd` from `jest-cli` to default configuration in `jest-config` ([#7146](https://github.com/facebook/jest/pull/7146)) - `[jest-config]` Fix `getMaxWorkers` on termux ([#7154](https://github.com/facebook/jest/pull/7154)) diff --git a/e2e/__tests__/location_in_results.test.js b/e2e/__tests__/location_in_results.test.js index 4413863b98b1..653451ad3f34 100644 --- a/e2e/__tests__/location_in_results.test.js +++ b/e2e/__tests__/location_in_results.test.js @@ -16,9 +16,13 @@ it('defaults to null for location', () => { const assertions = result.testResults[0].assertionResults; expect(result.success).toBe(true); - expect(result.numTotalTests).toBe(2); + expect(result.numTotalTests).toBe(6); expect(assertions[0].location).toBeNull(); expect(assertions[1].location).toBeNull(); + expect(assertions[2].location).toBeNull(); + expect(assertions[3].location).toBeNull(); + expect(assertions[4].location).toBeNull(); + expect(assertions[5].location).toBeNull(); }); it('adds correct location info when provided with flag', () => { @@ -28,13 +32,36 @@ it('adds correct location info when provided with flag', () => { const assertions = result.testResults[0].assertionResults; expect(result.success).toBe(true); - expect(result.numTotalTests).toBe(2); - expect(assertions[0].location).toEqual({column: 1, line: 10}); + expect(result.numTotalTests).toBe(6); + expect(assertions[0].location).toEqual({ + column: 1, + line: 12, + }); + + expect(assertions[1].location).toEqual({ + column: 1, + line: 16, + }); + + expect(assertions[2].location).toEqual({ + column: 1, + line: 20, + }); // Technically the column should be 3, but callsites is not correct. // jest-circus uses stack-utils + asyncErrors which resolves this. - expect(assertions[1].location).toEqual({ + expect(assertions[3].location).toEqual({ + column: isJestCircusRun() ? 3 : 2, + line: 25, + }); + + expect(assertions[4].location).toEqual({ + column: isJestCircusRun() ? 3 : 2, + line: 29, + }); + + expect(assertions[5].location).toEqual({ column: isJestCircusRun() ? 3 : 2, - line: 15, + line: 33, }); }); diff --git a/e2e/location-in-results/__tests__/test.js b/e2e/location-in-results/__tests__/test.js index 810c033d474a..1d412cc9b883 100644 --- a/e2e/location-in-results/__tests__/test.js +++ b/e2e/location-in-results/__tests__/test.js @@ -7,12 +7,30 @@ // This file is missing 'use strict' to force babel into doing something // as we have `transform-strict-mode` -it('no ancestors', () => { +/* eslint jest/no-focused-tests: 0 */ + +it('it no ancestors', () => { + expect(true).toBeTruthy(); +}); + +xit('xit no ancestors', () => { + expect(true).toBeTruthy(); +}); + +fit('fit no ancestors', () => { expect(true).toBeTruthy(); }); describe('nested', () => { - it('also works', () => { + it('it nested', () => { + expect(true).toBeTruthy(); + }); + + xit('xit nested', () => { + expect(true).toBeTruthy(); + }); + + fit('fit nested', () => { expect(true).toBeTruthy(); }); }); diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index b93eab79d10c..a21f98a376cb 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -54,6 +54,26 @@ async function jasmine2( return it; }; + + const originalXit = environment.global.xit; + environment.global.xit = (...args) => { + const stack = getCallsite(1, runtime.getSourceMaps()); + const xit = originalXit(...args); + + xit.result.__callsite = stack; + + return xit; + }; + + const originalFit = environment.global.fit; + environment.global.fit = (...args) => { + const stack = getCallsite(1, runtime.getSourceMaps()); + const fit = originalFit(...args); + + fit.result.__callsite = stack; + + return fit; + }; } jasmineAsyncInstall(environment.global);