You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+17-16Lines changed: 17 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -163,35 +163,36 @@ Currently all tests are located in the `jscomp/test` directory and you should ei
163
163
There are currently two formats for test files:
164
164
165
165
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)
167
167
168
168
Below we will discuss on how to write, build and run these test files.
169
169
170
170
### 1) Write a Mocha Test File
171
171
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:
- Build the test files: `node scripts/ninja.js clean && node scripts/ninja.js build`.
186
187
- Run the tests: `npx mocha jscomp/test/**/*test.js`.
187
188
188
-
### 2) Write a Plain `.ml` Test File
189
+
### 2) Write a Plain `.res` Test File
189
190
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.
191
192
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`.
- 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.
195
196
- Eventually check in other relevant files changed during the rebuild (depends on your compiler changes).
0 commit comments