compiler/packages/snap/src/sprout/README.md
React Forget test framework that executes compiler fixtures.
Currently, Sprout runs each fixture with a known set of inputs and annotations. Sprout compares execution outputs (i.e. return values and console logs) of original source code and the corresponding Forget-transformed version. We hope to add fuzzing capabilities to Sprout, synthesizing sets of program inputs based on type and/or effect annotations.
Sprout is now enabled for all fixtures! If Sprout cannot execute your fixture due to some technical limitations, add your fixture to SproutTodoFilter.ts with a comment explaining why.
Sprout is now run as a part of snap, except when in filter mode.
Each fixture test executed by Sprout needs to export const FIXTURE_ENTRYPOINT object with the following type signature.
type FixtureEntrypoint<T> = {
// function to be invoked
fn: ((...params: Array<T>) => any),
// params to pass to fn
// (if `fn` is a react component, this should be an array
// with exactly one element -- props)
params: Array<T>,
}
Example:
// test.js
function MyComponent(props) {
return <div>{props.a + props.b}</div>;
}
export const FIXTURE_ENTRYPOINT = {
fn: MyComponent,
params: [{a: "hello ", b: "world"}],
};
// test.js
import { addOne } from 'shared-runtime';
function customHelper(val1, val2) {
// This directive is important, as helper functions don't
// always follow the rules of React.
"use no forget";
// ...
}
// ...
If your fixture needs to import from an external module, we currently only support importing from react (see Milestones todo list).
Any fixture can use React hooks, but they need to be first imported. We may later enforce that only isComponent: true fixtures can use React hooks.
import {useState} from 'react';
If your fixture wants to export multiple functions to Sprout to run, please split up the fixture into multiple files (e.g. test-case-1, test-case-2, etc).
Sprout currently runs each fixture in an iife to prevent variable collisions, but it does not run fixtures in isolation. Please do not mutate any external state in fixtures.
Sprout does not run fixtures listed in SproutTodoFilter.ts, even in filter mode.
testing-library/react.SproutTodoFilter.ts). This involves each fixture being annotated with FIXTURE_ENTRYPOINT and using shared functions and/or defining its own helpers.
fixture.js, fixture.snap.md, and fixture.sprout.md.fbt.