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

inline_tests work on v0.15.1 but not on v0.16.0 #37

Open
mooreryan opened this issue Jun 28, 2023 · 5 comments
Open

inline_tests work on v0.15.1 but not on v0.16.0 #37

mooreryan opened this issue Jun 28, 2023 · 5 comments
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.

Comments

@mooreryan
Copy link

mooreryan commented Jun 28, 2023

I think I must be doing something obviously wrong here...but I can't get the inline tests to work with v0.16.0.

open! Core

let component = Bonsai.const Bonsai_web.Vdom.Node.(p [text "hello world"])

module Test = struct
  module Handle = Bonsai_web_test.Handle
  module Result_spec = Bonsai_web_test.Result_spec

  let%expect_test "it shows hello world" =
    let handle = Handle.create (Result_spec.vdom Fn.id) component in
    Handle.show handle ; [%expect {|  |}]
end

dune file

(library
 (name hi)
 (inline_tests
  (modes js))
 (libraries core bonsai.web bonsai.web_test)
 (preprocess
  (pps ppx_jane)))

Error when running tests

File "src/lib/test/dune", line 3, characters 1-28:
3 |  (inline_tests
4 |   (modes js))
node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module 'deasync'
Require stack:
- /home/ryan/projects/x/_build/default/src/lib/test/.lib_test.inline-tests/inline_test_runner_lib_test.bc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at /home/ryan/projects/x/_build/default/src/lib/test/.lib_test.inline-tests/inline_test_runner_lib_test.bc.js:4158:18
    at Object.<anonymous> (/home/ryan/projects/x/_build/default/src/lib/test/.lib_test.inline-tests/inline_test_runner_lib_test.bc.js:11581:3)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/ryan/projects/x/_build/default/src/lib/test/.lib_test.inline-tests/inline_test_runner_lib_test.bc.js'
  ]
}

Node.js v18.11.0

Switching back to the v0.15.1 release of bonsai, the above works fine.

@mooreryan
Copy link
Author

I also tried to set up the dune file as in the blog post on testing (https://github.com/janestreet/bonsai/blob/master/docs/blogs/testing.mdx):

(library (
  (name my_ui_test)
  (js_of_ocaml ())                   ; Test library must be marked with js_of_ocaml
  (libraries (core my_ui))
  (inline_tests (                    ; Native tests must be disabled
    (native     dont_build_dont_run)
    (javascript build_and_run)))))

But that gave other dune errors, so I'm assuming that isn't part of the solution.

@mooreryan
Copy link
Author

Here is a "minimum" example that triggers the error when running dune runtest:

dune file

(library
 (name hi)
 (inline_tests
  (modes js))
 (libraries bonsai.web_test)
 (preprocess
  (pps ppx_inline_test)))

OCaml file

let%test _ = 1 = 2

@mooreryan
Copy link
Author

So, I found a fix. I noticed that the bonsai.web_test pulls in async_js.async_test (here). Went to check on the runtime there and saw it required some JS package deasync (this).

So in the root of my project I ran npm install deasync, then reran the tests and it worked.

@mooreryan
Copy link
Author

So, I guess my question now is, is the npm install deasync the "correct" thing to do? (Well, it works so I will use it for now.)

@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Jun 29, 2023
@TyOverby
Copy link
Member

TyOverby commented Jul 6, 2023

Ah, yes that is the right package, but I'm a bit surprised that deasync is required if you aren't using our bonsai-test + async integration. I'll look into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

No branches or pull requests

3 participants