mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
3aa6196e30
snapshotting As demo'd on our sync. This is meant as a replacement for `yarn test` just for fixtures. On my machine, a test run from a steady state of Jest watch mode takes 6 seconds. With this script, it takes ~800ms. Workflow: make edits in `packages/snap/`, then `yarn build` in that directory to build the test runner. To run tests, `node packages/snap/dist/runner.js` from the main forget/ directory to run tests. Pass `--watch` for watch mode, `--update` to update snapshots. Note that this _only_ updates .expect.md files, it does not update Jest's `__snapshots__` directory (this is intentional, our use of Jest snapshots is a hack that this script is meant to replace). When running in watch mode, ctrl-c or q will quit, 'u' will update snapshots, and any other key will re-run tests. Tests will re-run on changes to the source code (after an incremental TS rebuild) and on changes to the fixtures. Main things that are missing: * Don't run tests if TS compilation had errors (the errors should be logged to console already, but we need to wire that up so that we abort tests if there are errors) * Actually delete stale files in update mode (there is some commented-out code to double-check and then uncomment) * Improve diff view: just print the diffed segments, not the whole file diff. See the API at https://github.com/facebook/jest/tree/main/packages/jest-diff (right now we're using `diff()` but should probably use one of the lower-level functions) * Properly parse/validate args with `yargs`, add a help option, etc * In watch mode, when tests finish print a list of commands so users know what they can do (like Jest does) * Support skipping tests and selecting a single test to focus. Suggestions: * Name files with `skip.` to skip * Allow passing a test name to the script to run only tests matching that pattern, eg `node runner.js -p <pattern>` * In watch mode, support typing 'p' to prompt the user for a pattern. After that, support typing 'a' to clear the pattern and run all tests.