This directory contains the test suite for Flow. Each subdirectory represents a test case with source files and expected outputs.
For all commands described below, they must be run from the project root (flow).
These tests are run by the Rust test runner, <flow> dev-tools runtests, where
<flow> is the path to a Flow binary.
# Build Flow
make
# Run all tests
bin/flow dev-tools runtests
# Run a specific test
bin/flow dev-tools runtests -t <test_name>
# Example: run the records test
bin/flow dev-tools runtests -t records$(buck2 build //flow:flow --show-full-output | awk '{print $2}') dev-tools runtests -t mytest<flow_binary> dev-tools runtests -f "^record" # All tests starting with "record"<flow_binary> dev-tools runtests -l<flow_binary> dev-tools runtests -t <test_name> -rThis re-records the test output. Use this when you've intentionally changed Flow's behavior and need to update the .exp files.
Each test directory contains:
- Source files (
.js,.flow, etc.) - The JavaScript/Flow code being tested .expfile - Expected type errors and their format (human-readable).outfile - Generated output from the last test run (auto-generated, not checked in).errfile - Error output if the test failed (auto-generated)test.sh(optional) - Custom test script for tests with special requirements
- Always build Flow before running tests - Stale binaries lead to confusing results
- Use
-tfor single tests during development - Faster iteration
Each test is a directory under tests/ containing source files and a .flowconfig.
Add all=true to the .flowconfig so that // @flow pragmas are not required in test .js files:
[options]
all=true
Use declare const to create a variable of a given type without needing a runtime value:
declare const x: number;
declare const y: Map<string, number>;Do not use declare var.
To reuse variable names, wrap declarations in blocks to scope them:
{
declare const x: number;
// use x as number here
}
{
declare const x: string;
// use x as string here
}Use as for type casts:
x as T;Add an end-of-line // ERROR comment on lines where you expect Flow to report an error:
declare const x: number;
x as string; // ERRORTo record the inferred type of a variable in the test snapshot, cast it to empty to force an error. The error output will include the variable's type:
x as empty; // ERRORMake sure you're using the full absolute path to the flow binary:
# Wrong (relative path may fail)
../bin/flow dev-tools runtests -t mytest
# Correct (absolute path)
/full/path/to/bin/flow dev-tools runtests -t mytest
# Or use command substitution (Meta only)
$(buck2 build //flow:flow --show-full-output | awk '{print $2}') dev-tools runtests -t mytest