Skip to content

Commit

Permalink
fix(vite-plugin-angular): prevent context loss for "each" describe bl… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gultyayev authored Jul 2, 2024
1 parent 623d711 commit 595a6b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
37 changes: 23 additions & 14 deletions packages/vite-plugin-angular/setup-vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,25 @@ function fixtureVitestSerializer(fixture: any) {
/**
* bind describe method to wrap describe.each function
*/
const bindDescribe = (originalVitestFn: {
apply: (
arg0: any,
arg1: any[]
) => {
(): any;
new (): any;
apply: { (arg0: any, arg1: any[]): any; new (): any };
};
}) =>
const bindDescribe = (
self: any,
originalVitestFn: {
apply: (
arg0: any,
arg1: any[]
) => {
(): any;
new (): any;
apply: { (arg0: any, arg1: any[]): any; new (): any };
};
}
) =>
function (...eachArgs: any) {
return function (...args: any[]) {
args[1] = wrapDescribeInZone(args[1]);

// @ts-ignore
return originalVitestFn.apply(this, eachArgs).apply(this, args);
return originalVitestFn.apply(self, eachArgs).apply(self, args);
};
};

Expand Down Expand Up @@ -258,10 +261,16 @@ const bindTest = (

return originalvitestFn.apply(this, args);
};
env[methodName].each = bindDescribe(originalvitestFn.each);
env[methodName].each = bindDescribe(originalvitestFn, originalvitestFn.each);
if (methodName === 'describe') {
env[methodName].only = bindDescribe(originalvitestFn.only);
env[methodName].skip = bindDescribe(originalvitestFn.skip);
env[methodName].only = bindDescribe(
originalvitestFn,
originalvitestFn.only
);
env[methodName].skip = bindDescribe(
originalvitestFn,
originalvitestFn.skip
);
}
});

Expand Down
37 changes: 23 additions & 14 deletions packages/vitest-angular/setup-zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,25 @@ function fixtureVitestSerializer(fixture: any) {
/**
* bind describe method to wrap describe.each function
*/
const bindDescribe = (originalVitestFn: {
apply: (
arg0: any,
arg1: any[]
) => {
(): any;
new (): any;
apply: { (arg0: any, arg1: any[]): any; new (): any };
};
}) =>
const bindDescribe = (
self: any,
originalVitestFn: {
apply: (
arg0: any,
arg1: any[]
) => {
(): any;
new (): any;
apply: { (arg0: any, arg1: any[]): any; new (): any };
};
}
) =>
function (...eachArgs: any) {
return function (...args: any[]) {
args[1] = wrapDescribeInZone(args[1]);

// @ts-ignore
return originalVitestFn.apply(this, eachArgs).apply(this, args);
return originalVitestFn.apply(self, eachArgs).apply(self, args);
};
};

Expand Down Expand Up @@ -258,10 +261,16 @@ const bindTest = (

return originalvitestFn.apply(this, args);
};
env[methodName].each = bindDescribe(originalvitestFn.each);
env[methodName].each = bindDescribe(originalvitestFn, originalvitestFn.each);
if (methodName === 'describe') {
env[methodName].only = bindDescribe(originalvitestFn.only);
env[methodName].skip = bindDescribe(originalvitestFn.skip);
env[methodName].only = bindDescribe(
originalvitestFn,
originalvitestFn.only
);
env[methodName].skip = bindDescribe(
originalvitestFn,
originalvitestFn.skip
);
}
});

Expand Down

0 comments on commit 595a6b3

Please sign in to comment.