Upgrade to mocha 12#4
Merged
GrahamCampbell merged 2 commits intomainfrom Apr 22, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the project’s test runner setup to support Mocha 12 and modernizes related runtime/test harness behavior, including Node.js version gating and more deterministic test isolation.
Changes:
- Switch Mocha execution to a repo-level config (
test/mocha/unit.cjs) with shared bootstrap + root hooks (Chai plugins, env defaults, sandboxed cwd/env, sinon restore). - Refactor Node logging initialization to be an explicit function (improves testability) and adjust tests accordingly.
- Tighten Node.js support checks to a semver range and update CLI messaging, docs, and CI workflows to match.
Reviewed changes
Copilot reviewed 36 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js | Removes per-file sinon-chai setup (now provided by global Mocha bootstrap). |
| test/unit/src/utils/serverless-utils/log-reporters/node.test.js | Updates tests for new initializeNodeLogging({ argv, env, stdin, stdout }) API and avoids global process.env/stdout mutation. |
| test/unit/src/utils/aws/remote-provider.test.js | Removes per-file chai-as-promised/sinon-chai setup (now global). |
| test/unit/src/utils/aws/get-credential-provider.test.js | Removes per-file sinon-chai setup (now global). |
| test/unit/src/utils/aws/get-client-config.test.js | Removes per-file sinon-chai setup (now global). |
| test/unit/src/utils/aws/from-node-provider-chain.test.js | Removes per-file sinon-chai setup (now global). |
| test/unit/src/utils/aws/default-provider.test.js | Removes per-file sinon-chai setup (now global). |
| test/unit/src/state/utils/get-state-bucket-region.test.js | Removes per-file chai-as-promised/sinon-chai setup (now global). |
| test/unit/src/state/utils/get-state-bucket-name.test.js | Removes per-file chai-as-promised/sinon-chai setup (now global). |
| test/unit/src/state/get-s3-state-storage-from-config.test.js | Removes per-file sinon-chai setup (now global). |
| test/unit/src/state/S3StateStorage.test.js | Removes per-file sinon-chai/chai-as-promised setup (now global). |
| test/unit/src/configuration/read.test.js | Removes per-file chai-as-promised setup (now global). |
| test/unit/src/components-service.test.js | Removes per-file chai-as-promised setup (now global). |
| test/unit/src/cli/is-supported-node-version.test.js | Updates unit tests for new semver-based Node support range behavior. |
| test/unit/src/Context.test.js | Small test refactor to create fresh Context instances per test. |
| test/unit/components/framework/index.test.js | Removes redundant Chai plugin wiring and uses chai.expect. |
| test/unit/bin/serverless-compose.test.js | Aligns expectations with new Node support messaging and runComponents(argv) signature. |
| test/mocha/unit.cjs | Adds Mocha config file (spec, requires, timeout, node options). |
| test/mocha/runtime-sandbox.cjs | Adds suite-wide sandbox for cwd/env/argv/EvalError state and cleanup. |
| test/mocha/root-hooks.cjs | Adds Mocha root hooks to restore sandbox state and run sinon.restore(). |
| test/mocha/bootstrap.cjs | Centralizes chai-as-promised/sinon-chai registration and sets env defaults used by tests. |
| test/lib/setup/restore-env.js | Removed (replaced by Mocha root hooks + runtime sandbox). |
| test/lib/setup/patch.js | Removed (replaced by Mocha config/node options and root hooks approach). |
| test/lib/setup/mock-homedir.js | Removed (replaced by runtime sandbox HOME/USERPROFILE handling). |
| test/lib/setup/mock-cwd.js | Removed (replaced by runtime sandbox cwd handling). |
| test/lib/setup/log.js | Removed (test logging behavior no longer injected via old runner patching). |
| src/utils/serverless-utils/log-reporters/node.js | Refactors log initialization into an injectable function and returns derived state. |
| src/state/LocalStateStorage.js | Stops using process.cwd() internally; now uses provided root for state dir. |
| src/index.js | Moves logging setup into runComponents(argv) and passes cwd explicitly to config resolver. |
| src/configuration/resolve-path.js | Accepts an explicit cwd parameter for better testability/control. |
| src/cli/is-supported-node-version.js | Uses semver + exported supported range to validate Node versions. |
| src/Context.js | Ensures root resolution handles missing root more directly; passes root into LocalStateStorage. |
| src/ComponentsService.js | Makes local component path resolution depend on context root instead of process.cwd(). |
| package.json | Switches test command to Mocha config; bumps Mocha to a v12 beta; updates Node engine range; removes inline Mocha config block. |
| bin/serverless-compose | Updates unsupported Node messaging and passes argv explicitly into runComponents. |
| README.md | Updates documented Node.js requirement to the new supported range. |
| .gitignore | Limits lockfile ignores to repo root (/package-lock.json, /yarn.lock). |
| .github/workflows/tests.yml | Updates actions versions, cache strategy, and install command to align with no-lock installs and new Node targets. |
| .github/workflows/publish.yml | Updates actions versions, cache strategy, and install command similarly for publishing pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.