Don't require manually running npm install before the JS tests

This commit is contained in:
Alexandre Archambault 2018-03-12 11:18:20 +01:00
parent c98393838a
commit b1fde7291d
4 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,4 @@
language: java
install:
- npm install
os:
- osx
script:

View File

@ -90,14 +90,9 @@ $ sbt
## Run unit tests (JS)
The JS tests require node to be installed, and a few dependencies to have been
fetched with
```
$ npm install
```
(run from the root of the coursier sources).
The JS tests require node to be installed. They automatically run `npm install` from the root of the coursier sources if needed.
JS tests can then be run like JVM tests, like
JS tests can be run like JVM tests, like
```
$ sbt
> ++2.12.4

View File

@ -41,7 +41,8 @@ lazy val tests = crossProject
.disablePlugins(ScriptedPlugin)
.dependsOn(core, cache % "test", scalaz)
.jsSettings(
scalaJSStage.in(Global) := FastOptStage
scalaJSStage.in(Global) := FastOptStage,
testOptions := testOptions.dependsOn(runNpmInstallIfNeeded).value
)
.configs(Integration)
.settings(

View File

@ -1,4 +1,6 @@
import java.nio.file.Files
import sbt._
import sbt.Keys._
import sbt.ScriptedPlugin.autoImport.{sbtLauncher, scriptedBufferLog, ScriptedLaunchConf, scriptedLaunchOpts}
@ -45,6 +47,28 @@ object Settings {
javacOptions.in(Keys.doc) := Seq()
)
val runNpmInstallIfNeeded = Def.task {
val baseDir = baseDirectory.in(ThisBuild).value
val evFile = baseDir / "node_modules" / ".npm_run"
val log = streams.value.log
if (!evFile.exists()) {
val cmd = Seq("npm", "install")
val b = new ProcessBuilder(cmd: _*)
b.directory(baseDir)
b.inheritIO()
log.info(s"Running ${cmd.mkString(" ")}")
val p = b.start()
val retCode = p.waitFor()
if (retCode == 0)
log.info(s"${cmd.mkString(" ")} ran successfully")
else
sys.error(s"${cmd.mkString(" ")} failed (return code $retCode)")
// Parent dir should have been created by npm install
Files.write(evFile.toPath, Array.emptyByteArray)
}
}
lazy val shared = javaScalaPluginShared ++ Seq(
scalaVersion := scala212,
libs ++= {