make action invocation cwd the same working dir as where the users files live (#69)
diff --git a/core/nodejsActionBase/runner.js b/core/nodejsActionBase/runner.js
index 43893f5..ea869be 100644
--- a/core/nodejsActionBase/runner.js
+++ b/core/nodejsActionBase/runner.js
@@ -58,6 +58,8 @@
}
try {
+ // Set the executable directory to the project dir
+ process.chdir(moduleDir);
thisRunner.userScriptMain = eval('require("' + moduleDir + '").' + message.main);
assertMainIsFunction();
// The value 'true' has no special meaning here;
diff --git a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
index 2cb4906..a5a136f 100644
--- a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
@@ -537,6 +537,30 @@
}
}
+ it should "set correct cwd for zipped actions" in {
+ val srcs = Seq(
+ Seq("package.json") -> examplePackageDotJson,
+ Seq("test.txt") -> "test text",
+ Seq("index.js") -> s"""
+ | const fs = require('fs');
+ | exports.main = function (args) {
+ | const fileData = fs.readFileSync('./test.txt').toString();
+ | return { result1: fileData,
+ | result2: __dirname === process.cwd() };
+ | }
+ """.stripMargin)
+
+ val code = ZipBuilder.mkBase64Zip(srcs)
+
+ withNodeJsContainer { c =>
+ c.init(initPayload(code))._1 should be(200)
+
+ val (runCode, runRes) = c.run(runPayload(JsObject()))
+ runRes.get.fields.get("result1") shouldBe Some(JsString("test text"))
+ runRes.get.fields.get("result2") shouldBe Some(JsBoolean(true))
+ }
+ }
+
it should "support default function parameters" in {
val (out, err) = withNodeJsContainer { c =>
val code = """