2018-10-06 23:42:52 +02:00
|
|
|
// @flow
|
2018-10-16 21:45:56 +02:00
|
|
|
/* eslint-disable no-console */
|
2018-10-06 23:42:52 +02:00
|
|
|
import * as React from 'react';
|
2018-10-16 21:45:56 +02:00
|
|
|
import render from './render';
|
2018-11-19 13:51:38 +01:00
|
|
|
import debugShallow from './helpers/debugShallow';
|
|
|
|
|
import debugDeep from './helpers/debugDeep';
|
|
|
|
|
import format from './helpers/format';
|
2018-10-06 23:42:52 +02:00
|
|
|
|
2018-10-16 21:45:56 +02:00
|
|
|
/**
|
|
|
|
|
* Log pretty-printed deep test component instance
|
|
|
|
|
*/
|
2018-11-19 13:51:38 +01:00
|
|
|
function debugDeepElementOrInstance(
|
2018-11-28 12:49:15 +01:00
|
|
|
instance: React.Element<any> | ?ReactTestRendererJSON,
|
2018-10-18 09:13:47 +02:00
|
|
|
message?: any = ''
|
|
|
|
|
) {
|
|
|
|
|
try {
|
2018-11-28 12:49:15 +01:00
|
|
|
// We're assuming React.Element<any> here and fallback to
|
2018-10-18 09:13:47 +02:00
|
|
|
// rendering ?ReactTestRendererJSON
|
|
|
|
|
// $FlowFixMe
|
|
|
|
|
const { toJSON } = render(instance);
|
2018-11-19 13:51:38 +01:00
|
|
|
if (message) {
|
|
|
|
|
console.log(`${message}\n\n`, format(toJSON()));
|
|
|
|
|
} else {
|
|
|
|
|
console.log(format(toJSON()));
|
|
|
|
|
}
|
2018-10-18 09:13:47 +02:00
|
|
|
} catch (e) {
|
2018-11-19 13:51:38 +01:00
|
|
|
// $FlowFixMe
|
|
|
|
|
debugDeep(instance);
|
2018-10-18 09:13:47 +02:00
|
|
|
}
|
2018-10-16 21:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-28 12:49:15 +01:00
|
|
|
function debug(
|
|
|
|
|
instance: ReactTestInstance | React.Element<any>,
|
|
|
|
|
message?: any
|
|
|
|
|
) {
|
2018-11-19 13:51:38 +01:00
|
|
|
return debugShallow(instance, message);
|
|
|
|
|
}
|
2018-10-16 21:45:56 +02:00
|
|
|
|
|
|
|
|
debug.shallow = debugShallow;
|
2018-11-19 13:51:38 +01:00
|
|
|
debug.deep = debugDeepElementOrInstance;
|
2018-10-16 21:45:56 +02:00
|
|
|
|
|
|
|
|
export default debug;
|