/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @emails oncall+recoil * @flow strict-local * @format */ 'use strict'; import type { RecoilValueReadOnly } from '../core/Recoil_RecoilValue'; import type { RecoilState, RecoilValue } from '../core/Recoil_RecoilValue'; import type { Store } from '../core/Recoil_State'; const ReactDOM = require('ReactDOM'); const { act } = require('ReactTestUtils'); const { graph } = require('../core/Recoil_Graph'); const { RecoilRoot, sendEndOfBatchNotifications_FOR_TESTING } = require('../core/Recoil_RecoilRoot.react'); const { invalidateDownstreams_FOR_TESTING } = require('../core/Recoil_RecoilValueInterface'); const { makeEmptyStoreState } = require('../core/Recoil_State'); const { useRecoilValue, useResetRecoilState, useSetRecoilState } = require('../hooks/Recoil_Hooks'); const selector = require('../recoil_values/Recoil_selector'); const invariant = require('../util/Recoil_invariant'); const nullthrows = require('../util/Recoil_nullthrows'); const stableStringify = require('../util/Recoil_stableStringify'); const React = require('react'); const { useEffect } = require('react'); // TODO Use Snapshot for testing instead of this thunk? declare function makeStore(): Store; declare class ErrorBoundary extends React.Component<{ children: React.Node | null, ... }, { hasError: boolean, ... }> { state: any, static getDerivedStateFromError(_error: any): any, render(): any, } declare function createReactRoot(container: any, contents: any): any; declare function renderElements(elements: ?React.Node): HTMLDivElement; declare function renderElementsWithSuspenseCount(elements: ?React.Node): [HTMLDivElement, JestMockFn<[], void>]; //////////////////////////////////////// // Useful RecoilValue nodes for testing //////////////////////////////////////// let id = 0; declare var errorThrowingAsyncSelector: (msg: any, dep: ?RecoilValue) => RecoilValueReadOnly; declare var resolvingAsyncSelector: (value: T) => RecoilValueReadOnly | RecoilValueReadOnly; declare var loadingAsyncSelector: () => any; declare function asyncSelector(dep?: RecoilValue): [RecoilValue, (T) => void, (Error) => void]; ////////////////////////////////// // Useful Components for testing ////////////////////////////////// declare function ReadsAtom(arg0: { atom: RecoilValue }): React.Node; // Returns a tuple: [ // Component, // setValue(T), // resetValue() // ] declare function componentThatReadsAndWritesAtom(atom: RecoilState): [() => React.Node, (T) => void, () => void]; declare function flushPromisesAndTimers(): Promise; type ReloadImports = () => void | (() => void); type AssertionsFn = (gks: Array) => ?Promise; type TestOptions = { gks?: Array> }; type TestFn = (string, AssertionsFn, TestOptions | void) => void; declare var testGKs: (reloadImports: ReloadImports, gks: Array>) => TestFn; const WWW_GKS_TO_TEST = [['recoil_suppress_rerender_in_callback'], ['recoil_hamt_2020'], ['recoil_memory_managament_2020', 'recoil_release_on_cascading_update_killswitch_2021'], ['recoil_hamt_2020', 'recoil_memory_managament_2020', 'recoil_release_on_cascading_update_killswitch_2021']]; /** * GK combinations to exclude in OSS, presumably because these combinations pass * in FB internally but not in OSS. Ideally this array would be empty. */ const OSS_GK_COMBINATION_EXCLUSIONS = []; // eslint-disable-next-line no-unused-vars const OSS_GKS_TO_TEST = WWW_GKS_TO_TEST.filter(gkCombination => !OSS_GK_COMBINATION_EXCLUSIONS.some(exclusion => exclusion.every(gk => gkCombination.includes(gk)))); declare var getRecoilTestFn: (reloadImports: ReloadImports) => TestFn; module.exports = { makeStore, renderElements, renderElementsWithSuspenseCount, ReadsAtom, componentThatReadsAndWritesAtom, errorThrowingAsyncSelector, resolvingAsyncSelector, loadingAsyncSelector, asyncSelector, flushPromisesAndTimers, getRecoilTestFn };