rtfeldman/node-test-runner

RuntimeError: unreachable

Closed this issue · 14 comments

In a new project, started with npm init and elm init

When upgrading to version 0.19.1-revision8 from 0.19.1-revision7 I get error

$ npx elm-test

RuntimeError: unreachable

package.json

{
  "name": "delme",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "elm-test"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "elm-test": "0.19.1-revision8"
  }
}

elm.json

{
    "type": "application",
    "source-directories": [
        "src"
    ],
    "elm-version": "0.19.1",
    "dependencies": {
        "direct": {
            "elm/browser": "1.0.2",
            "elm/core": "1.0.5",
            "elm/html": "1.0.0",
            "elm-explorations/test": "2.0.1"
        },
        "indirect": {
            "elm/bytes": "1.0.8",
            "elm/json": "1.1.3",
            "elm/random": "1.0.0",
            "elm/time": "1.0.0",
            "elm/url": "1.0.0",
            "elm/virtual-dom": "1.0.3"
        }
    },
    "test-dependencies": {
        "direct": {},
        "indirect": {}
    }
}

$ node -v
v16.11.0

Using M1 mac with MacOS v 12.6

Same error with 0.19.1-revision9 as well.

Hi! That’s odd!

I tried your example repo on M1 mac with MacOS v12.6 and Node.js 16:

❯ npx elm-test

The "source-directories" field in your elm.json lists the following directory:

/Users/simon/stuff/elm-test-error/src

It doesn't exist though. Is it missing? Is there a typo?

I then created the missing src directory and got:

❯ npx elm-test
Compiling > Starting tests

elm-test 0.19.1-revision8
-------------------------

Running 1 test. To reproduce these results, run: elm-test --fuzz 100 --seed 149470965090435


TEST RUN INCOMPLETE because there is 1 TODO remaining

Duration: 64 ms
Passed:   0
Failed:   0
Todo:     1
↓ Example
◦ TODO: Implement our first test. See https://package.elm-lang.org/packages/elm-explorations/test/latest for how to do this!

I wonder why you are seeing something different! 🤔

i was also running into this yesterday trying to upgrade to revision10 in an existing project, tracked it down to something happening in elm-deps-resolve-wasm or whatever it's called and gave up and reverted back to revision9.

I'm running an intel mac.

diff of changes

diff --git a/ui/elm.json b/ui/elm.json                                                                                                                                             
index ad9ea583b..7f15cb970 100644
--- a/ui/elm.json
+++ b/ui/elm.json
@@ -43,7 +43,7 @@
     },
     "test-dependencies": {
         "direct": {
-            "elm-explorations/test": "1.2.2"
+            "elm-explorations/test": "2.0.1"
         },
         "indirect": {}
     }
diff --git a/ui/package.json b/ui/package.json
index 4fc390ae8..a8559eab5 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -22,7 +22,7 @@
     "elm": "0.19.1-5",
     "elm-format": "^0.8.5",
     "elm-review": "^2.7.5",
-    "elm-test": "^0.19.1-revision9",
+    "elm-test": "^0.19.1-revision10",
     "sass": "^1.55.0",
     "vite": "^3.1.7",
     "vite-plugin-elm": "^2.7.2"

results of running elm-test:

$ yarn elm-test     
yarn run v1.22.19

RuntimeError: unreachable
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Interestingly I also get unreachable on a fresh checkout of girisho's test repo. Though you need to yarn add -D elm and mkdir src to get it to run:

$ yarn elm-test
yarn run v1.22.19
$ /Users/greg/trash/elm-test-error/node_modules/.bin/elm-test

RuntimeError: unreachable
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

With npx:

$ npx elm-test

RuntimeError: unreachable

It has something to do with dependency resolution. I just blew away my ~/.elm directory, re-ran and it worked. I suggest @girishso back-up and zip your ~/.elm directory and upload it somewhere if folks want to solve this problem.

Interesting!

One thing that would be helpful for me, is if you could temporarily edit node_modules/elm-test/lib/elm-test.js at the very close to the bottom like so:

      ).then(
        (code) => process.exit(code),
        (error) => {
-          console.error(error.message);
+          console.error(error);
          process.exit(1);
        }
      );

That way we’ll get to see the stack trace as well.

@lydell console.error(error) didn't help.

I have figured out where the error happens.

program
    // Hack: This command has a name that isn’t likely to exist as a directory
    // containing tests. If the command were instead called "tests" then
    // commander would interpret the `tests` in `elm-test tests src` as a
    // command and only run tests in `src/`, ignoring all files in `tests/`.
    .command('__elmTestCommand__ [globs...]', { hidden: true, isDefault: true })
    .action((testFileGlobs) => {
      const options = program.opts();
      const pathToElmBinary = getPathToElmBinary(options.compiler);
      const projectRootDir = getProjectRootDir('tests');
      const processes = Math.max(1, os.cpus().length);
      RunTests.runTests(
        dependencyProvider,
        projectRootDir,
        pathToElmBinary,
        testFileGlobs,
        processes,
        options
      ).then(
        (code) => process.exit(code),
        (error) => {
          console.error('rt')
          console.error(error);
          process.exit(1);
        }
      );
    });

When I comment out code above, it prints out usage help, uncommented code results in RuntimeError: unreachable. Hope this helps

As @greg-enbala mentioned deleting ~/.elm did work. I have uploaded my old .elm folder here https://www.dropbox.com/s/2d2sgfzzfdy1k96/dotelm.zip?dl=0

My sample repo didn't have src folder, fixed it now.

happening in elm-deps-resolve-wasm or whatever

@mpizenberg is this a panic in the rust code?

oooo, I'm getting the following error with the provided .elm/:

Solution for test dependencies:
panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { full_version: "1.0.2-o", version_part: "2-o", parse_error: "invalid digit found in string" }', src/lib.rs:98:66

And it seems this elm home contains a folder .../elm/browser/1.0.2-o which makes the version parser crash 🤦 . I guess I made the simplifying assumption that versions there would be correct, and I must have forgotten to robustify this during integration with node-test-runner.

❯ rg "unwrap\("
src/lib.rs
34:  utils::WasmLogger::init().unwrap();
    -> this one is fine, it's the logger initialization
98:  Ok(versions.into_iter().map(|v| SemVer::from_str(&v).unwrap()))
    -> this is the one crashing
119: let solution_json = serde_json::to_string(&solution).unwrap();
    -> this one is fine, it's just json-stringifying a valid solution

Ok it's fixed now, I just have filter_map instead of map:

versions.into_iter().filter_map(|v| SemVer::from_str(&v).ok())

I'll publish a new version of elm-solve-deps-wasm, so that this is fixed in the next version of node-test-runner.
Meanwhile, it is also possible to fix this on the JS side, by filtering out invalid version number folders in the elm home in the dependency provider of node-test-runner.

I'll publish a new version of elm-solve-deps-wasm, so that this is fixed in the next version of node-test-runner.

We depend on elm-solve-deps-wasm like so:

"elm-solve-deps-wasm": "^1.0.1"

So unless you bump to 2.0.0, no new node-test-runner release should be necessary.

Oh nice, good then, the fix has been published with version 1.0.2 just now