| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | // `test` is part of Jest's serializer API |
| 11 | export function test(maybeDehydratedValue) { |
| 12 | const {meta} = require('react-devtools-shared/src/hydration'); |
| 13 | |
| 14 | const hasOwnProperty = |
| 15 | Object.prototype.hasOwnProperty.bind(maybeDehydratedValue); |
| 16 | return ( |
| 17 | maybeDehydratedValue !== null && |
| 18 | typeof maybeDehydratedValue === 'object' && |
| 19 | hasOwnProperty(meta.inspectable) && |
| 20 | maybeDehydratedValue[meta.inspected] !== true |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | // print() is part of Jest's serializer API |
| 25 | export function print(dehydratedValue, serialize, indent) { |
| 26 | const {meta} = require('react-devtools-shared/src/hydration'); |
| 27 | const indentation = Math.max(indent('.').indexOf('.') - 2, 0); |
| 28 | const paddingLeft = ' '.repeat(indentation); |
| 29 | return ( |
| 30 | 'Dehydrated {\n' + |
| 31 | paddingLeft + |
| 32 | ' "preview_short": ' + |
| 33 | dehydratedValue[meta.preview_short] + |
| 34 | ',\n' + |
| 35 | paddingLeft + |
| 36 | ' "preview_long": ' + |
| 37 | dehydratedValue[meta.preview_long] + |
| 38 | ',\n' + |
| 39 | paddingLeft + |
| 40 | '}' |
| 41 | ); |
| 42 | } |