refactor: add Configuration.reset() static method#3649
Merged
Conversation
Tests that mutate `process.env` after the global Configuration has been resolved currently have to bypass the public API and reach into either `serviceLocator.reset()` (clears too much by name) or the private `Configuration.globalConfig` field via type assertions. Add `Configuration.reset()` as the discoverable, class-side equivalent — it delegates to `serviceLocator.reset()` so the entire service tree (configuration + event manager + storage client + logger) is dropped together, which is what callers actually want (resetting only the configuration would leave dependents holding the stale instance). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Configuration.reset() static method
B4nan
added a commit
to apify/apify-sdk-js
that referenced
this pull request
May 12, 2026
v4 `Configuration` resolves env vars eagerly at construction, so tests that mutate `process.env` afterwards need to drop the cached singleton. The previous pattern bypassed the public API and poked private static state via type assertions, duplicated across multiple test files. - `Configuration.reset()` clears the SDK's own `globalConfig` static *and* delegates to `serviceLocator.reset()` (matches the upcoming crawlee API in apify/crawlee#3649 — once published the SDK can swap the explicit `serviceLocator.reset()` call for `super.reset()`). - `Actor.reset()` clears `Actor._instance` and calls `Configuration.reset()`. Tests use this single call instead of the three-step boilerplate. - `utils.test.ts` and `actor.test.ts` updated; the awkward inline `(Configuration as unknown as { globalConfig?: ... })` / `(Actor as unknown as { _instance?: ... })` blocks are gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
B4nan
added a commit
to apify/apify-sdk-js
that referenced
this pull request
May 12, 2026
v4 `Configuration` resolves env vars eagerly at construction, so tests that mutate `process.env` afterwards need to drop the cached singleton. The previous pattern bypassed the public API and poked private static state via type assertions, duplicated across multiple test files. - `Configuration.reset()` clears the SDK's own `globalConfig` static *and* delegates to `serviceLocator.reset()` (matches the upcoming crawlee API in apify/crawlee#3649 — once published the SDK can swap the explicit `serviceLocator.reset()` call for `super.reset()`). - `Actor.reset()` clears `Actor._instance` and calls `Configuration.reset()`. Tests use this single call instead of the three-step boilerplate. - `utils.test.ts` and `actor.test.ts` updated; the awkward inline `(Configuration as unknown as { globalConfig?: ... })` / `(Actor as unknown as { _instance?: ... })` blocks are gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
B4nan
added a commit
to apify/apify-sdk-js
that referenced
this pull request
May 12, 2026
…uration crawlee 4.0.0-beta.56 ships `Configuration.reset()` (apify/crawlee#3649), so the SDK's override can delegate to `super.reset()` instead of calling `serviceLocator.reset()` directly. The SDK still owns clearing its own `globalConfig` static and replacing the `AsyncLocalStorage` singleton. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Configuration.reset()as a discoverable static method on the new v4Configurationclass. Delegates toserviceLocator.reset()so the cached configuration, event manager, storage client, and logger are all dropped together.Configuration.reset(), the nextConfiguration.getGlobalConfig()re-readsprocess.env.Motivation
v4
Configurationresolves env vars eagerly at construction, so tests that mutateprocess.envafter the global singleton has been resolved need a way to drop the cached instance. Today that's eitherserviceLocator.reset()(works, but the name suggests "service tree" rather than "the config I just changed env vars for") or reaching into the privateConfiguration.globalConfigvia type assertions (currently happening across multiple test files inapify-sdk-js).A class-side
Configuration.reset()makes the intent obvious from the call site and lives next toConfiguration.getGlobalConfig()in autocomplete. The implementation just delegates toserviceLocator.reset()rather than resetting only the configuration — resetting only the config would leave a staleEventManager/StorageClient/ logger holding the old config, which is the wrong contract for callers wanting to "start fresh".Test plan
vitest run packages/core/test/core/configuration.test.ts -t "reset"🤖 Generated with Claude Code