Skip to content

Commit

Permalink
ci: fix unit tests with new serverless version
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianMazur committed Jul 31, 2024
1 parent 3c829f5 commit 632711a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
FORCE_COLOR: 1
PRINT_OFFLINE_OUTPUT: 1
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}

jobs:
build:
Expand Down
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"luxon": "^3.4.4",
"node-schedule": "^2.1.1",
"p-memoize": "^7.1.1",
"tree-kill": "^1.2.2",
"tsx": "^4.16.2",
"velocityjs": "^2.0.6",
"ws": "^8.18.0"
Expand All @@ -114,7 +115,7 @@
"mocha": "^10.6.0",
"nyc": "^17.0.0",
"prettier": "^3.3.2",
"serverless": "^4.1.12"
"serverless": "^4.1.18"
},
"peerDependencies": {
"serverless": "^4.0.0"
Expand Down
31 changes: 16 additions & 15 deletions tests/_testHelpers/setupTeardown.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import process, { env } from "node:process"
import { join } from "desm"
import { execaNode } from "execa"
import { execa } from "execa"
import treeKill from "tree-kill"
import { install, getBinary } from "serverless/binary.js"

let serverlessProcess

const serverlessPath = join(
import.meta.url,
"../../node_modules/serverless/bin/serverless",
)

const shouldPrintOfflineOutput = env.PRINT_OFFLINE_OUTPUT

export async function setup(options) {
await install()
const binary = getBinary()
const { args = [], env: optionsEnv, servicePath, stdoutData } = options

serverlessProcess = execaNode(serverlessPath, ["offline", "start", ...args], {
serverlessProcess = execa(binary.binaryPath, ["offline", "start", ...args], {
cwd: servicePath,
env: optionsEnv,
})
Expand Down Expand Up @@ -61,11 +59,14 @@ export async function setup(options) {
}

export async function teardown() {
serverlessProcess.cancel()

try {
await serverlessProcess
} catch {
//
}
// Forcefully kill the serverless process as it spawns child processes
await new Promise((resolve) => {
treeKill(serverlessProcess.pid, "SIGKILL", (err) => {
if (err) {
console.error("Failed to kill process:", err)
}
resolve()
})
})
serverlessProcess = null
}
2 changes: 0 additions & 2 deletions tests/end-to-end/defaultResponse/src/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
service: uncategorized-tests

frameworkVersion: "3"

plugins:
- ../../../../src/index.js

Expand Down
3 changes: 1 addition & 2 deletions tests/manual/nodejs/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
service: basic

frameworkVersion: "4"

configValidationMode: error
deprecationNotificationMode: error

Expand All @@ -23,6 +21,7 @@ functions:
method: post
path: hello
handler: src/handler.hello
name: hello-${git:branch}

helloTypescript:
events:
Expand Down

0 comments on commit 632711a

Please sign in to comment.