mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
[CORL-159, CORL-160] Stream Config Tab (#2219)
* feat: Implement stream configuration tab * feat: split profile & configure into separate bundles * chore: better role logic * fix+chore: add test cases, implement expectAndFail, refactor tests * chore: add some comments * chore: Update src/core/client/framework/lib/form/helpers.tsx Co-Authored-By: cvle <vinh@wikiwi.io> * feat: support new graphql mutations/schema * fix: ci fixes * fix: improvement to revision loading * fix: updated some tests * fix: adapt client to changes * fix: remove obsolote isClosed in UpdateStory * ci: increase no_output_timeout for build
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Jest assertions will not fail if they live inside a try-catch block due to
|
||||
// https://github.com/facebook/jest/issues/3917.
|
||||
|
||||
// This file returns a version of `expect` that that
|
||||
// fails the test immediately when an exception is thrown.
|
||||
|
||||
/**
|
||||
* isPromise detects whether given object is a promise or not.
|
||||
*/
|
||||
const isPromise = <T extends any>(obj: any): obj is PromiseLike<T> =>
|
||||
!!obj &&
|
||||
(typeof obj === "object" || typeof obj === "function") &&
|
||||
typeof obj.then === "function";
|
||||
|
||||
/**
|
||||
* Wrap a jest matcher so if the expectation fails, it also fails the test.
|
||||
* @param func the jest matcher that will be wrapped.
|
||||
*/
|
||||
const wrapMatcher = (func: any) => {
|
||||
const wrappedMatcher: any = {};
|
||||
const keys = Object.keys(func);
|
||||
keys.forEach(k => {
|
||||
if (typeof func[k] === "function") {
|
||||
wrappedMatcher[k] = (...args: any[]) => {
|
||||
try {
|
||||
const result = func[k](...args);
|
||||
if (isPromise(result)) {
|
||||
return result.then(undefined, e => {
|
||||
// Remove this function from stacktrace.
|
||||
Error.captureStackTrace(e, wrappedMatcher[k]);
|
||||
fail(e);
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
// Remove this function from stacktrace.
|
||||
Error.captureStackTrace(e, wrappedMatcher[k]);
|
||||
fail(e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// This should be not, resolves, rejects.
|
||||
wrappedMatcher[k] = wrapMatcher(func[k]);
|
||||
}
|
||||
});
|
||||
return wrappedMatcher;
|
||||
};
|
||||
|
||||
const expectAndFail = (...args: any[]) => {
|
||||
const matcher = (global as any).expect(...args);
|
||||
return wrapMatcher(matcher);
|
||||
};
|
||||
|
||||
export default expectAndFail;
|
||||
@@ -1,6 +1,13 @@
|
||||
import expectAndFail from "./expectAndFail";
|
||||
|
||||
// Automatically unmock console.
|
||||
import "jest-mock-console/dist/setupTestFramework";
|
||||
|
||||
// Expose a version of expect that will fail tests immediately
|
||||
// when assertion fails. This works even inside of an try-catch block
|
||||
// to get around: https://github.com/facebook/jest/issues/3917
|
||||
(global as any).expectAndFail = expectAndFail;
|
||||
|
||||
// Log unhandled rejections.
|
||||
// tslint:disable-next-line:no-console
|
||||
process.on("unhandledRejection", err => {
|
||||
|
||||
Reference in New Issue
Block a user