scalajs-bundler
scalajs-bundler copied to clipboard
`testHtmlFastOpt` and `testHtmlFullOpt` use incorrect file
The HTML that gets generated uses [name]-test-[stage].js vs [name]-test-[stage]-bundle.js. It looks like it's looking at fastOptJS in testHtmlFastOpt for the file name. I made a quick fix in my own project, and would contribute it back but I don't really see where the bundle is named. Obviously it's fairly hacky.
fastOptJS in testHtmlFastOpt in Test := {
val f = (fastOptJS in testHtmlFastOpt in Test).value
val fd = new File(f.data.getPath.stripSuffix(".js") + "-bundle.js")
f.copy(fd)(f.metadata)
}
Thanks for reporting.
The bundle files are returned by the webpack command. I think the right implementation would be something like the following:
fastOptJS in testHtmlFastOpt in Test := {
(webpack in fastOptJS).value match {
case Seq(bundle) => Attributed(bundle)((fastOptJS in testHtmlFastOpt).value.metadata)
case _ => sys.error("testHtmlFastOpt task supports only exactly one bundle")
}
}
What do you think? (Or maybe just Attributed.blank(bundle))
I like this much better, I haven't tested it though. Shall I make the change on the website?
What do you mean by “the website”?
In the cookbooks sections. Or, is this something that you fix in the plugin?
That would be great if you could directly fix the plugin :)
You should add it to this list (and you should add a similar setting for testHtmlFullOpt, I think) and then add the following lines > testHtmlFastOpt and > testHtmlFullOpt at the end of this file.
On it!
Is this related to https://github.com/scalacenter/scalajs-bundler/issues/38 ? I'm getting "ReferenceError: exports is not defined" when trying to run tests with scala js bundler and jsdom... It seems that both tickets refer to this issue?
@raquo Are you using the testHtmlFastOpt task? Just running the tests with test should work if you added requiresDOM in Test := true to your build.
Thanks! I think I was using the test command with jsDependencies += RuntimeDOM % Test instead of the requiresDOM line you mentioned. Although I did try testHtmlFastOpt with the same result. Eventually I found this example https://github.com/scalacenter/scalajs-bundler/tree/master/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static and now I'm using the config as you've suggested, and it works.
I'm now getting the same exports is not defined problem when trying to run tests with selenium using the test command. Is that this same bug manifesting, or does this look like an issue with scalajs-env-selenium? Or maybe I'm doing something wrong?
The relevant build.sbt part is:
persistLauncher in Test := false
requiresDOM in Test := true
jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(org.scalajs.jsenv.selenium.Chrome())
(without the last line it works fine)
The workaround mentioned in the first post doesn't have any effect, I'm guessing because testHtmlFastOpt command is not run. Replacing fastOptJS in testHtmlFastOpt in Test with fastOptJS in Test also doesn't work as this creates incorrectly names files (-bundle-bundle.js)
PS sorry for hijacking this issue, it seems like it might be the same problem.
It might be the same issue, indeed… This would require a bit of investigation.
I am also getting the same exports is not defined error with jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(org.scalajs.jsenv.selenium.Chrome()).
Getting same problem with @ramnivas
I am getting the same Problem in my project
@raquo Hmm why would you have requiresDOM in Test if using Selenium as your JSEnv? Doesn't the latter provide that inherently? I thought the former's role was solely to download jsdom module.
If you compare the loaders for the web app vs a test you see the following:
runner
var exports = window;
exports.require = window["ScalaJSBundlerLibrary"].require;
test
{
var x0 = require("/project/target/scala-2.12/scalajs-bundler/test/project-test-fastopt.js");
Object.keys(x0).forEach((function(x1) {
return window[x1] = x0[x1]
}))
}
Why do we define exports in the one but not the other?
I also run into this issue. I am unable to run any tests now. It is not related to Selenium. it looks like what @matthughes said that the test loader is not including i.e. the -bundle version?
In my very specific case I was able to fix the error by removing this line:
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
and adding this one:
requireJsDomEnv in Test := true
Then a correct codeWithJSDOMContext.js was created in scalajs-bundler-jsdom and now the tests work.
Has there been any progress on this? Facing the same issue (ReferenceError: exports is not defined) and requireJsDomEnv in Test := true does not seem to fix it.
I believe this should be fixed when using Scala.js 1.x, with
requireJsDomEnv in Test := true
and with the task testHtml (which replaces testHtmlFastOpt and testHtmlFullOpt of Scala.js 0.6.x).
Alright thanks. I am still using Scala.js 0.6 so I guess I'll have to try to update. :)
Unfortunately we cannot update to Scala.js 1.0.1 yet since too many dependencies are still on 0.6. I'll need to look for a different solution. Thanks anyway @sjrd .