This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-nodejs.git


The following commit(s) were added to refs/heads/master by this push:
     new d864a0f  make action invocation cwd the same working dir as where the 
users files live (#69)
d864a0f is described below

commit d864a0f236f174871546368c1c6100d6daa8119c
Author: Eric Weiterman <[email protected]>
AuthorDate: Mon Jul 9 13:27:14 2018 -0400

    make action invocation cwd the same working dir as where the users files 
live (#69)
---
 core/nodejsActionBase/runner.js                    |  2 ++
 .../NodeJsActionContainerTests.scala               | 24 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

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 @@ function NodeActionRunner() {
                 }
 
                 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 @@ abstract class NodeJsActionContainerTests extends 
BasicActionRunnerTests with Ws
     }
   }
 
+  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 = """

Reply via email to