Skip to content

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.

1.0 KB
Raw Blame
import { Dataset, MemoryStorageBackend, serviceLocator } from '@crawlee/core';

beforeEach(async () => {
    serviceLocator.setStorageBackend(new MemoryStorageBackend());
});

describe('StorageManager', () => {
    test('failed openStorage call does not block subsequent calls (#3661)', async () => {
        // A real instance, so every method the open path calls (`purge`, `getStorageBackendCacheKey`)
        // operates on its own state - only the failing call is stubbed.
        const failingBackend = Object.assign(new MemoryStorageBackend(), {
            createDatasetBackend: () => {
                throw new Error('boom');
            },
        });

        await expect(Dataset.open('will-fail', { storageBackend: failingBackend as any })).rejects.toThrow('boom');

        await expect(
            Promise.race([
                Dataset.open('fallback'),
                new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 1000)),
            ]),
        ).resolves.toBeDefined();
    });
});