newtests/README.md
./tool test./tool is a script in the root of this project. ./tool test runs the tests in this directory.
To make it work: run yarn install in the flow directory. This is needed both for tool to run, and also for flow check to work in the newtests directory.
./tool testCheck out tool_test_example, which is an example test.
./**/test.js.test.js file exports a Suite by defaultSuite contains a list of Tests.Test contains a list of TestStepsSuiteThe only way to create a Suite is to call the suite() function. The suite() function takes a callback, like so
import {suite} from 'flow-dev-tools/src/test/Tester';
import type TestStep from 'flow-dev-tools/src/test/TestStep';
module.exports = suite((emptyTestStep: TestStep) => [ < List of Tests >]);
(Why the suite() function? Why not just export the callback directly? Well, it removes the need for type annotations!)
TestThe only way to create a Test is to call the test() function. The test() function takes a test name and a list of TestSteps, like so
const {suite, test} = require('flow-dev-tools/src/test/Tester');
import type TestStep from 'flow-dev-tools/src/test/TestStep';
module.exports = suite((emptyTestStep: TestStep) => [
test('My first test, [ < List of TestSteps > ]'),
]);
TestStepsA TestStep is made up of 0 or more actions and 0 or more assertions. The emptyTestStep passed to suite()'s callback is a TestStep with 0 actions and 0 assertions. TestSteps are immutable, so when you call emptyTestStep.addFile('foo.js') you get back a new TestStep with 1 action and 0 assertions. So a test looks like
const {suite, test} = require('flow-dev-tools/src/test/Tester');
import type TestStep from 'flow-dev-tools/src/test/TestStep';
module.exports = suite((emptyTestStep: TestStep) => [
test('My first test', [
emptyTestStep
.addCode('var x = 123')
.noNewErrors(),
emptyTestStep
.addCode('var y = "hello"')
.noNewErrors(),
]),
]);
More concisely, this can be written
const {suite, test} = require('flow-dev-tools/src/test/Tester');
module.exports = suite(({addCode}) => [
test('My first test', [
addCode('var x = 123')
.noNewErrors(),
addCode('var y = "hello"')
.noNewErrors(),
]),
]);
Note: You cannot add actions to a TestStep after an assertion because @gabelevi felt like messing around with the type system to prevent it :)