Skip to content

Update documentation about tests #7070

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

Merged
merged 1 commit into from
Oct 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The goal is to implement the runtime **purely in OCaml**. This includes removing

Each new PR should include appropriate testing.

Currently all tests are located in the `jscomp/test` directory and you should either add / update test files according to your changes to the compiler.
Currently all tests are located in the `tests/tests` directory and you should either add / update test files according to your changes to the compiler.

There are currently two formats for test files:

Expand All @@ -187,8 +187,8 @@ Below we will discuss on how to write, build and run these test files.

### 1) Write a Mocha Test File

- Create a file `jscomp/test/feature_abc_test.res`. Make sure to end the file name with `_test.res`.
- Inside the file, add a mocha test suite. The mocha bindings are defined in `jscomp/test/mt.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:
- Create a file `tests/tests/src/feature_abc_test.res`. Make sure to end the file name with `_test.res`.
- Inside the file, add a mocha test suite. The mocha bindings are defined in `tests/tests/src/mt.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:

```rescript
let suites: Mt.pair_suites = list{
Expand All @@ -201,16 +201,15 @@ Below we will discuss on how to write, build and run these test files.
Mt.from_pair_suites(__MODULE__, suites)
```

- Build the test files: `node scripts/ninja.js clean && node scripts/ninja.js build`.
- Run the tests: `npx mocha jscomp/test/**/*test.js`.
- Build the test files and run the tests: `node scripts/test.js -mocha`.

### 2) Write a Plain `.res` Test File

This is usually the file you want to create to test certain compile behavior without running the JS code formally as a test, i.e., when you just want to check that the ReScript code compiles and produces the expected JS code.

- Create your test file `jscomp/test/my_file_test.res`. Make sure to end the file name with `_test.res`.
- Build the `.js` artifact: `node scripts/ninja.js config && node scripts/ninja.js build`.
- Verify the output, check in the `jscomp/test/my_file_test.res` and `jscomp/test/my_file_test.js` to version control. The checked in `.js` file is essential for verifying regressions later on.
- Create your test file `tests/tests/src/my_file_test.res`. Make sure to end the file name with `_test.res`.
- Build the `.js` artifact: `node scripts/test.js -mocha`.
- Verify the output, check in the `tests/tests/src/my_file_test.res` and `tests/tests/src/my_file_test.js` to version control. The checked in `.js` file is essential for verifying regressions later on.
- Eventually check in other relevant files changed during the rebuild (depends on your compiler changes).

## Contribute to the ReScript Playground Bundle
Expand Down
4 changes: 2 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ ReScript imported one file from [jsoo](https://github.com/ocsigen/js_of_ocaml)

This file was imported but changed significantly in iterations later.

- [`jscomp/test`](jscomp/test)
- [`tests/tests`](tests/tests)

`jscomp/test` is based on [`ocaml/testsuite`](ocaml/testsuite).
`tests/tests` is based on [`ocaml/testsuite`](ocaml/testsuite).

ReScript unit test builds on parts of [OUnit](http://ounit.forge.ocamlcore.org/)

Expand Down