Skip to content

Fixed #183: JSDOMNodeJSEnv is handled incorrectly (Scalajs support) #212

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

Merged
merged 1 commit into from
May 11, 2021

Conversation

viktor-podzigun
Copy link
Contributor

@viktor-podzigun viktor-podzigun commented Jan 8, 2018

Fixes #183

UPDATED! Original PR description:

In this PR made attempt to correctly identify Node.js environments (with or without jsdom).

In order to detect Node.js environment I'm using the global object (approach, suggested here):

if (js.typeOf(g.global) == "object" && js.typeOf(g.global.require) == "function") {
    // Node.js environment detected
    NodeFile
}

It doesn't break existing logic and it is a step forward to fixing #183.

There should be also a corresponding change applied for JSDOMNodeJSEnv class in scala-js/scalajs-bundler to export global object, either by extending it with a setting to do so, or by creating separate implementation (see discussion here).

@viktor-podzigun
Copy link
Contributor Author

Hi @gslowikowski, could you, please, take a look to this PR when you will have some time?

Since there is a strong demand to make scoverage work for UI testing in scala-js using Node.js/jsdom env, it would be really great if we could make it work at least from scoverage side.

Thanks!

@nimaeskandary
Copy link

Any updates on this?

@gslowikowski
Copy link
Member

Hi

I've created simple project with jsdom env https://github.com/gslowikowski/scoverage-scalajs-node-jsdom-example, but JS module tests fail when building with the version of scoverage plugin from this pull request.

Maybe I'm doing something wrong. @viktor-podzigun can you help me to verify your PR?

@viktor-podzigun
Copy link
Contributor Author

Hi @gslowikowski,
thank you for taking care of it.

I've made PR to your test project with some changes, please, see my comments in build.sbt file:
https://github.com/gslowikowski/scoverage-scalajs-node-jsdom-example/pull/1/files

I think we would need to make one more PR to make it work with JSDOMNodeJSEnv, as the one I've made for scalajs-bundler

@ckipp01
Copy link
Member

ckipp01 commented May 10, 2021

@viktor-podzigun I know this has been stale for quite some time, but is this still relevant? If so, are you able to rebase?

@viktor-podzigun
Copy link
Contributor Author

@ckipp01 I've re-based it already.

And, yes, I think, its still relevant. As you can see, the PhantomFile js environment is assumed by the window global var, which is not always correct. As described in the original linked issue #183 , the node.js + jsdom env. would resolve to phantom!

@viktor-podzigun
Copy link
Contributor Author

viktor-podzigun commented May 11, 2021

@ckipp01 ok, re-based it one more time on the latest main branch

@ckipp01
Copy link
Member

ckipp01 commented May 11, 2021

@ckipp01 I've re-based it already.

And, yes, I think, its still relevant. As you can see, the PhantomFile js environment is assumed by the window global var, which is not always correct. As described in the original linked issue #183 , the node.js + jsdom env. would resolve to phantom!

gslowikowski/scoverage-scalajs-node-jsdom-example#1 (comment)

From this comment though, which has already been a couple years ago, it seems that this is sort of no longer a thing?

@viktor-podzigun
Copy link
Contributor Author

@ckipp01 maybe Phantom is no longer a thing, but that's exactly why we should make it work with node.js in the first place :) and that is this change proposed here is all about. The thing is, that when we install jsdom in node.js env. it is detected as Phantom atm.

@ckipp01
Copy link
Member

ckipp01 commented May 11, 2021

@ckipp01 maybe Phantom is no longer a thing, but that's exactly why we should make it work with node.js in the first place :) and that is this change proposed here is all about. The thing is, that when we install jsdom in node.js env. it is detected as Phantom atm.

ahhhh, totally misunderstood that. Thanks for clarifying.

Copy link
Member

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pr @viktor-podzigun and sorry it's stood still for so long. LGTM

@ckipp01 ckipp01 merged commit bf081e1 into scoverage:main May 11, 2021
@viktor-podzigun viktor-podzigun deleted the fix_183 branch May 11, 2021 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSDOMNodeJSEnv is handled incorrectly (Scalajs support issue)
4 participants