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

--reporter does not work with namespaced modules #199

Closed
NicoAiko opened this issue Jun 20, 2022 · 4 comments · Fixed by #209
Closed

--reporter does not work with namespaced modules #199

NicoAiko opened this issue Jun 20, 2022 · 4 comments · Fixed by #209

Comments

@NicoAiko
Copy link

Version: [email protected]
Operating System: Windows 10

This is a similar error to #196 if you ask me.

Likely the root of this problem

Due to loader.js in line 16 checking if the modulePath contains a path separator and for /, it tries to load the module using file:// protocol as (our) reporter contains a slash in its module name.

Line in question:
if (modulePath.indexOf(path.sep) === -1 && modulePath.indexOf('/') === -1) {

Error message:

Error: Failed to load reporter module xxx/yyy
Underlying error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'some absolute path'
// stack error stuff

Workaround:

Like in #196, it's possible to use "jsLoader": "require", but if possible that shouldn't be necessary.

@Kagu-chan
Copy link

Quick side note here: This behavior basicaly occurs when using namespaced node modules.

In our package.json we have:

{
  "scripts": {
    "test": "nyc ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json --reporter=@namespace/jasmine-junit-reporter"
  }
}

The reporter= section causes the issue on our end.

@sgravrock
Copy link
Member

Thanks @Kagu-chan .

I could take a crack at this myself, but I'm not aware of any publicly available reporters that are in namespaces. (I assume the reporters both of you are using are private, since you've both redacted the names or paths.) It would probably be better if someone who actually has this problem, and can therefore verify a fix, would submit a PR.

@Kagu-chan
Copy link

Hi @sgravrock

Thanks for the response - yes, we use a private / namespaced module.
I think just checking for a module starting with @ would not be enough, as there is stuff like rxjs/operators (which doesn't matter here, just for sake of an example - it would still be not found) or aliased imports (which would turn the issue in the exact opposite direction).

May it be an option to load the package.json (if we get the data without any problems) and 'whitelist' modules to load them as we normally would?

I don't know which implications to performance or stability / false positives this would have though...

@sgravrock
Copy link
Member

I think @NicoAiko has it right: the problem is that Jasmine incorrectly treats anything with a slash in it as a relative path. If that was fixed so that only import specifiers starting with ./ or ../ were treated as relative paths, everything should just work.

@sgravrock sgravrock changed the title Jasmine v4 - Failed to load reporter module --reporter does not work with namespaced modules Dec 26, 2022
jan-molak added a commit to jan-molak/jasmine-npm that referenced this issue Jun 20, 2023
jan-molak added a commit to serenity-js/serenity-js that referenced this issue Jun 20, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants