From 1b2193459609e128522568c67fc83ccddfd8d146 Mon Sep 17 00:00:00 2001 From: Benny Chew Date: Wed, 4 Dec 2024 17:40:33 +1100 Subject: [PATCH] feat: add support for nodejs22.x runtime (#1837) Co-authored-by: MazurDorian --- src/config/supportedRuntimes.js | 2 + .../docker/multiple/serverless.yml | 8 ++++ .../nodejs22.x/dockerNodejs22.x.test.js | 37 +++++++++++++++++++ .../docker/nodejs/nodejs22.x/handler.js | 16 ++++++++ .../docker/nodejs/nodejs22.x/serverless.yml | 30 +++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 tests/integration/docker/nodejs/nodejs22.x/dockerNodejs22.x.test.js create mode 100644 tests/integration/docker/nodejs/nodejs22.x/handler.js create mode 100644 tests/integration/docker/nodejs/nodejs22.x/serverless.yml diff --git a/src/config/supportedRuntimes.js b/src/config/supportedRuntimes.js index c0fbc3a85..4eaa691a5 100644 --- a/src/config/supportedRuntimes.js +++ b/src/config/supportedRuntimes.js @@ -15,6 +15,7 @@ export const supportedRuntimesArchitecture = { "nodejs16.x": [ARM64, X86_64], "nodejs18.x": [ARM64, X86_64], "nodejs20.x": [ARM64, X86_64], + "nodejs22.x": [ARM64, X86_64], "python3.7": [X86_64], "python3.8": [ARM64, X86_64], "python3.9": [ARM64, X86_64], @@ -47,6 +48,7 @@ export const supportedNodejs = new Set([ "nodejs16.x", "nodejs18.x", "nodejs20.x", + "nodejs22.x", ]) // PROVIDED diff --git a/tests/integration/docker/multiple/serverless.yml b/tests/integration/docker/multiple/serverless.yml index 8d34c43a9..a924b0ea9 100644 --- a/tests/integration/docker/multiple/serverless.yml +++ b/tests/integration/docker/multiple/serverless.yml @@ -44,3 +44,11 @@ functions: path: hello3 handler: handler.hello runtime: python3.8 + + hello4: + events: + - http: + method: get + path: hello4 + handler: handler.hello + runtime: nodejs22.x diff --git a/tests/integration/docker/nodejs/nodejs22.x/dockerNodejs22.x.test.js b/tests/integration/docker/nodejs/nodejs22.x/dockerNodejs22.x.test.js new file mode 100644 index 000000000..e7e85179f --- /dev/null +++ b/tests/integration/docker/nodejs/nodejs22.x/dockerNodejs22.x.test.js @@ -0,0 +1,37 @@ +import assert from "node:assert" +import { env } from "node:process" +import { join } from "desm" +import { setup, teardown } from "../../../../_testHelpers/index.js" +import { BASE_URL } from "../../../../config.js" + +describe("Node.js 22.x with Docker tests", function desc() { + beforeEach(() => + setup({ + servicePath: join(import.meta.url), + }), + ) + + afterEach(() => teardown()) + ;[ + { + description: "should work with nodejs22.x in docker container", + expected: { + message: "Hello Node.js 22.x!", + }, + path: "/dev/hello", + }, + ].forEach(({ description, expected, path }) => { + it(description, async function it() { + // "Could not find 'Docker', skipping tests." + if (!env.DOCKER_DETECTED) { + this.skip() + } + + const url = new URL(path, BASE_URL) + const response = await fetch(url) + const json = await response.json() + + assert.equal(json.message, expected.message) + }) + }) +}) diff --git a/tests/integration/docker/nodejs/nodejs22.x/handler.js b/tests/integration/docker/nodejs/nodejs22.x/handler.js new file mode 100644 index 000000000..a865d8d54 --- /dev/null +++ b/tests/integration/docker/nodejs/nodejs22.x/handler.js @@ -0,0 +1,16 @@ +"use strict" + +// eslint-disable-next-line unicorn/prefer-node-protocol +const { versions } = require("process") + +const { stringify } = JSON + +module.exports.hello = async () => { + return { + body: stringify({ + message: "Hello Node.js 22.x!", + version: versions.node, + }), + statusCode: 200, + } +} diff --git a/tests/integration/docker/nodejs/nodejs22.x/serverless.yml b/tests/integration/docker/nodejs/nodejs22.x/serverless.yml new file mode 100644 index 000000000..eed8b1aa9 --- /dev/null +++ b/tests/integration/docker/nodejs/nodejs22.x/serverless.yml @@ -0,0 +1,30 @@ +service: docker-nodejs22-x-test + +configValidationMode: error +deprecationNotificationMode: error + +plugins: + - ../../../../../src/index.js + +provider: + architecture: x86_64 + deploymentMethod: direct + memorySize: 1024 + name: aws + region: us-east-1 + runtime: nodejs22.x + stage: dev + versionFunctions: false + +custom: + serverless-offline: + noTimeout: true + useDocker: true + +functions: + hello: + events: + - http: + method: get + path: hello + handler: handler.hello