Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
refactor: add `Configuration.reset()` static method (#3649)
Martin Adámek63ef023efac4
diff --git a/packages/core/src/configuration.ts b/packages/core/src/configuration.tsindex fa2e275a7..457e93589 100644--- a/packages/core/src/configuration.ts+++ b/packages/core/src/configuration.ts@@ -205,6 +205,21 @@ export class Configuration {return serviceLocator.getConfiguration();}+ /**+ * Resets the global configuration (and the rest of the global service locator) so that the+ * next `Configuration.getGlobalConfig()` call constructs a fresh instance from the current+ * environment. Intended mainly for tests that mutate `process.env` at runtime — values are+ * resolved eagerly at construction, so changing env vars after the singleton has been+ * cached has no effect until the singleton is dropped.+ *+ * Delegates to {@link ServiceLocator.reset} since the global configuration is owned by the+ * service locator; resetting only the configuration would leave a stale `EventManager` /+ * `StorageClient` / logger holding the old config.+ */+ static reset(): void {+ serviceLocator.reset();+ }+/*** Resolves all field values once using the priority chain:* constructor options > env vars > crawlee.json > schema defaults.diff --git a/packages/core/test/core/configuration.test.ts b/packages/core/test/core/configuration.test.tsindex a382e8a41..2c1f3baa5 100644--- a/packages/core/test/core/configuration.test.ts+++ b/packages/core/test/core/configuration.test.ts@@ -317,4 +317,18 @@ describe('Configuration', () => {expect((config2 as any).customFlag).toBe(true);});});++ describe('reset()', () => {+ it('drops the cached global instance so the next `getGlobalConfig()` re-reads env vars', () => {+ setEnv('CRAWLEE_DEFAULT_DATASET_ID', 'first');+ expect(Configuration.getGlobalConfig().defaultDatasetId).toBe('first');++ // Without resetting, the singleton keeps the value resolved at first access.+ setEnv('CRAWLEE_DEFAULT_DATASET_ID', 'second');+ expect(Configuration.getGlobalConfig().defaultDatasetId).toBe('first');++ Configuration.reset();+ expect(Configuration.getGlobalConfig().defaultDatasetId).toBe('second');+ });+ });});