Skip to content

Commit c035367

Browse files
authored
Update contributing guide (#6355)
1 parent 9247327 commit c035367

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,35 +163,36 @@ Currently all tests are located in the `jscomp/test` directory and you should ei
163163
There are currently two formats for test files:
164164

165165
1. Mocha test files that run javascript test code
166-
2. Plain `.ml` files to check the result of compilation to JS (expectation tests)
166+
2. Plain `.res` files to check the result of compilation to JS (expectation tests)
167167

168168
Below we will discuss on how to write, build and run these test files.
169169

170170
### 1) Write a Mocha Test File
171171

172-
- Create a file `jscomp/test/feature_abc_test.ml`. Make sure to end the file name with `_test.ml`.
173-
- Inside the file, add a mocha test suite. The mocha bindings are defined in `jscomp/test/mt.ml`. To get you started, here is a simple scaffold for a test suite with multiple test cases:
174-
175-
```ocaml
176-
let suites : _ Mt.pair_suites =
177-
["hey", (fun _ -> Eq(true, 3 > 2));
178-
"hi", (fun _ -> Neq(2,3));
179-
"hello", (fun _ -> Approx(3.0, 3.0));
180-
"throw", (fun _ -> ThrowAny(fun _ -> raise 3))
181-
]
182-
let () = Mt.from_pair_suites __FILE__ suites
172+
- Create a file `jscomp/test/feature_abc_test.res`. Make sure to end the file name with `_test.res`.
173+
- 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:
174+
175+
```rescript
176+
let suites: Mt.pair_suites = list{
177+
("hey", _ => Eq(true, 3 > 2)),
178+
("hi", _ => Neq(2, 3)),
179+
("hello", _ => Approx(3.0, 3.0)),
180+
("throw", _ => ThrowAny(_ => raise(SomeException))),
181+
}
182+
183+
Mt.from_pair_suites(__MODULE__, suites)
183184
```
184185

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

188-
### 2) Write a Plain `.ml` Test File
189+
### 2) Write a Plain `.res` Test File
189190

190-
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. if you add a new type alias to a specific module and you just want to make sure the compiler handles the types correctly (see [`jscomp/test/empty_obj.ml`](jscomp/test/empty_obj.ml) as an example).
191+
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.
191192

192-
- Create your test file `jscomp/test/my_file_test.ml`. Make sure to end the file name with `_test.ml`.
193+
- Create your test file `jscomp/test/my_file_test.res`. Make sure to end the file name with `_test.res`.
193194
- Build the `.js` artifact: `node scripts/ninja.js config && node scripts/ninja.js build`.
194-
- Verify the output, check in the `jscomp/test/my_file_test.ml` and `jscomp/test/my_file_test.js` to version control. The checked in `.js` file is essential for verifying regressions later on.
195+
- 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.
195196
- Eventually check in other relevant files changed during the rebuild (depends on your compiler changes).
196197

197198
## Contribute to the ReScript Playground Bundle

0 commit comments

Comments
 (0)