mpizenberg / elm-test-rs

Fast and portable executable to run your Elm tests
BSD 3-Clause "New" or "Revised" License
81 stars 13 forks source link

Fails with "Error: Cannot find module 'worker_threads'" #39

Closed malaire closed 3 years ago

malaire commented 3 years ago

OS: Debian 10 Node: v10.21.0 Elm: 0.19.1

Trying to run elm-test-rs 0.4.1 for malaire/elm-uint64 fails with following error:

elm-test-rs 0.4.1
-----------------

Total time spent in the elm compiler: 0.13511102s
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/y/projects/GitHub/elm-uint64/elm-stuff/tests-0.19.1/js/node_supervisor.js:69:20)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
malaire commented 3 years ago

Looks like Node supports worker-threads since 10.5 with --experimental-worker command line switch, and since 12.0 without that switch.

ps. Node 10.21.0 is the latest version in Debian 10. Debian 11 is due around next summer and will have Node 12.x

lydell commented 3 years ago

Node.js 10 is EOL 2021-04-30: https://nodejs.org/en/about/releases/

mpizenberg commented 3 years ago

That's a bit annoying indeed. Worker thread is a key aspect of the work distribution chosen for elm-test-rs. Node-test-runner was based on node processes and named pipes but it was causing issues apparently and some hacks are present in the code base for this. I don't think I'm willing to go back to something else than worker threads for supervisor-runners communication.

I'm not familiar with Debian, are there some alternatives? Is it possible to install software that is not in the repository? maybe if that's the case, a Deno variant would be compatible with it?

malaire commented 3 years ago

I'm not familiar with Debian, are there some alternatives? Is it possible to install software that is not in the repository?

It is possible to install additional unofficial repositories and newer Node can be installed that way, but that can make Debian less stable. Personally I'd rather use Deno than Node from unofficial repository. (I don't currently have time to try Deno, but as I love Rust I'll definitely get to that eventually.)

Potential solution to support Node 10.x could be to detect Node version and use --experimental-worker for 10.x - but I don't know how feasible that is (or how "experimental" that feature was in 10.x).

mpizenberg commented 3 years ago

I just tried inside a debian container and it seems to be working. To try it, I run elm-test-rs, which crashed, but after generating all the necessary files inside elm-stuff/. Then I moved inside elm-stuff/tests-0.19.1/js/, run node with the experimental option and entered via stdin the path to the compiled runner:

root@cd327f072613:/app/elm-stuff/tests-0.19.1/js# nodejs --experimental-worker node_supervisor.js
/app/elm-stuff/tests-0.19.1/js/node_runner.js

Running 1 tests. To reproduce these results later, run:
elm-test-rs --seed 1924657170 --fuzz 100 (TODO: pass files to reporter)

◦ TODO: Implement the first test. See https://package.elm-lang.org/packages/elm-explorations/test/latest for how to do this!

TEST RUN INCOMPLETE because there is 1 TODO remaining

Duration: 2 ms
Passed:   0
Failed:   0
Todo:     1
Running duration (since Node.js start): 4863 ms

So it seems that the usage of workers in elm-test-rs is working. I haven't covered 100% of the JS code though. I've no idea if I've used JS syntax for example that may not be supported in Node 10.

mpizenberg commented 3 years ago

The node --version command seems to be quick to answer, taking few milliseconds. So I guess checking the node version can be done if that enables support for debian. Here is where node is invoked if you want to give it a try: https://github.com/mpizenberg/elm-test-rs/blob/466f3415ddb2e1bf4b9b006031cdf7fd85f2ada2/src/run.rs#L356

harrysarson commented 3 years ago

Normally using an --experimental flag would be bad but in this case (specific range of nodejs when the feature is stable in later versions) there is no risk of the unstable feature changing and causing problems so this approach looks good to me