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

Add support for JSDOM JSEnv #456

Merged
merged 11 commits into from
May 29, 2022
Merged

Add support for JSDOM JSEnv #456

merged 11 commits into from
May 29, 2022

Conversation

armanbilge
Copy link
Contributor

@armanbilge armanbilge commented May 27, 2022

Relates to #183 and #212.

Specifically #212 suggests

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

This PR works around that, so no changes are needed upstream. /cc @viktor-podzigun

Copy link
Contributor Author

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

The JSDOM environment runs within a sandbox in Node.js, so it has access to the same APIs via a sandbox-breaking technique. This PR abstracts the existing Node.js support and adds an alternate implementation for JSDOM.

Comment on lines 74 to 81
else if (
globalObject
.hasOwnProperty("navigator")
.asInstanceOf[Boolean] && globalObject.navigator.userAgent
.asInstanceOf[js.UndefOr[String]]
.exists(_.contains("jsdom"))
)
JSDOMFile
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 118 to 120
private[scalajssupport] object JSDOMFile extends NodeLikeFile {
lazy val require = js.Dynamic.global.Node.constructor("return require")()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how we break the JSDOM sandbox. See jsdom/jsdom#2729.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch and elegant solution! Thanks @armanbilge

@ckipp01
Copy link
Member

ckipp01 commented May 27, 2022

Thanks a lot for the pr @armanbilge. Can you target the V2 branch, as all new development is going to be taking place there now since there will be no more stable releases until 2.x is released. I'll try to look at this a bit closer in the coming days as I'm extremely unfamiliar with this, and a bit iffy if we're not actually testing it at all in CI.

@armanbilge
Copy link
Contributor Author

Thanks for the response, can do!

and a bit iffy if we're not actually testing it at all in CI.

Ok, I won't be so lazy then and I'll actually add it to CI 😅 sorry!

@armanbilge armanbilge changed the base branch from main to V2 May 27, 2022 20:26
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.

Again, thanks for the pr @armanbilge. I looked through it all and read up a bit, and I think this all seems totally fine. Just a quick note about docs and then a small question. Then we should be good to go.

@armanbilge armanbilge requested a review from ckipp01 May 28, 2022 13:17
@armanbilge
Copy link
Contributor Author

Thanks for the fast review! :)

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.

I have a couple other small things to take care of, and then I'll cut a new RC with this in. Thanks again @armanbilge!

@ckipp01 ckipp01 merged commit bbe6d53 into scoverage:V2 May 29, 2022
@viktor-podzigun
Copy link
Contributor

Nice 🎉 Thank you!

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.

3 participants