Skip to content

Commit

Permalink
Deduplicate Jasmine global test location wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
apexskier committed Aug 16, 2020
1 parent 6cdff68 commit 85fe942
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,26 @@ 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) {
const originalIt = environment.global.it;
environment.global.it = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const it = originalIt(...args);

// @ts-expect-error
it.result.__callsite = stack;

return it;
}) as Global.Global['it'];

const originalXit = environment.global.xit;
environment.global.xit = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const xit = originalXit(...args);

// @ts-expect-error
xit.result.__callsite = stack;

return xit;
}) as Global.Global['xit'];

const originalFit = environment.global.fit;
environment.global.fit = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const fit = originalFit(...args);

// @ts-expect-error
fit.result.__callsite = stack;
function wrapIt<T extends Global.ItBase>(original: T): T {
const wrapped = (
testName: Global.TestName,
fn: Global.TestFn,
timeout?: number,
) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const it = original(testName, fn, timeout);

// @ts-expect-error
it.result.__callsite = stack;

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

return 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 85fe942

Please sign in to comment.