Skip to content

Commit

Permalink
Add initContext to nodejs (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg committed Nov 3, 2020
1 parent 0d4b3d3 commit ed29047
Show file tree
Hide file tree
Showing 15 changed files with 3,437 additions and 268 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,12 @@ jobs:
- name: Run python test
run: |
make test-python
test_nodejs:
name: Test NodeJS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run NodeJS test
run: |
make test-nodejs
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,17 @@ test-kafka: build-test
$(NUCLIO_DOCKER_TEST_TAG) \
/bin/bash -c "make test-kafka-undockerized"

.PHONY: test-nodejs
test-nodejs:
docker run \
--rm \
--volume $(shell pwd)/pkg/processor/runtime/nodejs/js:/nuclio/nodejs \
--volume $(shell pwd)/test:/nuclio/test \
--workdir /nuclio/nodejs \
--env RUN_MODE=CI \
node:10.20-alpine \
sh -c 'npm install && npm run lint && npm run test'

.PHONY: test-python
test-python:
docker build \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ FROM quay.io/nuclio/processor:${NUCLIO_LABEL}-${NUCLIO_ARCH} as processor
FROM scratch

COPY --from=processor /home/nuclio/bin/processor /home/nuclio/bin/processor
COPY pkg/processor/runtime/nodejs/wrapper.js /home/nuclio/bin/wrapper.js
COPY pkg/processor/runtime/nodejs/js/wrapper.js /home/nuclio/bin/wrapper.js
16 changes: 16 additions & 0 deletions pkg/processor/build/runtime/nodejs/test/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/nuclio/nuclio/pkg/processor/build/runtime/test/suite"
"github.com/nuclio/nuclio/pkg/processor/trigger/http/test/suite"

"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -58,6 +59,9 @@ func (suite *TestSuite) GetFunctionInfo(functionName string) buildsuite.Function
case "long-initialization":
functionInfo.Path = []string{suite.GetTestFunctionsDir(), "common", "long-initialization", "nodejs", "sleepy.js"}

case "context-init-fail":
functionInfo.Path = []string{suite.GetTestFunctionsDir(), "common", "context-init-fail", "nodejs", "contextinitfail.js"}

default:
suite.Logger.InfoWith("Test skipped", "functionName", functionName)
functionInfo.Skip = true
Expand All @@ -66,6 +70,18 @@ func (suite *TestSuite) GetFunctionInfo(functionName string) buildsuite.Function
return functionInfo
}

func (suite *TestSuite) TestBuildWithContextInitializer() {
createFunctionOptions := suite.GetDeployOptions("context-init",
suite.GetFunctionPath(suite.GetTestFunctionsDir(), "common", "context-init", "nodejs", "contextinit.js"))

suite.DeployFunctionAndRequest(createFunctionOptions,
&httpsuite.Request{
RequestMethod: "POST",
RequestBody: "10",
ExpectedResponseBody: "20",
})
}

func TestIntegrationSuite(t *testing.T) {
if testing.Short() {
return
Expand Down
157 changes: 157 additions & 0 deletions pkg/processor/runtime/nodejs/js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"object-curly-spacing": [
"error", "always"
],
"complexity": [
2,
12
],
"curly": [
2,
"all"
],
"eqeqeq": 2,
"guard-for-in": 2,
"no-caller": 2,
"no-eval": 2,
"no-eq-null": 2,
"no-extend-native": 2,
"no-global-assign": 2,
"no-invalid-this": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-new-wrappers": 2,
"no-new": 2,
"no-new-func": 2,
"no-proto": 2,
"no-script-url": 2,
"wrap-iife": 2,
// Strict category
"strict": 0,
// Variables category
"no-shadow": 2,
"no-undef": 2,
"no-unused-vars": 0,
"no-use-before-define": [
2,
{
"functions": false
}
],
// Stylistic Issues category
"array-bracket-spacing": [
2,
"never",
{}
],
"brace-style": [
2,
"1tbs"
],
"camelcase": [
2,
{
"properties": "never"
}
],
"comma-dangle": 0,
"eol-last": 2,
"indent": [
1,
4,
{
"CallExpression": {
"arguments": "first"
},
"FunctionDeclaration": {
"parameters": "first"
},
"ignoreComments": true,
"ignoredNodes": [
"ConditionalExpression"
],
"SwitchCase": 1
}
],
"key-spacing": [
2,
{
"afterColon": true,
"beforeColon": false
}
],
"keyword-spacing": [
2,
{
"before": true
}
],
"max-depth": [
2,
5
],
"max-params": [
2,
20
],
"max-statements": [
2,
50
],
"new-cap": [
2,
{
"newIsCap": false
}
],
"no-bitwise": 2,
"no-multiple-empty-lines": 2,
"no-trailing-spaces": 2,
"operator-linebreak": [
2,
"after"
],
"quotes": [
2,
"single"
],
"semi": 0,
"space-before-blocks": [
2,
"always"
],
"space-before-function-paren": [
2,
{
"anonymous": "always",
"named": "never"
}
],
"space-in-parens": [
2,
"never"
],
"space-infix-ops": 2,
"space-unary-ops": [
2,
{
"nonwords": false,
"overrides": {}
}
],
// ECMAScript 6 category
"require-yield": 0
}
}
Loading

0 comments on commit ed29047

Please sign in to comment.