Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8291D200CAA for ; Sat, 3 Jun 2017 02:26:34 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 80CCC160BDD; Sat, 3 Jun 2017 00:26:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C79BF160BD2 for ; Sat, 3 Jun 2017 02:26:33 +0200 (CEST) Received: (qmail 79750 invoked by uid 500); 3 Jun 2017 00:26:33 -0000 Mailing-List: contact commits-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list commits@openwhisk.apache.org Received: (qmail 79740 invoked by uid 99); 3 Jun 2017 00:26:33 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Jun 2017 00:26:33 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id E3EB9868BF; Sat, 3 Jun 2017 00:26:31 +0000 (UTC) Date: Sat, 03 Jun 2017 00:26:31 +0000 To: "commits@openwhisk.apache.org" Subject: =?utf-8?q?=5Bincubator-openwhisk-devtools=5D_branch_master_updat?= =?utf-8?q?ed=3A_added_script_to_node-local_testing_for_running_test=2Ejs_?= =?utf-8?b?dmlhIHRoZSBhY3Rpb27igKYgKCMzOCk=?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <149644959169.15072.12013726172453372810@gitbox.apache.org> From: dragos@apache.org Reply-To: "commits@openwhisk.apache.org" X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-openwhisk-devtools X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 5b1fd7bfe0dab5b76bfcb8d8b0192eb3bbda4221 X-Git-Newrev: 2aa67e35a3dfc42fc5e2b926854e4f7d604ba622 X-Git-Rev: 2aa67e35a3dfc42fc5e2b926854e4f7d604ba622 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.3.dev Auto-Submitted: auto-generated archived-at: Sat, 03 Jun 2017 00:26:34 -0000 This is an automated email from the ASF dual-hosted git repository. dragos pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git The following commit(s) were added to refs/heads/master by this push: new 2aa67e3 added script to node-local testing for running test.js via the action… (#38) 2aa67e3 is described below commit 2aa67e35a3dfc42fc5e2b926854e4f7d604ba622 Author: tysonnorris AuthorDate: Fri Jun 2 17:26:30 2017 -0700 added script to node-local testing for running test.js via the action… (#38) * added script to node-local testing for running test.js via the action container itself, so that npm libraries can be tested more simply * avoiding merge conflict; JSON output was added by another PR * fixing multiple params --- node-local/README.md | 18 +++++++++++++++- node-local/runtest.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ node-local/test.js | 11 +++++++--- 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/node-local/README.md b/node-local/README.md index 1ec15b5..f59190e 100644 --- a/node-local/README.md +++ b/node-local/README.md @@ -24,4 +24,20 @@ cat input.json | node test.js ./path-to-function.js If you intend to post-process the result, for instance with `jq`, add the parameter `--json`, which will make sure `test.js` returns well-formed JSON. The default is off, which means you -will get a slightly more readable output. \ No newline at end of file +will get a slightly more readable output. + +## using npm libraries + +If your action uses npm libraries, you may have trouble running it locally without creating a special environment just for it to run. + +In this case you can run the docker image that open whisk uses to launch your action, along with its preinstalled libraries: + +```bash +./runtest.sh --debug --action ./path-to-function.js --param name=value --param othername=othervalue +``` + +Usage: +* --debug : enable request debugging (by adding NODE_DEBUG=request) +* --action : action js file you are trying to test +* --param : parameter to pass to main (multiple allowed) +* --image : the action image used to run node (default is openwhisk/nodejs6action:latest) diff --git a/node-local/runtest.sh b/node-local/runtest.sh new file mode 100755 index 0000000..444a740 --- /dev/null +++ b/node-local/runtest.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +abs_path() +{ + pushd $(dirname "$1") > /dev/null + echo $(pwd)/$(basename "$1") + popd > /dev/null + +} + +this_dir=$(dirname "$(abs_path "$0")") +action_executor="$this_dir/test.js" +action_image="openwhisk/nodejs6action:latest" +debug_env="debug_disabled" + + +while [[ $# -gt 1 ]] +do +key="$1" + +case $key in + --action) + action="$(abs_path "$2")" + shift # past argument + ;; + --param) + params+=" $2" + shift # past argument + ;; + --image) + actionimage="$2" + shift # past argument + ;; + --debug) + debug_env="NODE_DEBUG=request" + ;; + *) + # unknown option + ;; +esac +shift # past argument or value +done + +echo "#######################################################" +echo "Testing action $action using image $action_image" +echo "#######################################################" + + + +docker_cmd="docker run --name=\"actiontest\" --rm -it \ + -e \"$debug_env\" \ + -v \"$action_executor:/nodejsAction/testexecutor.js\" \ + -v \"$action:/nodejsAction/testaction.js\" \ + $action_image node testexecutor.js ./testaction.js $params" + +#using eval here because $params may have multiple space separate values, which need to be passed as separate args +eval "$docker_cmd" diff --git a/node-local/test.js b/node-local/test.js index 63f4bda..416f368 100644 --- a/node-local/test.js +++ b/node-local/test.js @@ -77,12 +77,11 @@ function run(action, params, outputJSON) { } const imports = require(action); - + //support a non-exported main function as a fallback const mainfunct = imports.main ? imports.main : fallback(action); let result = mainfunct(params); - if (result.then) { Promise.resolve(result) .then(result => console.log(outputJSON ? JSON.stringify(result) : result)) @@ -90,4 +89,10 @@ function run(action, params, outputJSON) { } else { console.log(outputJSON ? JSON.stringify(result) : result); } -} \ No newline at end of file +} + +//allow ctrl-c to exit... +process.on('SIGINT', function() { + console.log("exiting..."); + process.exit(); +}); \ No newline at end of file -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" '].