Skip to content

Commit

Permalink
Remove repeatTest util, use "@klaster_1/testcafe-repeat-test" package…
Browse files Browse the repository at this point in the history
….instead.
  • Loading branch information
Klaster1 committed Jul 14, 2024
1 parent a662fc3 commit 9940bdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 54 deletions.
54 changes: 0 additions & 54 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,3 @@ export const restoreDate = () =>
document.body.removeChild(iframe);
Date.now = originalDateNow;
});

export const repeatTest = (times, options?: { rename?: boolean }) => {
const testDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'test');
const tests: TestFn[] = [];
Object.defineProperty(globalThis, 'test', {
get() {
Object.defineProperty(globalThis, 'test', testDescriptor);

const makeTest = testDescriptor.get as any;
const testInstance = makeTest();
function proxyInstance(name: string, fn: any) {
for (let i = 1; i <= times; i++) {
const instance = makeTest();
const testName = options?.rename ?? true ? `${name} ${i}` : name;
tests.push(instance.only(testName, fn));
}
testInstance(name, fn);
return proxyInstance;
}
const skip = new Set(['prototype', 'length', 'name']);
for (const [property, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(testInstance))) {
if (skip.has(property)) continue;
if (descriptor.get === undefined) {
Object.defineProperty(proxyInstance, property, {
get() {
return testInstance[property];
},
});
} else {
Object.defineProperty(proxyInstance, property, {
get: () => {
const method = descriptor.get();
if (method.name !== 'apiOrigin') {
return (...args) => {
method(...args);
for (const test of tests) {
test[property](...args);
}
return proxyInstance;
};
} else {
for (const test of tests) {
test[property];
}
return proxyInstance;
}
},
});
}
}
return proxyInstance;
},
});
};
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@angular/compiler-cli": "^18.1.0",
"@angular/language-service": "^18.1.0",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@klaster_1/testcafe-repeat-test": "^1.0.1",
"@napi-rs/canvas": "^0.1.53",
"@types/chrome-remote-interface": "^0.31.14",
"@types/node": "^20.14.10",
Expand Down

0 comments on commit 9940bdc

Please sign in to comment.