Split Tezt into a JS-compatible core and a JS-incompatible Main
Corresponding MR in tezos/opam-repository: opam-repository!353 (merged)
Context
We'd like to convert unit test to Tezt (#1265 (closed)). However, it is currently not possible to run executables linked with Tezt using nodejs because of the dependency on lwt.unix. This MR splits Tezt into a core lib (tezt.core) which does not depend on lwt.unix (only on lwt and unix), and a non-JS compatible part (tezt).
The Process and Runner modules will not be available in the JS version, this would be too much work.
The Temp module is currently not available either in the JS version, but there is probably a way to make it work later. The big issue being the dependency from Temp to Runner, so we may need two different implementations of Temp?
The rest of Tezt though can be put in tezt.core:
-
Lwt_unix.sleepbecomes a parameter; - the call
Lwt_main.runis pushed into theSchedulersubmodule, which is itself turned into a parameter; - the
Regressionmodule usedProcessto calldiff, I replaced that with my own implementation of diff; - the
Regressionmodule also needed the typeProcess.hooks, which I have moved into its own moduleProcess_hooks; - the
Regressionmodule no longer depends onTempeither: it gathers data in memory instead of a temporary file.
The new Main module is in charge of passing Unix-specific parameters such as Lwt_unix.sleep and the Scheduler.
TODO
-
Find what to do with Unix.getpid ()inTemp(replace withRandom.int? but do we wantRandom.self_init?) -
Remove the example -
Update the manifest to have it generate JS versions of tezts when we want -
Use Lwt_js.sleep(fromjs_of_ocaml-lwt) -
Try to have only one opam package but with js_of_ocamlas an optional dependency by makingtezt.jsitself optional (stanza(optional)to implement in the manifest) -
Have a nice story to tell about how to use Tezt: with unix, with JS, with both, for non-Octez devs (i.e. no manifest) -
Update documentation
Manually testing the MR
$ dune build tezt/example_js
$ dune exec tezt/example_js/main.exe
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ dune exec tezt/example_js/main.exe -j 4
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ nodejs _build/default/tezt/example_js/main_js.bc.js
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ nodejs _build/default/tezt/example_js/main_js.bc.js -j 4
[13:43:58.877] [warn] The -j argument is ignored when using Tezt_js.run.
[13:43:58.882] [SUCCESS] (1/1) an example of test
Also, check the absence of missing primitives with:
dune build tezt/example_js/main_js.bc.js --profile release
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR