Skip to content

Commit

Permalink
chore: apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Oct 27, 2024
1 parent e066550 commit ff61ddc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/support/seeded-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ class TestGenerator<
const tester: MethodTester<TModule[TMethodName]> = {
it(name: string, ...args: Parameters<TModule[TMethodName]>) {
expectVariantNotTested(name);
const extraStackFrames = collectExtraStackFrames(name.length + 7);
const extraStackFrames = collectExtraStackFrames(
/* t. */ `it('${name}', `.length // ...args)
);
vi_it(name, () => callAndVerify(method, args, extraStackFrames));
return tester;
},
Expand All @@ -251,7 +253,9 @@ class TestGenerator<
...args: Parameters<TModule[TMethodName]>
) {
expectVariantNotTested(name);
const extraStackFrames = collectExtraStackFrames(name.length + 7);
const extraStackFrames = collectExtraStackFrames(
/* t. */ `itRepeated('${name}', ${repetitions}, `.length // ...args)
);
vi_it(name, () =>
callAndVerify(method, args, extraStackFrames, repetitions)
);
Expand Down Expand Up @@ -318,7 +322,7 @@ function collectExtraStackFrames(extraOffset: number = 0): () => string[] {
return () =>
stack
.split('\n')
.map((e) => e.replaceAll('\\', '/'))
.map((e) => e.replaceAll('\\', '/')) // Windows to Linux paths
.filter((e) => e.includes('/test/')) // exclude node_modules
.filter((e) => !e.includes('/test/support/')) // exclude this file
.map((e) =>
Expand All @@ -327,10 +331,10 @@ function collectExtraStackFrames(extraOffset: number = 0): () => string[] {
}

/**
* Modifies the error stack to include the given additional stack frames.
* Modifies the error stack to include the given additional stack frames after the last occurrence of this file.
*
* @param error The error to modify.
* @param extraStackFrames The additional stack frames to add after this file.
* @param extraStackFrames The additional stack frames to add.
*/
function patchExtraStackFrames(
error: unknown,
Expand All @@ -339,7 +343,9 @@ function patchExtraStackFrames(
if (error instanceof Error && error.stack != null) {
const stack = error.stack.split('\n');
const index = stack.findLastIndex((e) =>
e.replaceAll('\\', '/').includes('/test/support/')
e
.replaceAll('\\', '/') // Windows to Linux paths
.includes('/test/support/')
);
stack.splice(index + 1, 0, ...extraStackFrames());
error.stack = stack.join('\n');
Expand Down

0 comments on commit ff61ddc

Please # to comment.