Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Create test harness #4268

Merged
merged 6 commits into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -36,6 +36,9 @@ cli/.flow-bins-cache/*
cli/package-lock.json
cli/README.md

# Test harness
harness/

# Editors
.vscode
.idea
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -88,6 +88,8 @@ and now you'd like to contribute it.
>
> This will cover steps 1 - 4, of course without real definitions or tests written for you.

> Before you start, if you think you have a fairly complicated library definition or one that you have not yet written and tested with your personal project you may consider leveraging our **test harness** which allows you to write code immediately in a simplified clean environment. Learn more [here](https://flow-typed.github.io/flow-typed/#/harness) or just create the harness (`./test_harness.sh`) to get started.

#### 1) Create a new directory called `definitions/npm/left-pad_v4.x.x/`.

***We call this the "package version directory".***
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Expand Up @@ -13,5 +13,6 @@
- [update-cache](cache.md)
- [validate-defs](validate.md)
- [version](version.md)
- [Test Harness](harness.md)
- [FAQ](faq.md)
- [Changelog](changelog.md)
23 changes: 23 additions & 0 deletions docs/harness.md
@@ -0,0 +1,23 @@
# Test Harness

A testing ground created to help you write and test flow definitions before contributing them back to our registry.

After cloning the repository you can run `./test_harness.sh` in the root directory to create the `./harness` directory. Here you can write general flow code or definitions to verify functionality in real time with an IDE.

``` bash
# Sample usage
./test_harness.sh
./test_harness.sh 0.140.0 # creates the test harness with flow-bin set to `v0.140.0`
```

The directory is git ignored so please feel free to add any settings to `.flowconfig`, dependencies to package.json or other library definitions to achieve your needs.

Once you're done with development you can delete the directory or leave it for next time, the choice is yours.

## Contributing back

If you wrote a definition you'd like to now contribute back you can read our [contributing](contributing.md) guide and copy the definition over. The test harness is originally setup with a `definition.js` and `test_definition.js` for definition creation and testing respectively for this purpose.

Once you have them copied, you can run our full test suite that runs them against various flow versions to ensure they're up to the standards we need for contribution.

**Contrary to the test harness code written in the `definitions` directory can't be checked by flow in real time**
38 changes: 38 additions & 0 deletions test_harness.sh
@@ -0,0 +1,38 @@
#!/bin/sh

flowVersion=$1
if [ -z "$flowVersion" ]
then
lib="flow-bin@latest"
else
lib="flow-bin@$flowVersion"
fi

if [ -d "./harness" ]
then
cd harness
npm i --save-dev $lib
else
mkdir harness
cd harness
npm init -y
npm i --save-dev $lib
npx flow-setup flow-typed-harness
cp ../docs/harness.md README.md
cat <<EOF > definition.js
declare module "" {

}
EOF
cat <<EOF > test_definition.js
// @flow
import { describe, it } from 'flow-typed-test';
// import lib from 'test';

describe('', () => {
it('', () => {

});
});
EOF
fi