Skip to content

Commit

Permalink
wip: modify wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
apexskier committed Aug 16, 2020
1 parent 03c899f commit 78595d1
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {SnapshotStateType} from 'jest-snapshot';
import type {RuntimeType as Runtime} from 'jest-runtime';

import {getCallsite} from '@jest/source-map';
import {unlink} from 'graceful-fs';
import installEach from './each';
import {installErrorOnPrivate} from './errorOnPrivate';
import JasmineReporter from './reporter';
Expand Down Expand Up @@ -48,10 +47,14 @@ async function jasmine2(
// TODO: Remove config option if V8 exposes some way of getting location of caller
// in a future version
if (config.testLocationInResults === true) {
function wrapIt(original: (...args: Array<unknown>) => unknown) {
return (...args: Array<unknown>) => {
function wrapIt<T extends Global.ItBase>(original: T): T {
const wrapped = (
testName: Global.TestName,
fn: Global.TestFn,
timeout?: number,
) => {
let stack = getCallsite(1, runtime.getSourceMaps());
const it = original(...args);
const it = original(testName, fn, timeout);

if (stack.getFileName()?.includes('/jest-each/')) {
stack = getCallsite(4, runtime.getSourceMaps());
Expand All @@ -61,19 +64,12 @@ async function jasmine2(

return it;
};
return (wrapped as any) as T;
}

environment.global.it = wrapIt(
environment.global.it,
) as Global.Global['it'];

environment.global.it = wrapIt(
environment.global.xit,
) as Global.Global['xit'];

environment.global.fit = wrapIt(
environment.global.fit,
) as Global.Global['fit'];
environment.global.it = wrapIt(environment.global.it);
environment.global.xit = wrapIt(environment.global.xit);
environment.global.fit = wrapIt(environment.global.fit);
}

jasmineAsyncInstall(globalConfig, environment.global);
Expand Down

0 comments on commit 78595d1

Please sign in to comment.