bloodyowl / rescript-test

A lightweight test framework for ReScript
https://bloodyowl.github.io/rescript-test/
MIT License
78 stars 9 forks source link

bin #5

Closed JesterXL closed 2 years ago

JesterXL commented 3 years ago

My Jenkins server at work breaks with newer versions of Retest:

09:21:54  file:///home/git/workspace/rets-node-lambda-rescript_master/node_modules/rescript-test/bin/retest.mjs:19
09:21:54  let { autoBoot, runTests } = await import(`../src/Test${suffix}`);
09:21:54                               ^^^^^
09:21:54  
09:21:54  SyntaxError: Unexpected reserved word
09:21:54      at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
09:21:54      at async link (internal/modules/esm/module_job.js:42:21)

An older version, 0.6.5, works, I think because it uses CommonJS. Is there a way to support CommonJS? Yes, yes, I'm intimately aware of the struggle between MJS and CommonJS. However, in Node.js nothing is supported; case in point I'm in Node.js 14 which supports mjs 14 and "all kinds of weird things break". I'll revert to v0.6.5 for now, but if it sounds like a lot of work, I get it, I can help. As someone who's attempted twice to use mjs professionally and had all kinds of stupid stuff break, I empathize.

bloodyowl commented 3 years ago

It's supposed to support CommonJS too, but I'll look into it.

Can you share some elements of your bsconfig? Module type/chosen suffix?

bloodyowl commented 3 years ago

Other information that can be useful, what version of rescript are you using? Changes were made recently that can impact that

bloodyowl commented 3 years ago
Screen Shot 2021-06-21 at 07 41 32

Tried a repro, seems to work there.

JesterXL commented 3 years ago

Ah, good question, lemme look...

bloodyowl commented 3 years ago

Any news @JesterXL?

shulhi commented 3 years ago

I'm also having the same issue

{
  "$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
  "name": "stencil",
  "version": "0.0.1",
  "reason": {"react-jsx": 3},
  "refmt": 3,
  "sources": [
    {
      "dir" : "src",
      "subdirs" : true
    },
    {
      "dir": "test",
      "subdirs" : true,
      "type": "dev"
    }
  ],
  "package-specs": {
    "module": "commonjs"
  },
  "suffix": ".bs.js",
  "bs-dependencies": [
    "reason-react",
    "bs-fetch",
    "bs-aeson"
  ],
  "bs-dev-dependencies": [
    "rescript-test"
  ],
  "warnings": {
    "error" : "+101"
  }
}

I'm using rescript 9.1.4 with node v14

shulhi commented 3 years ago

I updated my node and got a different error now,

$  npm test --prefix assets

> stencil-frontend@0.0.1 test /home/shulhi/Devel/projects/stencil/assets
> retest test/*.bs.js

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/shulhi/Devel/projects/stencil/assets/node_modules/rescript-test/src/Test.bs.js' imported from /home/shulhi/Devel/projects/stencil/assets/node_modules/rescript-test/bin/retest.mjs
    at finalizeResolution (internal/modules/esm/resolve.js:276:11)
    at moduleResolve (internal/modules/esm/resolve.js:699:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:85:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
    at Loader.import (internal/modules/esm/loader.js:164:28)
    at importModuleDynamically (internal/modules/esm/translators.js:110:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at file:///home/shulhi/Devel/projects/stencil/assets/node_modules/rescript-test/bin/retest.mjs:19:57
    at ModuleJob.run (internal/modules/esm/module_job.js:146:23) {
  code: 'ERR_MODULE_NOT_FOUND'
}
npm ERR! Test failed.  See above for more details.
bloodyowl commented 3 years ago

Can you try to re-run rescript build -with-deps?

shulhi commented 3 years ago

rescript build -with-deps

Still the same error.

image

This is inside node_modules. I think it has to do with my bsconfig.json where I didn't set in-source to true. I like to keep my source and the generated .bs.js in a different directory.

bloodyowl commented 3 years ago

Indeed the command doesn't handle out of source compilation yet. I'll try to tackle that in the coming days.

bloodyowl commented 3 years ago

@shulhi I just released 3.1.0, which should support out-of-source compilation.

In your case:

$ retest lib/js/test/*.bs.js

should work once updated. Can you confirm it's ok?

JesterXL commented 2 years ago

Sorry for the delay, stuck with the old version. Leaving comment here as this resurfaced recently, so just in case anyone else runs into this.

I actually just got shulhi's error in CI and locally when I changed the suffix from .bs.js to .js and I think it has to do with the files not being compiled. If I run a fresh clean then build then test works good. The error message claims it can't find Test.bs.js or *Test.bs.js, which may be accurate; VSCode at least for me isn't always 100% of what is actually on disk.

Anyway, a fresh clean then build then test seems to consistently fix, and works consistently in CI, and locally you only have to do this once and can just run tests later. Still on CommonJS, hah (it's AWS Lambda's fault....)