refactor: use __TEST__ flag

This commit is contained in:
Evan You
2019-11-04 11:24:22 -05:00
parent fec47bb3ac
commit 300a705221
6 changed files with 23 additions and 15 deletions

View File

@@ -126,12 +126,15 @@ export function handleError(
logError(err, type, contextVNode)
}
// Test-only toggle for testing the uhandled warning behavior
let forceRecover = false
export function setErrorRecovery(value: boolean) {
forceRecover = value
}
function logError(err: Error, type: ErrorTypes, contextVNode: VNode | null) {
// default behavior is crash in prod & test, recover in dev.
if (
__DEV__ &&
!(typeof process !== 'undefined' && process.env.NODE_ENV === 'test')
) {
if (__DEV__ && (forceRecover || !__TEST__)) {
const info = ErrorTypeStrings[type]
if (contextVNode) {
pushWarningContext(contextVNode)

View File

@@ -53,7 +53,7 @@ export function warn(msg: string, ...args: any[]) {
if (
trace.length &&
// avoid spamming console during tests
(typeof process === 'undefined' || process.env.NODE_ENV !== 'test')
!__TEST__
) {
warnArgs.push(`\n`, ...formatTrace(trace))
}