Skip to content

Drop support for jsdom 9.x. #43

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 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ scala:
jdk:
- openjdk8
env:
- JSDOM_VERSION=9.12.0
- JSDOM_VERSION=10.0.0
- JSDOM_VERSION=16.0.0
install:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
inThisBuild(Seq(
version := "1.0.1-SNAPSHOT",
version := "1.1.0-SNAPSHOT",
organization := "org.scala-js",

crossScalaVersions := Seq("2.12.10", "2.11.12", "2.13.1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,79 +78,46 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
val scriptsURIsJSArray = scriptsURIsAsJSStrings.mkString("[", ", ", "]")
val jsDOMCode = {
s"""
|
|(function () {
| var jsdom = require("jsdom");
|
| if (typeof jsdom.JSDOM === "function") {
| // jsdom >= 10.0.0
| var virtualConsole = new jsdom.VirtualConsole()
| .sendTo(console, { omitJSDOMErrors: true });
| virtualConsole.on("jsdomError", function (error) {
| try {
| // Display as much info about the error as possible
| if (error.detail && error.detail.stack) {
| console.error("" + error.detail);
| console.error(error.detail.stack);
| } else {
| console.error(error);
| }
| } finally {
| // Whatever happens, kill the process so that the run fails
| process.exit(1);
| var virtualConsole = new jsdom.VirtualConsole()
| .sendTo(console, { omitJSDOMErrors: true });
| virtualConsole.on("jsdomError", function (error) {
| try {
| // Display as much info about the error as possible
| if (error.detail && error.detail.stack) {
| console.error("" + error.detail);
| console.error(error.detail.stack);
| } else {
| console.error(error);
| }
| });
|
| var dom = new jsdom.JSDOM("", {
| virtualConsole: virtualConsole,
| url: "http://localhost/",
|
| /* Allow unrestricted <script> tags. This is exactly as
| * "dangerous" as the arbitrary execution of script files we
| * do in the non-jsdom Node.js env.
| */
| resources: "usable",
| runScripts: "dangerously"
| });
| } finally {
| // Whatever happens, kill the process so that the run fails
| process.exit(1);
| }
| });
|
| var window = dom.window;
| window["scalajsCom"] = global.scalajsCom;
| var dom = new jsdom.JSDOM("", {
| virtualConsole: virtualConsole,
| url: "http://localhost/",
|
| var scriptsSrcs = $scriptsURIsJSArray;
| for (var i = 0; i < scriptsSrcs.length; i++) {
| var script = window.document.createElement("script");
| script.src = scriptsSrcs[i];
| window.document.body.appendChild(script);
| }
| } else {
| // jsdom v9.x
| var virtualConsole = jsdom.createVirtualConsole()
| .sendTo(console, { omitJsdomErrors: true });
| virtualConsole.on("jsdomError", function (error) {
| /* This inelegant if + console.error is the only way I found
| * to make sure the stack trace of the original error is
| * printed out.
| */
| if (error.detail && error.detail.stack)
| console.error(error.detail.stack);
| /* Allow unrestricted <script> tags. This is exactly as
| * "dangerous" as the arbitrary execution of script files we
| * do in the non-jsdom Node.js env.
| */
| resources: "usable",
| runScripts: "dangerously"
| });
|
| // Throw the error anew to make sure the whole execution fails
| throw error;
| });
| var window = dom.window;
| window["scalajsCom"] = global.scalajsCom;
|
| jsdom.env({
| html: "",
| virtualConsole: virtualConsole,
| url: "http://localhost/",
| created: function (error, window) {
| if (error == null) {
| window["scalajsCom"] = global.scalajsCom;
| } else {
| throw error;
| }
| },
| scripts: $scriptsURIsJSArray
| });
| var scriptsSrcs = $scriptsURIsJSArray;
| for (var i = 0; i < scriptsSrcs.length; i++) {
| var script = window.document.createElement("script");
| script.src = scriptsSrcs[i];
| window.document.body.appendChild(script);
| }
|})();
|""".stripMargin
Expand Down