Fix integration test lifecycle fuctions not failing tests (#2259)

This commit is contained in:
Sebastian Malton committed 2021-04-06 10:13:45 -04:00
1 parent 64ebfc25ae
commit 5591c872f0
5 files changed
+59 -22

No files matched your search

+33
View File
@@ -8,6 +8,39 @@ const AppPaths: Partial<Record<NodeJS.Platform, string>> = {
"darwin": "./dist/mac/Lens.app/Contents/MacOS/Lens",
};
interface DoneCallback {
(...args: any[]): any;
fail(error?: string | { message: string }): any;
}
/**
* This is necessary because Jest doesn't do this correctly.
* @param fn The function to call
*/
export function wrapJestLifecycle(fn: () => Promise<void>): (done: DoneCallback) => void {
return function (done: DoneCallback) {
fn()
.then(() => done())
.catch(error => done.fail(error));
};
}
export function beforeAllWrapped(fn: () => Promise<void>): void {
beforeAll(wrapJestLifecycle(fn));
}
export function beforeEachWrapped(fn: () => Promise<void>): void {
beforeEach(wrapJestLifecycle(fn));
}
export function afterAllWrapped(fn: () => Promise<void>): void {
afterAll(wrapJestLifecycle(fn));
}
export function afterEachWrapped(fn: () => Promise<void>): void {
afterEach(wrapJestLifecycle(fn));
}
export function itIf(condition: boolean) {
return condition ? it : it.skip;
}