Skip to content

Commit

Permalink
Adding xit and fit to the test result locations (#6482)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenliebig authored and SimenB committed Oct 17, 2018
1 parent ee9fc73 commit 7a64497
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
37 changes: 32 additions & 5 deletions e2e/__tests__/location_in_results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
});
});
22 changes: 20 additions & 2 deletions e2e/location-in-results/__tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
20 changes: 20 additions & 0 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7a64497

Please sign in to comment.