Skip to content

Commit 735f1c6

Browse files
committedAug 28, 2022
Add tests for ExternalJSRun.Config.env
The functionality previously existed, but was untested.
1 parent 9d46d49 commit 735f1c6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎js-envs/src/test/scala/org/scalajs/jsenv/ExternalJSRunTest.scala

+40
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,44 @@ class ExternalJSRunTest {
9090
run.close()
9191
Await.result(run.future, 1.second)
9292
}
93+
94+
private def checkEnvRun(name: String, want: String, config: ExternalJSRun.Config) = {
95+
ExternalJSRun.start(List("node"), config) { stdin =>
96+
val p = new java.io.PrintStream(stdin)
97+
p.println("""const process = require("process");""");
98+
p.println(s"""process.exit(process.env["$name"] !== "$want");""");
99+
p.close()
100+
}
101+
}
102+
103+
@Test
104+
def setEnv: Unit = {
105+
val config = silentConfig
106+
.withEnv(Map("EXTERNAL_JS_RUN_TEST" -> "witness"))
107+
val run = checkEnvRun("EXTERNAL_JS_RUN_TEST", "witness", config)
108+
109+
Await.result(run.future, 1.second)
110+
}
111+
112+
// Confidence tests for checkEnvRun.
113+
114+
@Test
115+
def setEnvWrong: Unit = {
116+
val config = silentConfig
117+
.withEnv(Map("EXTERNAL_JS_RUN_TEST" -> "not-witness"))
118+
val run = checkEnvRun("EXTERNAL_JS_RUN_TEST", "witness", config)
119+
120+
assertFails(run.future) {
121+
case ExternalJSRun.NonZeroExitException(1) => // OK
122+
}
123+
}
124+
125+
@Test
126+
def setEnvMissing: Unit = {
127+
val run = checkEnvRun("EXTERNAL_JS_RUN_TEST", "witness", silentConfig)
128+
129+
assertFails(run.future) {
130+
case ExternalJSRun.NonZeroExitException(1) => // OK
131+
}
132+
}
93133
}

0 commit comments

Comments
 (0)
Please sign in to comment.