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.

fixed tests.

Petr Patek7e5f2eaa7122
diff --git a/test/crawlers/basic_crawler.test.js b/test/crawlers/basic_crawler.test.js
index 70c499de3..165dd3860 100644
--- a/test/crawlers/basic_crawler.test.js
+++ b/test/crawlers/basic_crawler.test.js
@@ -6,7 +6,7 @@ import * as Apify from '../../build';
import * as keyValueStore from '../../build/key_value_store';
import { RequestQueue, RequestQueueLocal } from '../../build/request_queue';
import { sleep } from '../../build/utils';
-import { LOCAL_STORAGE_DIR } from '../_helper';
+import { LOCAL_STORAGE_DIR, emptyLocalStorageSubdir } from '../_helper';
import events from '../../build/events';
describe('BasicCrawler', () => {
@@ -626,15 +626,15 @@ describe('BasicCrawler', () => {
persistStateKey: 'POOL',
},
handleRequestFunction: async ({ session }) => {
- expect(session.constructor.name).to.be.eql('Session');
- expect(session.id).to.exist // eslint-disable-line
+ expect(session.constructor.name).toEqual('Session');
+ expect(session.id).toBeDefined();
},
handleFailedRequestFunction: ({ request }) => results.push(request),
});
await crawler.run();
- expect(crawler.sessionPool).to.exist; //eslint-disable-line
- expect(results).length(0);
+ expect(crawler.sessionPool).toBeDefined();
+ expect(results).toHaveLength(0);
});
it('should use pass options to sessionPool', async () => {
@@ -656,7 +656,7 @@ describe('BasicCrawler', () => {
});
await crawler.run();
- expect(crawler.sessionPool.maxPoolSize).to.be.eql(10);
+ expect(crawler.sessionPool.maxPoolSize).toEqual(10);
});
it('should teardown Session pool after it is finished', async () => {
@@ -678,13 +678,13 @@ describe('BasicCrawler', () => {
});
crawler._loadHandledRequestCount = () => { // eslint-disable-line
- expect(crawler.sessionPool).to.exist; // eslint-disable-line
- expect(events.listenerCount(ACTOR_EVENT_NAMES.PERSIST_STATE)).to.be.eql(1);
+ expect(crawler.sessionPool).toBeDefined();
+ expect(events.listenerCount(ACTOR_EVENT_NAMES.PERSIST_STATE)).toEqual(1);
};
await crawler.run();
- expect(events.listenerCount(ACTOR_EVENT_NAMES.PERSIST_STATE)).to.be.eql(0);
- expect(crawler.sessionPool.maxPoolSize).to.be.eql(10);
+ expect(events.listenerCount(ACTOR_EVENT_NAMES.PERSIST_STATE)).toEqual(0);
+ expect(crawler.sessionPool.maxPoolSize).toEqual(10);
});
it('should not use SessionPool by default', async () => {
@@ -701,7 +701,7 @@ describe('BasicCrawler', () => {
});
await crawler.run();
- expect(crawler.sessionPool).to.be.undefined; // eslint-disable-line
+ expect(crawler.sessionPool).toBeUndefined();
});
});
});
diff --git a/test/session_pool/session_pool.test.js b/test/session_pool/session_pool.test.js
index 423ebce9d..680860fa4 100644
--- a/test/session_pool/session_pool.test.js
+++ b/test/session_pool/session_pool.test.js
@@ -155,7 +155,11 @@ describe('SessionPool - testing session pool', () => {
const loadedSessionPool = new SessionPool();
await loadedSessionPool.initialize();
- expect(loadedSessionPool).toEqual(expect.objectContaining(sessionPool));
+ expect(sessionPool.sessions).toHaveLength(loadedSessionPool.sessions.length);
+ expect(sessionPool.maxPoolSize).toEqual(loadedSessionPool.maxPoolSize);
+ expect(sessionPool.maxSessionAgeSecs).toEqual(loadedSessionPool.maxSessionAgeSecs);
+ expect(sessionPool.maxSessionUsageCount).toEqual(loadedSessionPool.maxSessionUsageCount);
+ expect(sessionPool.persistStateKey).toEqual(loadedSessionPool.persistStateKey);
sessionPool.teardown();
});
@@ -253,8 +257,8 @@ describe('SessionPool - testing session pool', () => {
});
it('should remove persist state event listener', () => {
- expect(events.listenerCount(ACTOR_EVENT_NAMES_EX.PERSIST_STATE)).to.be.eq(1);
+ expect(events.listenerCount(ACTOR_EVENT_NAMES_EX.PERSIST_STATE)).toEqual(1);
sessionPool.teardown();
- expect(events.listenerCount(ACTOR_EVENT_NAMES_EX.PERSIST_STATE)).to.be.eq(0);
+ expect(events.listenerCount(ACTOR_EVENT_NAMES_EX.PERSIST_STATE)).toEqual(0);
});
});