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

Add tests for static_react_task example #795

Merged
merged 32 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b116336
✅ Added passing tests for static_react_task
Etesam913 Jun 16, 2022
a091438
🔥 Removed the starter test
Etesam913 Jun 16, 2022
379c9e9
🔧 Configured github actions for cypress
Etesam913 Jun 17, 2022
481433f
✏️ Added correct extension to workflow
Etesam913 Jun 17, 2022
8bcd15c
🔥 Removed extraneous code from cypress folder
Etesam913 Jun 17, 2022
ee4d978
📝 Added info on cypress testing to contributing.md
Etesam913 Jun 17, 2022
0aee860
🐛 Fixed request_agent test being inconsistent
Etesam913 Jun 18, 2022
7bc4f1b
✨ Added ability to link packages from command line
Etesam913 Jun 20, 2022
9ee7203
Merge branch 'main' of https://github.com/facebookresearch/Mephisto i…
Etesam913 Jun 20, 2022
ac59bbd
✨ Added command line arg to other examples
Etesam913 Jun 20, 2022
3c392a5
⛓ Updated github action to link to mephisto-task
Etesam913 Jun 20, 2022
113b8a8
✏️ Renamed the test
Etesam913 Jun 20, 2022
b944d78
🎨 Added spacing
Etesam913 Jun 20, 2022
a5cc65f
🔥 Delete commented out file
Etesam913 Jun 20, 2022
2e989e9
⏮ Reverting test back
Etesam913 Jun 20, 2022
f904089
🔥 Removed defineConfig from cypressConfig
Etesam913 Jun 21, 2022
721b4e6
🔀 Pulled from origin
Etesam913 Jun 21, 2022
0fc65a1
🐛 Fixed syntax bug
Etesam913 Jun 21, 2022
5702d9e
🔧 Updated hydra config to accept two new parameters
Etesam913 Jun 21, 2022
41cc544
📝 Added post_build_script to cypress start action
Etesam913 Jun 21, 2022
6b40eed
✏️ Updated contributing to two new sections
Etesam913 Jun 22, 2022
d5e846d
📦 Moved troubleshooting section
Etesam913 Jun 22, 2022
eb27dc9
✏️ Fixed typo in CONTRIBUTING.md
Etesam913 Jun 23, 2022
00e0023
✅ Simplified the tests for alerts
Etesam913 Jun 24, 2022
35b3f28
🔥 Removed extraneous code
Etesam913 Jun 24, 2022
d34a2ef
✏️ Added testing section to readme of task
Etesam913 Jun 26, 2022
e1393b9
✏️ Fixed typos in task_run fields
Etesam913 Jun 27, 2022
14beded
✏️ Renamed post_build_script field
Etesam913 Jun 27, 2022
db879d5
✏️ Replaced all occurrences of post_build_script
Etesam913 Jun 27, 2022
28c8431
🥅 Update build_bundle to work with no run_config
Etesam913 Jul 5, 2022
ff7ae27
🔥 Removed two properties from hydra_config
Etesam913 Jul 5, 2022
cd3a36c
🚨 Removed parameter warnings as they were too noisy
Etesam913 Jul 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/cypress-end-to-end-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: cypress-end-to-end-tests
on:
pull_request:
push:
branches: [main]

jobs:
static-react-task:
runs-on: ubuntu-latest
steps:
- name: 🔀 Checking out repo
uses: actions/checkout@v2
- name: 🐍 Installing python
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
with:
node-version: 16

- name: 🤖 Install Mephisto
run: pip install -e .

- name: 🖋 Create data directory
run: |
cd ~
mkdir mephisto
cd mephisto
mkdir data

- name: 📂 Set the data directory
run: |
mephisto config core.main_data_directory ~/mephisto/data

- name: 📦 Setting up mephisto-task package
run: |
cd packages/mephisto-task
yarn install
yarn build
npm link

- name: ⌛️ Running cypress tests
uses: cypress-io/[email protected]
with:
install: false
project: ./examples/static_react_task/webapp
config-file: ./cypress.config.js
start: python examples/static_react_task/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
Copy link
Contributor Author

@Etesam913 Etesam913 Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#795 (comment)

As a note - we can probably get these to automatically trigger as part of the test suite when any file in packages is updated, such that we get this 'for free' on PRs.

I think I am already doing that in this github action (the start field)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - missed that on first pass!

wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
command-prefix: yarn dlx
headless: true
44 changes: 43 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,49 @@ We actively welcome your pull requests.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

### Task Contributions
## Cypress Testing
For cypress testing the base url is: http://localhost:3000/?worker_id=x&assignment_id=1

### Running end to end tests on a task:
1. Run the task by running python run_task.py in the appropriate task folder
2. In a separate terminal window go into the webapp directory and run `npm run test`
3. This should open a cypress app
4. It is advised to test in Chrome(Chrome, Electron, and Firefox are all the options) as this browser works well with Cypress.
5. After clicking one of the spec files, the tests from that spec will automatically run

### Troubleshooting:
### There may be a case where there is a baseUrl mismatch.

For example:
Suppose you ran the toxicity detection task and then closed it. This would use assignmentId=1 and assignmentId=2.

If you then ran the mnist task, for example, then assignmentId=3 and assignmentId=4 would be used. While this task is running you can choose to run cypress tests in a different terminal window by going into the webapp folder and running `npm run test`.

These tests will fail because the base url of http://localhost:3000/?worker_id=x&assignment_id=1 is not associated with the mnist task, it is associated with the toxicity detection task. The correct react-elements will not show up.

There is a way to fix this:
* You can change the base url(found in the cypress.config.js file in the webapp folder) to the current url that you are on.
* Make sure to reset the baseUrl back to default("/") if contributing to the repo as the GitHub action will fail otherwise.

## Local Package Development
If you are modifying either the `mephisto-task` or `mephisto-worker-experience` packages you probably want to see your changes propagate to the task that you are working on.

The easiest way to do this is to run a task by doing:
```bash
python run_task.py mephisto.task.post_install_script=link_mephisto_task.sh mephisto.task.force_rebuild=true
```

Setting `mephisto.task.force_rebuild=true` runs `npm build` before running your task. By default the task is only rebuilt if a file is changed in the webapp, not if a linked package is changed.

Setting `mephisto.task.post_install_script=link_mephisto_task.sh` runs the `link_mephisto_task.sh` script after `npm install` is ran and before the task is started. This script should be located in the webapp folder of the task. While this script can do many things, for local package development the primary purpose of it is to link to a local package.
Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note - we can probably get these to automatically trigger as part of the test suite when any file in packages is updated, such that we get this 'for free' on PRs.


Alternatively, these values can be set in the task's hydra_configs/conf yaml file if you want to forgo typing the above and just type
```bash
python run_task.py
```
instead.

## Task Contributions
Generally we encourage people to provide their own blueprints as part of the repo in which they release their code, though if someone creates a strong case for an abstract `Blueprint` that is generally applicable we'd be happy to review it.

## Contributor License Agreement ("CLA")
Expand Down
7 changes: 6 additions & 1 deletion examples/remote_procedure/mnist/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def handle_with_model(
)

task_dir = cfg.task_dir
build_custom_bundle(task_dir)

build_custom_bundle(
task_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
post_install_script=cfg.mephisto.task.post_install_script,
)

operator.launch_task_run(cfg.mephisto, shared_state)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)
Expand Down
Loading