Add itSkipOnFail util

Part of #139076
This commit is contained in:
Daniel Imms
2021-12-14 08:05:43 -08:00
parent 838cbd5223
commit c29df4c2d5
2 changed files with 22 additions and 2 deletions

View File

@@ -18,6 +18,25 @@ export function itRepeat(n: number, description: string, callback: (this: Contex
}
}
/**
* Defines a test-case that will run but will be skips it if it throws an exception. This is useful
* to get some runs in CI when trying to stabilize a flaky test, without failing the build. Note
* that this only works if something inside the test throws, so a test's overall timeout won't work
* but throwing due to a polling timeout will.
* @param title The test-case title.
* @param callback The test-case callback.
*/
export function itSkipOnFail(title: string, callback: (this: Context) => any): void {
it(title, function () {
return Promise.resolve().then(() => {
return callback.apply(this, arguments);
}).catch(() => {
console.warn(`Test "${title}" failed but was marks as skip on fail`);
this.skip();
});
});
}
export function installAllHandlers(logger: Logger, optionsTransform?: (opts: ApplicationOptions) => ApplicationOptions) {
installDiagnosticsHandler(logger);
installAppBeforeHandler(optionsTransform);