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).
# Build Flow
make
# Run all tests
./runtests.sh bin/flow
# Run a specific test
./runtests.sh -t <test_name> bin/flow
# Example: run the records test
./runtests.sh -t records bin/flow./runtests.sh -t mytest $(buck2 build //flow:flow --show-full-output | awk '{print $2}')./runtests.sh <flow_binary> -f "^record" # All tests starting with "record"./runtests.sh -l <flow_binary>./runtests.sh -t <test_name> -r <flow_binary>This 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)
./runtests.sh -t mytest ../bin/flow
# Correct (absolute path)
./runtests.sh -t mytest /full/path/to/bin/flow
# Or use command substitution (Meta only)
./runtests.sh -t mytest $(buck2 build //flow:flow --show-full-output | awk '{print $2}')