Skip to content

Drop pre-NodeJS 20.x support and add support for NodeJS 24.x and Fix broken tests#1867

Merged
crespowang merged 5 commits intomasterfrom
nodejs24
Feb 7, 2026
Merged

Drop pre-NodeJS 20.x support and add support for NodeJS 24.x and Fix broken tests#1867
crespowang merged 5 commits intomasterfrom
nodejs24

Conversation

@crespowang
Copy link
Copy Markdown
Collaborator

@crespowang crespowang commented Nov 24, 2025

Description

Investigated Test Failures

Problem: Tests were failing with "Unauthorized" errors when running npm test

Root Cause Discovered:

  • Serverless Framework v4 uses a compiled binary (Go) instead of pure JavaScript
  • The binary makes HTTP requests to https://core.serverless.com/api for authentication
  • Nock mocks don't work because they can only intercept requests in the same Node.js
    process, not external binaries
  • The mock API key approach was fundamentally broken

Solution: Switched to using real Serverless API keys for testing


Removed Node.js 14, 16, and 18 Support 🗑️

AWS only supports NodeJS 20+

Key Changes:

  • src/config/supportedRuntimes.js: Removed nodejs14.x, nodejs16.x, nodejs18.x from
    supported runtimes
    • Now only supports: Node.js 20, 22, and 24
  • src/config/constants.js: Updated DEFAULT_LAMBDA_RUNTIME from nodejs14.x → nodejs20.x
  • .github/workflows/nodejs.yml: Updated CI matrix to test only Node.js 20, 22, 24
  • package.json: Updated minimum Node version: >=18.12.0 → >=20.0.0
  • Deleted: tests/integration/docker/nodejs/{nodejs14.x,nodejs16.x,nodejs18.x}/ directories
  • Updated: 71 serverless.yml files changed runtime: nodejs14.x/16.x/18.x → runtime:
    nodejs20.x

Implemented Real API Key Authentication

Problem: Tests needed a way to authenticate with Serverless Framework v4

Solution Implemented:

A. Added Pre-Test Validation (tests/mochaHooks.cjs)

  • Checks if SERVERLESS_ACCESS_KEY environment variable is set before any tests run
  • If not set: immediately exits with process.exit(1) and displays helpful error message
  • Prevents cascading errors from running tests without authentication

B. Updated Test Setup (tests/_testHelpers/setupTeardown.js)

  • Removed hardcoded MOCK_ACCESS_KEY
  • Now reads SERVERLESS_ACCESS_KEY from environment
  • Removed nock mock setup (no longer needed)
  • Simplified code with comment explaining validation happens in mochaHooks

C. Updated CI Workflow (.github/workflows/nodejs.yml)

  • Added SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} to environment
  • Requires GitHub repository secret to be configured

D. Cleaned Up Unused Files

  • Deleted: tests/_testHelpers/serverlessApiMockSetup.cjs (non-functional nock mock)
  • Removed: Unused join import from desm package

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

@crespowang crespowang self-assigned this Nov 24, 2025
This commit modernizes the codebase to support only Node.js 20+ and fixes
test failures caused by Serverless Framework v4's authentication mechanism.

## Summary of Changes

### 1. Removed Node.js 14, 16, and 18 Support (78 files modified)

- Update supported runtimes to Node.js 20, 22, and 24 only
- Remove nodejs14.x, nodejs16.x, nodejs18.x from supportedRuntimes
- Update DEFAULT_LAMBDA_RUNTIME from nodejs14.x to nodejs20.x
- Update package.json minimum Node version: >=18.12.0 → >=20.0.0
- Update CI workflow to test only Node.js 20, 22, 24
- Delete nodejs14.x, nodejs16.x, nodejs18.x test directories
- Update 71 serverless.yml files to use nodejs20.x runtime

### 2. Fixed Test Authentication for Serverless Framework v4

**Root Cause**: Serverless v4 uses a compiled binary that makes HTTP requests
for authentication. Nock mocks cannot intercept requests from external binaries,
only from the same Node.js process.

**Solution**: Require real SERVERLESS_ACCESS_KEY environment variable

- Add pre-test validation in mochaHooks.cjs that exits immediately if key not set
- Update setupTeardown.js to use SERVERLESS_ACCESS_KEY from environment
- Remove non-functional nock mock setup (serverlessApiMockSetup.cjs)
- Add SERVERLESS_ACCESS_KEY to GitHub Actions workflow (requires secret)
- Display helpful error message with instructions when key is missing

### 3. Files Changed

Core configuration:
- src/config/supportedRuntimes.js
- src/config/constants.js
- package.json
- .github/workflows/nodejs.yml

Test infrastructure:
- tests/mochaHooks.cjs (added validation)
- tests/_testHelpers/setupTeardown.js (use real API key)
- tests/_testHelpers/serverlessApiMockSetup.cjs (deleted)

Configuration files:
- 71 serverless.yml files updated across tests/, examples/, and integration tests
- 2 markdown issue templates updated

### How to Run Tests

Locally:
```bash
# Option 1: Login with Serverless
npx serverless login

# Option 2: Set API key directly
export SERVERLESS_ACCESS_KEY=your_key_here

# Run tests
npm test
```

In CI: Add SERVERLESS_ACCESS_KEY to GitHub repository secrets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@crespowang crespowang changed the title feat: Add support for Node.js 24.x Drop pre-NodeJS 20.x support and add support for NodeJS 24.x and Fix broken tests Nov 24, 2025
@darkmavis1980
Copy link
Copy Markdown

Waiting for this PR to be merged as now I can't use serverless-offline with node.js 24, which is now officially supported by AWS

@crespowang
Copy link
Copy Markdown
Collaborator Author

@dherault Is there anything else need to be done to get this merged?

@darkmavis1980
Copy link
Copy Markdown

I tested this branch and it seems to work fine for me, but there are 4 failing checks

cwd: servicePath,
env: {
SERVERLESS_ACCESS_KEY: "MOCK_ACCESS_KEY",
SERVERLESS_ACCESS_KEY: serverlessAccessKey,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to pass an actual serverless key here instead of using a mock?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serverless Framework v4 uses a compiled binary (Go) instead of pure JavaScript
The binary makes HTTP requests to https://core.serverless.com/api for authentication
Nock mocks don't work because they can only intercept requests in the same Node.js
process, not external binaries so the mock API key approach was fundamentally broken

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rukywe
Copy link
Copy Markdown

rukywe commented Feb 5, 2026

Any hopes of getting this merged soon ? :(!

@Samaze123
Copy link
Copy Markdown

Any hopes of getting this merged soon ? :(!

Just for info, if you change in the serverless.yml file runtime: nodejs22.x, it works with node 24.

@darkmavis1980
Copy link
Copy Markdown

Any hopes of getting this merged soon ? :(!

Just for info, if you change in the serverless.yml file runtime: nodejs22.x, it works with node 24.

You shouldn't change it every time just to run it locally, you should set the appropriate version, so when you deploy it, it deploys with Node.js 24

Copy link
Copy Markdown

@darkmavis1980 darkmavis1980 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it works fine, but there are still some tests failing

@crespowang crespowang merged commit f51fe41 into master Feb 7, 2026
5 of 9 checks passed
@crespowang
Copy link
Copy Markdown
Collaborator Author

Now that it is merged, what's the process to release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants