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

deno test - Cannot resolve module #9284

Closed
LukeChannings opened this issue Jan 26, 2021 · 5 comments · Fixed by #9815
Closed

deno test - Cannot resolve module #9284

LukeChannings opened this issue Jan 26, 2021 · 5 comments · Fixed by #9815
Labels
cli related to cli/ dir

Comments

@LukeChannings
Copy link
Contributor

λ deno --version
deno 1.7.0+ada43cc (canary, x86_64-apple-darwin)
v8 8.9.255.3
typescript 4.1.3

I have an import map:

{
  "imports": {
    "/": "./",
  }
}

My program runs correctly with:

deno run -A --unstable --import-map=./import_map.json ./cmd/moviematch/main.ts

I have a simple test file:

import { assertEquals } from "https://deno.land/std@0.84.0/testing/asserts.ts";

import { getDirectories } from "/internal/app/plex/api.ts";

Deno.test("getDirectories", async () => {
 // test getDirectories
});

When I run:

λ deno test --import-map ./import_map.json -A --unstable

I get:

Check file:///Users/luke/Developer/MovieMatch/$deno$test.ts
error: Cannot resolve module "file:///Users/luke/Developer/MovieMatch/Users/luke/Developer/MovieMatch/internal/app/plex/api_test.ts" from "file:///Users/luke/Developer/MovieMatch/$deno$test.ts".

Things I've tried:

  • Moving the test into a standalone test folder and selecting it with deno test --import-map ./import_map.json -A --unstable tests
  • Importing the source relatively (works, but absolute imports are used throughout so it fails further on)

Why is the behaviour of deno test different to deno run?

@kitsonk
Copy link
Contributor

kitsonk commented Jan 26, 2021

deno test creates a "synthetic" module which imports all the test modules it find, that is why the behaviour is different.

@nayeemrmn
Copy link
Collaborator

I was going to say we should reconsider a non-file URL for $deno$test.ts so it's not subject to this, but $deno$eval.ts and $deno$repl.ts etc. can't be helped because we want relative specifiers to work for them.

I think the fake module specifier we use should be put through the import map, and the result of that should be passed to insert_cached() instead.

@kitsonk
Copy link
Contributor

kitsonk commented Jan 27, 2021

I think the fake module specifier we use should be put through the import map, and the result of that should be passed to insert_cached() instead.

That sounds reasonable.

@kitsonk kitsonk added the cli related to cli/ dir label Jan 27, 2021
@caspervonb
Copy link
Contributor

If #9662 ends up landing we'll be removing the synthetic test module as a side effect.

@LukeChannings
Copy link
Contributor Author

LukeChannings commented Mar 4, 2021

As a side note, I've found that I can work around this issue by being more specific with aliases:

{
  "imports": {
    "/internal/": "../internal/",
    "/types/": "../types/"
  }
}

(paths are ../ because I keep my import_map.json in ./configs)

I'm not sure why this works, but it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants