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.

Migrate all tests to Jest

Ondra Urban1027a3427da7
diff --git a/package.json b/package.json
index 6acee2255..65898a07f 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"build": "rm -rf ./build && babel src --out-dir build --copy-files",
"build-docs": "npm run clean && npm run build && node ./website/tools/build_docs.js",
"build-readme": "node ./tools/build_readme.js",
- "test": "npm run build && jest",
+ "test": "npm run build && jest --testTimeout=60000",
"test:integration": "npm run build && nyc --reporter=html --reporter=text mocha 'test/integration_tests' --timeout 60000 --require @babel/register --recursive --exit",
"prepare": "npm run build",
"prepublishOnly": "(test $TRAVIS || (echo \"Publishing is reserved to the Travis CI!\"; exit 1))",
diff --git a/test/_helper.js b/test/_helper.js
index 3651f06e9..3e60d8a05 100644
--- a/test/_helper.js
+++ b/test/_helper.js
@@ -22,16 +22,16 @@ export const emptyLocalStorageSubdir = (subdir) => {
fs.emptyDirSync(fullPath);
};
-export const expectNotUsingLocalStorage = () => expect(process.env[ENV_VARS.LOCAL_STORAGE_DIR]).to.be.a('undefined');
+export const expectNotUsingLocalStorage = () => expect(process.env[ENV_VARS.LOCAL_STORAGE_DIR]).toBeUndefined();
export const expectDirEmpty = (dirPath) => {
const content = fs.readdirSync(dirPath);
- expect(content).to.have.lengthOf(0);
+ expect(content).toHaveLength(0);
};
export const expectDirNonEmpty = (dirPath) => {
const content = fs.readdirSync(dirPath);
- expect(content).to.have.lengthOf.above(0);
+ expect(content).not.toHaveLength(0);
};
export const startExpressAppPromise = (app, port) => {
diff --git a/test/actor.test.js b/test/actor.test.js
index e367c2821..117237243 100644
--- a/test/actor.test.js
+++ b/test/actor.test.js
@@ -140,7 +140,7 @@ describe('Apify.getEnv()', () => {
setEnv(expectedEnv);
const env = Apify.getEnv();
- expect(env).to.containSubset(expectedEnv);
+ expect(env).toMatchObject(expectedEnv);
});
test('works with with non-null values', () => {
@@ -159,7 +159,7 @@ describe('Apify.getEnv()', () => {
setEnv(expectedEnv);
const env = Apify.getEnv();
- expect(env).to.containSubset(expectedEnv);
+ expect(env).toMatchObject(expectedEnv);
});
});
@@ -167,7 +167,7 @@ describe('Apify.main()', () => {
test('throws on invalid args', () => {
expect(() => {
Apify.main();
- }).to.throw(Error);
+ }).toThrowError(Error);
});
test('works with simple user function', () => {
@@ -183,7 +183,7 @@ describe('Apify.main()', () => {
await testMain({
userFunc: () => {
- expect(process.env[ENV_VARS.LOCAL_STORAGE_DIR]).to.eql(path.join(process.cwd(), './apify_storage'));
+ expect(process.env[ENV_VARS.LOCAL_STORAGE_DIR]).toEqual(path.join(process.cwd(), './apify_storage'));
},
exitCode: 0,
});
@@ -206,7 +206,7 @@ describe('Apify.main()', () => {
exitCode: 0,
})
.then(() => {
- expect(called).to.eql(true);
+ expect(called).toBe(true);
});
});
@@ -285,7 +285,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, input, { contentType, token, disableBodyParser: true, build, memoryMbytes, timeoutSecs, webhooks })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -337,7 +337,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, input, { contentType, token, disableBodyParser: true, build, memory, timeoutSecs })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -378,7 +378,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId)
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -409,7 +409,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, undefined, { waitSecs: 1 })
.then((callOutput) => {
- expect(callOutput).to.be.eql(readyRun);
+ expect(callOutput).toEqual(readyRun);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -450,7 +450,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, null)
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -493,7 +493,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, input)
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -534,7 +534,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, input, { token, disableBodyParser: true, build })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -568,7 +568,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, null, { token, fetchOutput: false })
.then((callOutput) => {
- expect(callOutput).to.be.eql(finishedRun);
+ expect(callOutput).toEqual(finishedRun);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -600,7 +600,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, null, { token, waitSecs })
.then((callOutput) => {
- expect(callOutput).to.be.eql(runningRun);
+ expect(callOutput).toEqual(runningRun);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -642,7 +642,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, input, { contentType, token, disableBodyParser: true, build })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -669,7 +669,7 @@ describe('Apify.call()', () => {
return Apify
.call(actId, null, { token, waitSecs })
.then((callOutput) => {
- expect(callOutput).to.be.eql(readyRun);
+ expect(callOutput).toEqual(readyRun);
keyValueStoresMock.restore();
actsMock.restore();
});
@@ -695,9 +695,9 @@ describe('Apify.call()', () => {
return Apify
.call(actId, null, { token })
.then(() => { throw new Error('This was suppose to fail!'); }, (err) => {
- expect(err).to.be.instanceOf(ApifyCallError);
- expect(err.run.status).to.be.eql(ACT_JOB_STATUSES.ABORTED);
- expect(err.run).to.be.eql(failedRun);
+ expect(err).toBeInstanceOf(ApifyCallError);
+ expect(err.run.status).toEqual(ACT_JOB_STATUSES.ABORTED);
+ expect(err.run).toEqual(failedRun);
actsMock.restore();
});
});
@@ -753,7 +753,7 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId, input, { token, disableBodyParser: true, memoryMbytes, timeoutSecs, build, webhooks })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
tasksMock.restore();
@@ -791,7 +791,7 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId, undefined, { token, disableBodyParser: true, fetchOutput: false })
.then((callOutput) => {
- expect(callOutput).to.be.eql(finishedRun);
+ expect(callOutput).toEqual(finishedRun);
keyValueStoresMock.restore();
actsMock.restore();
tasksMock.restore();
@@ -827,7 +827,7 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId, undefined, { token, disableBodyParser: true, fetchOutput: false, waitSecs })
.then((callOutput) => {
- expect(callOutput).to.be.eql(runningRun);
+ expect(callOutput).toEqual(runningRun);
keyValueStoresMock.restore();
actsMock.restore();
tasksMock.restore();
@@ -871,7 +871,7 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId, undefined, { token, disableBodyParser: true })
.then((callOutput) => {
- expect(callOutput).to.be.eql(expected);
+ expect(callOutput).toEqual(expected);
keyValueStoresMock.restore();
actsMock.restore();
tasksMock.restore();
@@ -902,7 +902,7 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId, undefined, { token, waitSecs })
.then((callOutput) => {
- expect(callOutput).to.be.eql(readyRun);
+ expect(callOutput).toEqual(readyRun);
keyValueStoresMock.restore();
actsMock.restore();
tasksMock.restore();
@@ -932,9 +932,9 @@ describe('Apify.callTask()', () => {
return Apify
.callTask(taskId)
.catch((err) => {
- expect(err).to.be.instanceOf(ApifyCallError);
- expect(err.run.status).to.be.eql(ACT_JOB_STATUSES.ABORTED);
- expect(err.run).to.be.eql(failedRun);
+ expect(err).toBeInstanceOf(ApifyCallError);
+ expect(err.run.status).toEqual(ACT_JOB_STATUSES.ABORTED);
+ expect(err.run).toEqual(failedRun);
actsMock.restore();
tasksMock.restore();
});
@@ -1051,32 +1051,33 @@ describe('Apify.getApifyProxyUrl()', () => {
expect(Apify.getApifyProxyUrl({
session: 'XYZ',
groups: ['g1', 'g2', 'g3'],
- })).to.be.eql('http://groups-g1+g2+g3,session-XYZ:[email protected]:123');
+ })).toBe('http://groups-g1+g2+g3,session-XYZ:[email protected]:123');
expect(Apify.getApifyProxyUrl({
groups: ['g1', 'g2', 'g3'],
- })).to.be.eql('http://groups-g1+g2+g3:[email protected]:123');
+ })).toBe('http://groups-g1+g2+g3:[email protected]:123');
expect(Apify.getApifyProxyUrl({
session: 'XYZ',
- })).to.be.eql('http://session-XYZ:[email protected]:123');
+ })).toBe('http://session-XYZ:[email protected]:123');
- expect(Apify.getApifyProxyUrl()).to.be.eql('http://auto:[email protected]:123');
+ expect(Apify.getApifyProxyUrl()).toBe('http://auto:[email protected]:123');
delete process.env[ENV_VARS.PROXY_PASSWORD];
delete process.env[ENV_VARS.PROXY_HOSTNAME];
delete process.env[ENV_VARS.PROXY_PORT];
- expect(Apify.getApifyProxyUrl({ password: 'xyz' }))
- .to.be.eql(`http://auto:xyz@${LOCAL_ENV_VARS[ENV_VARS.PROXY_HOSTNAME]}:${LOCAL_ENV_VARS[ENV_VARS.PROXY_PORT]}`);
+ expect(Apify.getApifyProxyUrl({ password: 'xyz' })).toEqual(
+ `http://auto:xyz@${LOCAL_ENV_VARS[ENV_VARS.PROXY_HOSTNAME]}:${LOCAL_ENV_VARS[ENV_VARS.PROXY_PORT]}`
+ );
- expect(() => Apify.getApifyProxyUrl()).to.throw();
+ expect(() => Apify.getApifyProxyUrl()).toThrowError();
expect(Apify.getApifyProxyUrl({
password: 'xyz',
hostname: 'your.host.com',
port: 345,
- })).to.be.eql('http://auto:[email protected]:345');
+ })).toBe('http://auto:[email protected]:345');
});
// Test old params - session, groups
@@ -1090,32 +1091,33 @@ describe('Apify.getApifyProxyUrl()', () => {
expect(Apify.getApifyProxyUrl({
apifyProxySession: 'XYZ',
apifyProxyGroups: ['g1', 'g2', 'g3'],
- })).to.be.eql('http://groups-g1+g2+g3,session-XYZ:[email protected]:123');
+ })).toBe('http://groups-g1+g2+g3,session-XYZ:[email protected]:123');
expect(Apify.getApifyProxyUrl({
apifyProxyGroups: ['g1', 'g2', 'g3'],
- })).to.be.eql('http://groups-g1+g2+g3:[email protected]:123');
+ })).toBe('http://groups-g1+g2+g3:[email protected]:123');
expect(Apify.getApifyProxyUrl({
apifyProxySession: 'XYZ',
- })).to.be.eql('http://session-XYZ:[email protected]:123');
+ })).toBe('http://session-XYZ:[email protected]:123');
- expect(Apify.getApifyProxyUrl()).to.be.eql('http://auto:[email protected]:123');
+ expect(Apify.getApifyProxyUrl()).toBe('http://auto:[email protected]:123');
delete process.env[ENV_VARS.PROXY_PASSWORD];
delete process.env[ENV_VARS.PROXY_HOSTNAME];
delete process.env[ENV_VARS.PROXY_PORT];
- expect(Apify.getApifyProxyUrl({ password: 'xyz' }))
- .to.be.eql(`http://auto:xyz@${LOCAL_ENV_VARS[ENV_VARS.PROXY_HOSTNAME]}:${LOCAL_ENV_VARS[ENV_VARS.PROXY_PORT]}`);
+ expect(Apify.getApifyProxyUrl({ password: 'xyz' })).toEqual(
+ `http://auto:xyz@${LOCAL_ENV_VARS[ENV_VARS.PROXY_HOSTNAME]}:${LOCAL_ENV_VARS[ENV_VARS.PROXY_PORT]}`
+ );
- expect(() => Apify.getApifyProxyUrl()).to.throw();
+ expect(() => Apify.getApifyProxyUrl()).toThrowError();
expect(Apify.getApifyProxyUrl({
password: 'xyz',
hostname: 'your.host.com',
port: 345,
- })).to.be.eql('http://auto:[email protected]:345');
+ })).toBe('http://auto:[email protected]:345');
log.setLevel(ll);
});
@@ -1124,25 +1126,25 @@ describe('Apify.getApifyProxyUrl()', () => {
process.env[ENV_VARS.PROXY_HOSTNAME] = 'my.host.com';
process.env[ENV_VARS.PROXY_PORT] = 123;
- expect(() => Apify.getApifyProxyUrl({ session: 'a-b' })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ session: 'a$b' })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ session: {} })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ session: new Date() })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ apifyProxySession: new Date() })).to.throw();
-
- expect(() => Apify.getApifyProxyUrl({ session: 'a_b' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: '0.34252352' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: 'aaa~BBB' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: 'a_1_b' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: 'a_2' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: 'a' })).to.not.throw();
- expect(() => Apify.getApifyProxyUrl({ session: '1' })).to.not.throw();
-
- expect(() => Apify.getApifyProxyUrl({ groups: [new Date()] })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ groups: [{}, 'fff', 'ccc'] })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ groups: ['ffff', 'ff-hf', 'ccc'] })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ groups: ['ffff', 'fff', 'cc$c'] })).to.throw();
- expect(() => Apify.getApifyProxyUrl({ apifyProxyGroups: [new Date()] })).to.throw();
+ expect(() => Apify.getApifyProxyUrl({ session: 'a-b' })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: 'a$b' })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: {} })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: new Date() })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ apifyProxySession: new Date() })).toThrowError();
+
+ expect(() => Apify.getApifyProxyUrl({ session: 'a_b' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: '0.34252352' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: 'aaa~BBB' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: 'a_1_b' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: 'a_2' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: 'a' })).not.toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ session: '1' })).not.toThrowError();
+
+ expect(() => Apify.getApifyProxyUrl({ groups: [new Date()] })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ groups: [{}, 'fff', 'ccc'] })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ groups: ['ffff', 'ff-hf', 'ccc'] })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ groups: ['ffff', 'fff', 'cc$c'] })).toThrowError();
+ expect(() => Apify.getApifyProxyUrl({ apifyProxyGroups: [new Date()] })).toThrowError();
delete process.env[ENV_VARS.PROXY_PASSWORD];
delete process.env[ENV_VARS.PROXY_HOSTNAME];
@@ -1222,7 +1224,7 @@ describe('Apify.addWebhook()', () => {
} catch (err) {
isThrow = true;
}
- expect(isThrow).to.be.eql(true);
+ expect(isThrow).toBe(true);
delete process.env[ENV_VARS.IS_AT_HOME];
});
diff --git a/test/autoscaling/autoscaled_pool.test.js b/test/autoscaling/autoscaled_pool.test.js
index 691395516..c22ef01b5 100644
--- a/test/autoscaling/autoscaled_pool.test.js
+++ b/test/autoscaling/autoscaled_pool.test.js
@@ -44,8 +44,9 @@ describe('AutoscaledPool', () => {
const startedAt = Date.now();
await pool.run();
- expect(result).to.be.eql(_.range(0, 10));
- expect(Date.now() - startedAt).to.be.within(50, 200);
+ expect(result).toEqual(_.range(0, 10));
+ expect(Date.now() - startedAt).toBeGreaterThanOrEqual(50);
+ expect(Date.now() - startedAt).toBeLessThanOrEqual(200);
});
test('should work with concurrency 10', async () => {
@@ -77,8 +78,9 @@ describe('AutoscaledPool', () => {
const startedAt = Date.now();
await pool.run();
- expect(result).to.be.eql(_.range(0, 100));
- expect(Date.now() - startedAt).to.be.within(50, 200);
+ expect(result).toEqual(_.range(0, 100));
+ expect(Date.now() - startedAt).toBeGreaterThanOrEqual(50);
+ expect(Date.now() - startedAt).toBeLessThanOrEqual(200);
});
test('enables setting concurrency', async () => {
@@ -109,9 +111,9 @@ describe('AutoscaledPool', () => {
isTaskReadyFunction: () => Promise.resolve(!isFinished),
});
- expect(pool.minConcurrency).to.be.eql(3);
- expect(pool.maxConcurrency).to.be.eql(13);
- expect(pool.desiredConcurrency).to.be.eql(9);
+ expect(pool.minConcurrency).toBe(3);
+ expect(pool.maxConcurrency).toBe(13);
+ expect(pool.desiredConcurrency).toBe(9);
const startedAt = Date.now();
const promise = await pool.run();
@@ -121,14 +123,15 @@ describe('AutoscaledPool', () => {
pool.maxConcurrency = 14;
pool.desiredConcurrency = 7;
- expect(pool.minConcurrency).to.be.eql(4);
- expect(pool.maxConcurrency).to.be.eql(14);
- expect(pool.desiredConcurrency).to.be.eql(7);
+ expect(pool.minConcurrency).toBe(4);
+ expect(pool.maxConcurrency).toBe(14);
+ expect(pool.desiredConcurrency).toBe(7);
await promise;
- expect(result).to.be.eql(_.range(0, 100));
- expect(Date.now() - startedAt).to.be.within(50, 200);
+ expect(result).toEqual(_.range(0, 100));
+ expect(Date.now() - startedAt).toBeGreaterThanOrEqual(50);
+ expect(Date.now() - startedAt).toBeLessThanOrEqual(200);
});
describe('should scale correctly', () => {
@@ -158,23 +161,23 @@ describe('AutoscaledPool', () => {
test('works with low values', () => {
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(2);
+ expect(pool.desiredConcurrency).toBe(2);
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(2); // because currentConcurrency is not high enough;
+ expect(pool.desiredConcurrency).toBe(2); // because currentConcurrency is not high enough;
pool._currentConcurrency = 2;
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(3);
+ expect(pool.desiredConcurrency).toBe(3);
systemStatus.okNow = false; // this should have no effect
pool._currentConcurrency = 3;
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(4);
+ expect(pool.desiredConcurrency).toBe(4);
systemStatus.okLately = false;
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(3);
+ expect(pool.desiredConcurrency).toBe(3);
});
test('works with high values', () => {
@@ -183,19 +186,19 @@ describe('AutoscaledPool', () => {
pool._currentConcurrency = Math.floor(pool.desiredConcurrency * pool.desiredConcurrencyRatio) - 1;
systemStatus.okLately = true;
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(50);
+ expect(pool.desiredConcurrency).toBe(50);
// Should scale because we bumped up current concurrency.
pool._currentConcurrency = Math.floor(pool.desiredConcurrency * pool.desiredConcurrencyRatio);
let newConcurrency = pool.desiredConcurrency + Math.ceil(pool.desiredConcurrency * pool.scaleUpStepRatio);
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(newConcurrency);
+ expect(pool.desiredConcurrency).toEqual(newConcurrency);
// Should scale down.
systemStatus.okLately = false;
newConcurrency = pool.desiredConcurrency - Math.ceil(pool.desiredConcurrency * pool.scaleDownStepRatio);
pool._autoscale(cb);
- expect(pool.desiredConcurrency).to.be.eql(newConcurrency);
+ expect(pool.desiredConcurrency).toEqual(newConcurrency);
});
test('works at minConcurrency when currently overloaded', async () => {
@@ -222,10 +225,10 @@ describe('AutoscaledPool', () => {
},
});
- expect(pool.currentConcurrency).to.be.eql(0);
+ expect(pool.currentConcurrency).toBe(0);
await pool.run();
- expect(concurrencyLog.some(n => n > 1)).to.be.eql(false);
+ expect(concurrencyLog.some(n => n > 1)).toBe(false);
limit = 50;
concurrencyLog = [];
@@ -233,7 +236,7 @@ describe('AutoscaledPool', () => {
pool.minConcurrency = 5;
await pool.run();
- expect(concurrencyLog.some(n => n > 5)).to.be.eql(false);
+ expect(concurrencyLog.some(n => n > 5)).toBe(false);
});
});
@@ -273,7 +276,7 @@ describe('AutoscaledPool', () => {
isTaskReadyFunction: () => Promise.resolve(true),
});
- await expect(pool.run()).to.be.rejectedWith('some-promise-error');
+ await expect(pool.run()).rejects.toThrow('some-promise-error');
});
test('when runTaskFunction throws', async () => {
@@ -290,7 +293,7 @@ describe('AutoscaledPool', () => {
});
- await expect(pool.run()).to.be.rejectedWith('some-runtask-error');
+ await expect(pool.run()).rejects.toThrow('some-runtask-error');
});
test('when isFinishedFunction throws', async () => {
@@ -304,7 +307,7 @@ describe('AutoscaledPool', () => {
});
- await expect(pool.run()).to.be.rejectedWith('some-finished-error');
+ await expect(pool.run()).rejects.toThrow('some-finished-error');
});
test('when isTaskReadyFunction throws', async () => {
@@ -321,7 +324,7 @@ describe('AutoscaledPool', () => {
});
- await expect(pool.run()).to.be.rejectedWith('some-ready-error');
+ await expect(pool.run()).rejects.toThrow('some-ready-error');
});
});
@@ -343,8 +346,9 @@ describe('AutoscaledPool', () => {
await pool.run();
await delayPromise(10);
+ expect(count).toBeGreaterThanOrEqual(11);
// Check finished tasks.
- expect(count).to.be.within(11, 13);
+ expect(count).toBeLessThanOrEqual(13);
}
);
@@ -372,8 +376,8 @@ describe('AutoscaledPool', () => {
await pool.run();
// Check finished tasks.
- expect(finished).to.have.lengthOf(20);
- expect(finished[11] - finished[10]).to.be.above(9);
+ expect(finished).toHaveLength(20);
+ expect(finished[11] - finished[10]).toBeGreaterThan(9);
}
);
@@ -387,7 +391,7 @@ describe('AutoscaledPool', () => {
loggingIntervalMillis: null,
});
pool._autoscale(() => {});
- expect(pool.desiredConcurrency).to.be.eql(2);
+ expect(pool.desiredConcurrency).toBe(2);
});
test('should abort', async () => {
@@ -406,7 +410,7 @@ describe('AutoscaledPool', () => {
isTaskReadyFunction: () => !aborted,
});
await pool.run();
- expect(finished).to.be.eql(false);
+ expect(finished).toBe(false);
});
test('should only finish after tasks complete', async () => {
@@ -430,8 +434,8 @@ describe('AutoscaledPool', () => {
});
await pool.run();
- expect(started).to.be.eql(true);
- expect(completed).to.be.eql(true);
+ expect(started).toBe(true);
+ expect(completed).toBe(true);
});
test('should pause and resume', async () => {
@@ -457,17 +461,17 @@ describe('AutoscaledPool', () => {
const runPromise = pool.run();
runPromise.then(() => { finished = true; });
await pausePromise;
- expect(count).to.be.eql(20);
- expect(finished).to.be.eql(false);
- expect(results).to.have.lengthOf(count);
- results.forEach((r, i) => expect(r).to.be.eql(i));
+ expect(count).toBe(20);
+ expect(finished).toBe(false);
+ expect(results).toHaveLength(count);
+ results.forEach((r, i) => expect(r).toEqual(i));
pool.resume();
await runPromise;
- expect(count).to.be.eql(50);
- expect(finished).to.be.eql(true);
- expect(results).to.have.lengthOf(count);
- results.forEach((r, i) => expect(r).to.be.eql(i));
+ expect(count).toBe(50);
+ expect(finished).toBe(true);
+ expect(results).toHaveLength(count);
+ results.forEach((r, i) => expect(r).toEqual(i));
});
});
diff --git a/test/autoscaling/snapshotter.test.js b/test/autoscaling/snapshotter.test.js
index 27905a413..8b41000e2 100644
--- a/test/autoscaling/snapshotter.test.js
+++ b/test/autoscaling/snapshotter.test.js
@@ -45,32 +45,32 @@ describe('Snapshotter', () => {
expect(cpuSnapshots).toHaveLength(2);
cpuSnapshots.forEach((ss) => {
expect(ss.createdAt).toBeInstanceOf(Date);
- expect(ss.isOverloaded).toBeInstanceOf(Boolean);
- expect(ss.usedRatio).toBeInstanceOf(Number);
+ expect(typeof ss.isOverloaded).toBe('boolean');
+ expect(typeof ss.usedRatio).toBe('number');
});
expect(Array.isArray(memorySnapshots)).toBe(true);
expect(memorySnapshots).toHaveLength(2);
memorySnapshots.forEach((ss) => {
expect(ss.createdAt).toBeInstanceOf(Date);
- expect(ss.isOverloaded).toBeInstanceOf(Boolean);
- expect(ss.usedBytes).toBeInstanceOf(Number);
+ expect(typeof ss.isOverloaded).toBe('boolean');
+ expect(typeof ss.usedBytes).toBe('number');
});
expect(Array.isArray(eventLoopSnapshots)).toBe(true);
expect(eventLoopSnapshots).toHaveLength(3);
eventLoopSnapshots.forEach((ss) => {
expect(ss.createdAt).toBeInstanceOf(Date);
- expect(ss.isOverloaded).toBeInstanceOf(Boolean);
- expect(ss.exceededMillis).toBeInstanceOf(Number);
+ expect(typeof ss.isOverloaded).toBe('boolean');
+ expect(typeof ss.exceededMillis).toBe('number');
});
expect(Array.isArray(clientSnapshots)).toBe(true);
expect(clientSnapshots).toHaveLength(2);
clientSnapshots.forEach((ss) => {
expect(ss.createdAt).toBeInstanceOf(Date);
- expect(ss.isOverloaded).toBeInstanceOf(Boolean);
- expect(ss.rateLimitErrorCount).toBeInstanceOf(Number);
+ expect(typeof ss.isOverloaded).toBe('boolean');
+ expect(typeof ss.rateLimitErrorCount).toBe('number');
});
utils.apifyClient.stats = oldStats;
@@ -121,7 +121,7 @@ describe('Snapshotter', () => {
expect(cpuSnapshots).toHaveLength(4);
cpuSnapshots.forEach((ss, i) => {
expect(ss.createdAt).toBeInstanceOf(Date);
- expect(ss.isOverloaded).toBeInstanceOf(Boolean);
+ expect(typeof ss.isOverloaded).toBe('boolean');
expect(ss.isOverloaded).toEqual(i % 2 === 0);
});
} finally {
diff --git a/test/crawlers/basic_crawler.test.js b/test/crawlers/basic_crawler.test.js
index b01d9720d..80078c76b 100644
--- a/test/crawlers/basic_crawler.test.js
+++ b/test/crawlers/basic_crawler.test.js
@@ -235,8 +235,8 @@ describe('BasicCrawler', () => {
expect(failed['http://example.com/2'].retryCount).toBe(3);
expect(failed['http://example.com/3'].errorMessages).toHaveLength(4);
expect(failed['http://example.com/3'].retryCount).toBe(3);
- expect(_.values(failed)).to.have.length.of(3);
- expect(_.values(processed)).to.have.length.of(0);
+ expect(_.values(failed)).toHaveLength(3);
+ expect(_.values(processed)).toHaveLength(0);
expect(await requestList.isFinished()).toBe(true);
expect(await requestList.isEmpty()).toBe(true);
errors.forEach(error => expect(error).toBeInstanceOf(Error));
@@ -605,6 +605,6 @@ describe('BasicCrawler', () => {
await crawler.run();
expect(results).toHaveLength(1);
expect(results[0].url).toEqual(url);
- results[0].errorMessages.forEach(msg => expect(msg).toEqual(expect.arrayContaining(['handleRequestFunction timed out'])));
+ results[0].errorMessages.forEach(msg => expect(msg).toMatch('handleRequestFunction timed out'));
});
});
diff --git a/test/crawlers/cheerio_crawler.test.js b/test/crawlers/cheerio_crawler.test.js
index 42b364b4e..03959644b 100644
--- a/test/crawlers/cheerio_crawler.test.js
+++ b/test/crawlers/cheerio_crawler.test.js
@@ -267,8 +267,8 @@ describe('CheerioCrawler', () => {
failed.forEach((request) => {
expect(request.errorMessages).toHaveLength(2);
- expect(request.errorMessages[0]).toEqual(expect.arrayContaining(['request timed out']));
- expect(request.errorMessages[1]).toEqual(expect.arrayContaining(['request timed out']));
+ expect(request.errorMessages[0]).toMatch('request timed out');
+ expect(request.errorMessages[1]).toMatch('request timed out');
});
});
@@ -307,8 +307,8 @@ describe('CheerioCrawler', () => {
failed.forEach((request) => {
expect(request.errorMessages).toHaveLength(2);
- expect(request.errorMessages[0]).toEqual(expect.arrayContaining(['handlePageFunction timed out']));
- expect(request.errorMessages[1]).toEqual(expect.arrayContaining(['handlePageFunction timed out']));
+ expect(request.errorMessages[0]).toMatch('handlePageFunction timed out');
+ expect(request.errorMessages[1]).toMatch('handlePageFunction timed out');
});
});
});
@@ -405,9 +405,9 @@ describe('CheerioCrawler', () => {
expect(handlePageInvocationCount).toBe(0);
expect(errorMessages).toHaveLength(4);
- errorMessages.forEach(msg => expect(msg).toEqual(
- expect.arrayContaining(['Content-Type application/json, but only text/html, '
- + 'application/xhtml+xml are allowed. Skipping resource.'])
+ errorMessages.forEach(msg => expect(msg).toMatch(
+ 'Content-Type application/json, but only text/html, '
+ + 'application/xhtml+xml are allowed. Skipping resource.',
));
expect(chunkReadCount).toBe(0);
});
@@ -488,7 +488,7 @@ describe('CheerioCrawler', () => {
expect(handlePageInvocationCount).toBe(0);
expect(errorMessages).toHaveLength(8);
- errorMessages.forEach(msg => expect(msg).toEqual(expect.arrayContaining(['Internal Server Error'])));
+ errorMessages.forEach(msg => expect(msg).toMatch('Internal Server Error'));
});
test('when statusCode >= 500 and application/json is received', async () => {
@@ -506,7 +506,7 @@ describe('CheerioCrawler', () => {
expect(handlePageInvocationCount).toBe(0);
expect(errorMessages).toHaveLength(8);
- errorMessages.forEach(msg => expect(msg).toEqual(expect.arrayContaining(['CUSTOM_ERROR'])));
+ errorMessages.forEach(msg => expect(msg).toMatch('CUSTOM_ERROR'));
});
test('when 406 is received', async () => {
@@ -530,9 +530,7 @@ describe('CheerioCrawler', () => {
expect(handlePageInvocationCount).toBe(0);
expect(errorMessages).toHaveLength(4);
- errorMessages.forEach(msg => expect(msg).toEqual(
- expect.arrayContaining(['is not available in HTML format. Skipping resource.'])
- ));
+ errorMessages.forEach(msg => expect(msg).toMatch('is not available in HTML format. Skipping resource.'));
});
xit('when status is ok, but a wrong content type is received', async () => {
@@ -564,7 +562,7 @@ describe('CheerioCrawler', () => {
expect(handlePageInvocationCount).toBe(0);
expect(errorMessages).toHaveLength(4);
errorMessages.forEach(msg => expect(msg).toEqual(
- expect.arrayContaining(['served Content-Type application/json instead of text/html'])
+ expect.arrayContaining(['served Content-Type application/json instead of text/html']),
));
expect(chunkReadCount).toBe(0);
});
@@ -775,7 +773,7 @@ describe('CheerioCrawler', () => {
});
throw new Error('Invalid error.');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['useApifyProxy']));
+ expect(err.message).toMatch('useApifyProxy');
}
});
@@ -789,7 +787,7 @@ describe('CheerioCrawler', () => {
});
throw new Error('Invalid error.');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['must not be empty']));
+ expect(err.message).toMatch('must not be empty');
}
});
});
diff --git a/test/dataset.test.js b/test/dataset.test.js
index 033dc7d75..3b28bc3e6 100644
--- a/test/dataset.test.js
+++ b/test/dataset.test.js
@@ -25,7 +25,7 @@ describe('dataset', () => {
beforeEach(() => emptyLocalStorageSubdir(LOCAL_STORAGE_SUBDIR));
afterEach(() => emptyLocalStorageSubdir(LOCAL_STORAGE_SUBDIR));
- describe('local', async () => {
+ describe('local', () => {
test('should successfully save data', async () => {
const dataset = new DatasetLocal('my-dataset', LOCAL_STORAGE_DIR);
@@ -326,7 +326,7 @@ describe('dataset', () => {
});
});
- describe('remote', async () => {
+ describe('remote', () => {
const mockData = bytes => 'x'.repeat(bytes);
test('should succesfully save simple data', async () => {
@@ -432,7 +432,7 @@ describe('dataset', () => {
throw new Error('Should fail!');
} catch (err) {
expect(err).toBeInstanceOf(Error);
- expect(err.message).toEqual(expect.arrayContaining(['Data item is too large']));
+ expect(err.message).toMatch('Data item is too large');
}
mock.expects('deleteDataset')
.once()
@@ -457,7 +457,7 @@ describe('dataset', () => {
throw new Error('Should fail!');
} catch (err) {
expect(err).toBeInstanceOf(Error);
- expect(err.message).toEqual(expect.arrayContaining(['Data item at index 3 is too large']));
+ expect(err.message).toMatch('Data item at index 3 is too large');
}
mock.expects('deleteDataset')
.once()
@@ -746,7 +746,7 @@ describe('dataset', () => {
});
});
- describe('Apify.openDataset', async () => {
+ describe('Apify.openDataset', () => {
test('should work', () => {
const mock = sinon.mock(utils);
@@ -773,23 +773,23 @@ describe('dataset', () => {
});
});
- describe('pushData', async () => {
+ describe('pushData', () => {
test('throws on invalid args', async () => {
process.env[ENV_VARS.DEFAULT_DATASET_ID] = 'some-id-8';
process.env[ENV_VARS.LOCAL_STORAGE_DIR] = LOCAL_STORAGE_DIR;
const dataErrMsg = 'Parameter "data" of type Array | Object must be provided';
- await expect(Apify.pushData()).to.be.rejectedWith(dataErrMsg);
- await expect(Apify.pushData('')).to.be.rejectedWith(dataErrMsg);
- await expect(Apify.pushData(123)).to.be.rejectedWith(dataErrMsg);
- await expect(Apify.pushData(true)).to.be.rejectedWith(dataErrMsg);
- await expect(Apify.pushData(false)).to.be.rejectedWith(dataErrMsg);
- await expect(Apify.pushData(() => {})).to.be.rejectedWith(dataErrMsg);
+ await expect(Apify.pushData()).rejects.toThrow(dataErrMsg);
+ await expect(Apify.pushData('')).rejects.toThrow(dataErrMsg);
+ await expect(Apify.pushData(123)).rejects.toThrow(dataErrMsg);
+ await expect(Apify.pushData(true)).rejects.toThrow(dataErrMsg);
+ await expect(Apify.pushData(false)).rejects.toThrow(dataErrMsg);
+ await expect(Apify.pushData(() => {})).rejects.toThrow(dataErrMsg);
const circularObj = {};
circularObj.xxx = circularObj;
const jsonErrMsg = 'Converting circular structure to JSON';
- await expect(Apify.pushData(circularObj)).to.be.rejectedWith(jsonErrMsg);
+ await expect(Apify.pushData(circularObj)).rejects.toThrow(jsonErrMsg);
delete process.env[ENV_VARS.DEFAULT_DATASET_ID];
delete process.env[ENV_VARS.LOCAL_STORAGE_DIR];
@@ -802,13 +802,13 @@ describe('dataset', () => {
process.env[ENV_VARS.TOKEN] = 'xxx';
process.env[ENV_VARS.DEFAULT_DATASET_ID] = '';
- await expect(Apify.pushData({ something: 123 })).to.be.rejectedWith(Error);
+ await expect(Apify.pushData({ something: 123 })).rejects.toThrow(Error);
delete process.env[ENV_VARS.DEFAULT_DATASET_ID];
- await expect(Apify.pushData({ something: 123 })).to.be.rejectedWith(Error);
+ await expect(Apify.pushData({ something: 123 })).rejects.toThrow(Error);
delete process.env[ENV_VARS.TOKEN];
- }
+ },
);
test('correctly stores records', async () => {
@@ -826,7 +826,7 @@ describe('dataset', () => {
});
});
- describe('utils', async () => {
+ describe('utils', () => {
test('checkAndSerialize() works', () => {
// Basic
const obj = { foo: 'bar' };
diff --git a/test/enqueue_links/click_elements.test.js b/test/enqueue_links/click_elements.test.js
index b4e59fcf8..7cbbd6ea3 100644
--- a/test/enqueue_links/click_elements.test.js
+++ b/test/enqueue_links/click_elements.test.js
@@ -179,7 +179,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toMatch(/https:\/\/example\.com\/?$/);
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.location = ']));
+ expect(pageContent).toMatch('onclick="return window.location = ');
});
test(
@@ -198,7 +198,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toBe('https://example.com/#foo');
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.location = ']));
+ expect(pageContent).toMatch('onclick="return window.location = ');
}
);
@@ -216,7 +216,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toMatch(/https:\/\/example\.com\/?$/);
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.location.reload()']));
+ expect(pageContent).toMatch('onclick="return window.location.reload()');
});
test('should prevent forced reload with window.reload(true)', async () => {
@@ -233,7 +233,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toMatch(/https:\/\/example\.com\/?$/);
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.location.reload(true)']));
+ expect(pageContent).toMatch('onclick="return window.location.reload(true)');
});
test('should prevent manipulation with window.history', async () => {
@@ -259,7 +259,7 @@ describe('enqueueLinksByClickingElements()', () => {
const interceptedRequests = await clickElementsAndInterceptNavigationRequests(getOpts());
expect(interceptedRequests).toHaveLength(0);
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return handleClick();']));
+ expect(pageContent).toMatch('onclick="return handleClick();');
});
test('should save urls pushed to window.history', async () => {
@@ -276,7 +276,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toBe('https://example.com/bar/foo');
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.history.pushState']));
+ expect(pageContent).toMatch('onclick="return window.history.pushState');
});
test('should close newly opened tabs', async () => {
@@ -311,7 +311,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(callCounts.create).toBe(1);
expect(callCounts.destroy).toBe(1);
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.open(']));
+ expect(pageContent).toMatch('onclick="return window.open(');
});
test('should save urls from newly opened tabs', async () => {
@@ -331,7 +331,7 @@ describe('enqueueLinksByClickingElements()', () => {
expect(interceptedRequests).toHaveLength(1);
expect(interceptedRequests[0].url).toBe('https://example.com/');
const pageContent = await page.content();
- expect(pageContent).toEqual(expect.arrayContaining(['onclick="return window.open(']));
+ expect(pageContent).toMatch('onclick="return window.open(');
});
});
});
diff --git a/test/enqueue_links/enqueue_links.test.js b/test/enqueue_links/enqueue_links.test.js
index 068777102..364cb7a3f 100644
--- a/test/enqueue_links/enqueue_links.test.js
+++ b/test/enqueue_links/enqueue_links.test.js
@@ -269,7 +269,7 @@ describe('enqueueLinks()', () => {
await enqueueLinks({ page, selector: '.click', requestQueue, pseudoUrls });
throw new Error('Wrong error.');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['pseudoUrls[1]']));
+ expect(err.message).toMatch('pseudoUrls[1]');
expect(enqueued).toHaveLength(0);
}
});
@@ -549,7 +549,7 @@ describe('enqueueLinks()', () => {
await enqueueLinks({ $, selector: '.click', requestQueue, pseudoUrls });
throw new Error('Wrong error.');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['pseudoUrls[1]']));
+ expect(err.message).toMatch('pseudoUrls[1]');
expect(enqueued).toHaveLength(0);
}
});
@@ -604,7 +604,7 @@ describe('enqueueLinks()', () => {
await enqueueLinks({ $, requestQueue });
throw new Error('wrong error');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['/x/absolutepath']));
+ expect(err.message).toMatch('/x/absolutepath');
}
expect(enqueued).toHaveLength(0);
});
diff --git a/test/key_value_store.test.js b/test/key_value_store.test.js
index fc1811da3..e71df8b85 100644
--- a/test/key_value_store.test.js
+++ b/test/key_value_store.test.js
@@ -25,7 +25,7 @@ describe('KeyValueStore', () => {
const obj = {};
obj.self = obj;
expect(() => maybeStringify(obj, { contentType: null })).toThrowError(
- 'The "value" parameter cannot be stringified to JSON: Converting circular structure to JSON'
+ 'The "value" parameter cannot be stringified to JSON: Converting circular structure to JSON',
);
});
});
@@ -50,7 +50,7 @@ describe('KeyValueStore', () => {
});
});
- describe('local', async () => {
+ describe('local', () => {
test('should work', async () => {
const store = new KeyValueStoreLocal('my-store-id', LOCAL_STORAGE_DIR);
const store2 = new KeyValueStoreLocal('another-store-id', LOCAL_STORAGE_DIR);
@@ -73,7 +73,7 @@ describe('KeyValueStore', () => {
throw new Error('This should throw!!!');
} catch (err) {
expect(err).toBeInstanceOf(Error);
- expect(err.message).toEqual(expect.arrayContaining(['This should throw!!!']));
+ expect(err.message).not.toMatch('This should throw!!!');
}
// Check that it still exists.
@@ -111,7 +111,7 @@ describe('KeyValueStore', () => {
});
});
- describe('remote', async () => {
+ describe('remote', () => {
test('works', async () => {
const store = new KeyValueStore('some-id-1');
const mock = sinon.mock(apifyClient.keyValueStores);
@@ -178,7 +178,7 @@ describe('KeyValueStore', () => {
});
});
- describe('Apify.openKeyValueStore', async () => {
+ describe('Apify.openKeyValueStore', () => {
test('should work', async () => {
const mock = sinon.mock(utils);
@@ -205,14 +205,14 @@ describe('KeyValueStore', () => {
});
});
- describe('getValue', async () => {
+ describe('getValue', () => {
test('throws on invalid args', async () => {
process.env[ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID] = '1234';
process.env[ENV_VARS.LOCAL_STORAGE_DIR] = LOCAL_STORAGE_DIR;
- await expect(Apify.getValue()).to.be.rejectedWith('Parameter "key" of type String must be provided');
- await expect(Apify.getValue({})).to.be.rejectedWith('Parameter "key" of type String must be provided');
- await expect(Apify.getValue('')).to.be.rejectedWith('The "key" parameter cannot be empty');
- await expect(Apify.getValue(null)).to.be.rejectedWith('Parameter "key" of type String must be provided');
+ await expect(Apify.getValue()).rejects.toThrow('Parameter "key" of type String must be provided');
+ await expect(Apify.getValue({})).rejects.toThrow('Parameter "key" of type String must be provided');
+ await expect(Apify.getValue('')).rejects.toThrow('The "key" parameter cannot be empty');
+ await expect(Apify.getValue(null)).rejects.toThrow('Parameter "key" of type String must be provided');
delete process.env[ENV_VARS.LOCAL_STORAGE_DIR];
});
@@ -224,55 +224,55 @@ describe('KeyValueStore', () => {
process.env[ENV_VARS.TOKEN] = 'xxx';
const errMsg = 'The \'APIFY_DEFAULT_KEY_VALUE_STORE_ID\' environment variable is not defined';
- await expect(Apify.getValue('KEY')).to.be.rejectedWith(errMsg);
+ await expect(Apify.getValue('KEY')).rejects.toThrow(errMsg);
delete process.env[ENV_VARS.TOKEN];
- }
+ },
);
});
- describe('setValue', async () => {
+ describe('setValue', () => {
test('throws on invalid args', async () => {
process.env[ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID] = '12345';
process.env[ENV_VARS.LOCAL_STORAGE_DIR] = LOCAL_STORAGE_DIR;
- await expect(Apify.setValue()).to.be.rejectedWith('Parameter "key" of type String must be provided');
- await expect(Apify.setValue('', null)).to.be.rejectedWith('The "key" parameter cannot be empty');
- await expect(Apify.setValue('', 'some value')).to.be.rejectedWith('The "key" parameter cannot be empty');
- await expect(Apify.setValue({}, 'some value')).to.be.rejectedWith('Parameter "key" of type String must be provided');
- await expect(Apify.setValue(123, 'some value')).to.be.rejectedWith('Parameter "key" of type String must be provided');
+ await expect(Apify.setValue()).rejects.toThrow('Parameter "key" of type String must be provided');
+ await expect(Apify.setValue('', null)).rejects.toThrow('The "key" parameter cannot be empty');
+ await expect(Apify.setValue('', 'some value')).rejects.toThrow('The "key" parameter cannot be empty');
+ await expect(Apify.setValue({}, 'some value')).rejects.toThrow('Parameter "key" of type String must be provided');
+ await expect(Apify.setValue(123, 'some value')).rejects.toThrow('Parameter "key" of type String must be provided');
const valueErrMsg = 'The "value" parameter must be a String or Buffer when "options.contentType" is specified';
- await expect(Apify.setValue('key', {}, { contentType: 'image/png' })).to.be.rejectedWith(valueErrMsg);
- await expect(Apify.setValue('key', 12345, { contentType: 'image/png' })).to.be.rejectedWith(valueErrMsg);
- await expect(Apify.setValue('key', () => {}, { contentType: 'image/png' })).to.be.rejectedWith(valueErrMsg);
+ await expect(Apify.setValue('key', {}, { contentType: 'image/png' })).rejects.toThrow(valueErrMsg);
+ await expect(Apify.setValue('key', 12345, { contentType: 'image/png' })).rejects.toThrow(valueErrMsg);
+ await expect(Apify.setValue('key', () => {}, { contentType: 'image/png' })).rejects.toThrow(valueErrMsg);
const optsErrMsg = 'Parameter "options" of type Object must be provided';
- await expect(Apify.setValue('key', {}, 123)).to.be.rejectedWith(optsErrMsg);
- await expect(Apify.setValue('key', {}, 'bla/bla')).to.be.rejectedWith(optsErrMsg);
- await expect(Apify.setValue('key', {}, true)).to.be.rejectedWith(optsErrMsg);
+ await expect(Apify.setValue('key', {}, 123)).rejects.toThrow(optsErrMsg);
+ await expect(Apify.setValue('key', {}, 'bla/bla')).rejects.toThrow(optsErrMsg);
+ await expect(Apify.setValue('key', {}, true)).rejects.toThrow(optsErrMsg);
const circularObj = {};
circularObj.xxx = circularObj;
const circularErrMsg = 'The "value" parameter cannot be stringified to JSON: Converting circular structure to JSON';
const undefinedErrMsg = 'The "value" parameter was stringified to JSON and returned undefined. '
+ 'Make sure you\'re not trying to stringify an undefined value.';
- await expect(Apify.setValue('key', circularObj)).to.be.rejectedWith(circularErrMsg);
- await expect(Apify.setValue('key', undefined)).to.be.rejectedWith(undefinedErrMsg);
- await expect(Apify.setValue('key')).to.be.rejectedWith(undefinedErrMsg);
+ await expect(Apify.setValue('key', circularObj)).rejects.toThrow(circularErrMsg);
+ await expect(Apify.setValue('key', undefined)).rejects.toThrow(undefinedErrMsg);
+ await expect(Apify.setValue('key')).rejects.toThrow(undefinedErrMsg);
const contTypeRedundantErrMsg = 'The "options.contentType" parameter must not be used when removing the record';
- await expect(Apify.setValue('key', null, { contentType: 'image/png' })).to.be.rejectedWith(contTypeRedundantErrMsg);
- await expect(Apify.setValue('key', null, { contentType: '' })).to.be.rejectedWith(contTypeRedundantErrMsg);
+ await expect(Apify.setValue('key', null, { contentType: 'image/png' })).rejects.toThrow(contTypeRedundantErrMsg);
+ await expect(Apify.setValue('key', null, { contentType: '' })).rejects.toThrow(contTypeRedundantErrMsg);
await expect(Apify.setValue('key', null, { contentType: {} }))
- .to.be.rejectedWith('Parameter "options.contentType" of type String | Null | Undefined must be provided');
+ .rejects.toThrow('Parameter "options.contentType" of type String | Null | Undefined must be provided');
const contTypeStringErrMsg = 'Parameter "options.contentType" of type String | Null | Undefined must be provided';
- await expect(Apify.setValue('key', 'value', { contentType: 123 })).to.be.rejectedWith(contTypeStringErrMsg);
- await expect(Apify.setValue('key', 'value', { contentType: {} })).to.be.rejectedWith(contTypeStringErrMsg);
- await expect(Apify.setValue('key', 'value', { contentType: new Date() })).to.be.rejectedWith(contTypeStringErrMsg);
+ await expect(Apify.setValue('key', 'value', { contentType: 123 })).rejects.toThrow(contTypeStringErrMsg);
+ await expect(Apify.setValue('key', 'value', { contentType: {} })).rejects.toThrow(contTypeStringErrMsg);
+ await expect(Apify.setValue('key', 'value', { contentType: new Date() })).rejects.toThrow(contTypeStringErrMsg);
await expect(Apify.setValue('key', 'value', { contentType: '' }))
- .to.be.rejectedWith('Parameter options.contentType cannot be empty string.');
+ .rejects.toThrow('Parameter options.contentType cannot be empty string.');
delete process.env[ENV_VARS.LOCAL_STORAGE_DIR];
});
@@ -311,10 +311,10 @@ describe('KeyValueStore', () => {
process.env[ENV_VARS.TOKEN] = 'xxx';
const errMsg = 'The \'APIFY_DEFAULT_KEY_VALUE_STORE_ID\' environment variable is not defined';
- await expect(Apify.setValue('KEY', {})).to.be.rejectedWith(errMsg);
+ await expect(Apify.setValue('KEY', {})).rejects.toThrow(errMsg);
delete process.env[ENV_VARS.TOKEN];
- }
+ },
);
test('correctly adds charset to content type', async () => {
@@ -501,7 +501,7 @@ describe('KeyValueStore', () => {
});
});
- describe('getInput', async () => {
+ describe('getInput', () => {
test('should work', async () => {
process.env[ENV_VARS.LOCAL_STORAGE_DIR] = LOCAL_STORAGE_DIR;
const defaultStore = await Apify.openKeyValueStore();
diff --git a/test/puppeteer.test.js b/test/puppeteer.test.js
index e5a29c2f3..506ec0545 100644
--- a/test/puppeteer.test.js
+++ b/test/puppeteer.test.js
@@ -57,29 +57,28 @@ beforeAll(() => {
afterAll(() => {
process.env[ENV_VARS.HEADLESS] = prevEnvHeadless;
- this.timeout(5 * 1000);
if (proxyServer) return util.promisify(proxyServer.close).bind(proxyServer)();
-});
+}, 5000);
describe('Apify.launchPuppeteer()', () => {
test('throws on invalid args', () => {
- expect(Apify.launchPuppeteer('some non-object')).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer(1234)).to.be.rejectedWith(Error);
-
- expect(Apify.launchPuppeteer({ proxyUrl: 234 })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: {} })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'invalidurl' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'http://host-without-port' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'invalid://somehost:1234' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'https://user:[email protected]:1234' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'socks4://user:[email protected]:1234' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'socks5://user:[email protected]:1234' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: ' something really bad' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ proxyUrl: 'xxx', useApifyProxy: true })).to.be.rejectedWith(Error);
-
- expect(Apify.launchPuppeteer({ args: 'wrong args' })).to.be.rejectedWith(Error);
- expect(Apify.launchPuppeteer({ args: [12, 34] })).to.be.rejectedWith(Error);
+ expect(Apify.launchPuppeteer('some non-object')).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer(1234)).rejects.toThrow(Error);
+
+ expect(Apify.launchPuppeteer({ proxyUrl: 234 })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: {} })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'invalidurl' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'http://host-without-port' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'invalid://somehost:1234' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'https://user:[email protected]:1234' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'socks4://user:[email protected]:1234' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'socks5://user:[email protected]:1234' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: ' something really bad' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ proxyUrl: 'xxx', useApifyProxy: true })).rejects.toThrow(Error);
+
+ expect(Apify.launchPuppeteer({ args: 'wrong args' })).rejects.toThrow(Error);
+ expect(Apify.launchPuppeteer({ args: [12, 34] })).rejects.toThrow(Error);
});
test('opens supports non-HTTP proxies without authentication', async () => {
@@ -114,7 +113,7 @@ describe('Apify.launchPuppeteer()', () => {
return page.goto('https://www.example.com');
})
.then(() => page.content())
- .then(html => expect(html).to.include('<h1>Example Domain</h1>'))
+ .then(html => expect(html).toMatch('<h1>Example Domain</h1>'))
.then(() => browser.close());
});
@@ -140,11 +139,11 @@ describe('Apify.launchPuppeteer()', () => {
return page.goto('https://example.com');
})
.then(() => {
- expect(wasProxyCalled).to.eql(true);
+ expect(wasProxyCalled).toBe(true);
return page.content();
})
- .then(html => expect(html).to.include('<h1>Example Domain</h1>'))
+ .then(html => expect(html).toMatch('<h1>Example Domain</h1>'))
.then(() => browser.close());
});
@@ -171,7 +170,7 @@ describe('Apify.launchPuppeteer()', () => {
return page.content();
})
.then((html) => {
- expect(html).to.contain(`"user-agent": "${opts.userAgent}"`);
+ expect(html).toMatch(`"user-agent": "${opts.userAgent}"`);
return browser.close();
});
});
@@ -195,10 +194,10 @@ describe('Apify.launchPuppeteer()', () => {
const title = await page.title();
const version = await browser.version();
- expect(title).to.be.eql('Example Domain');
- expect(version).to.include('Chrome');
- expect(version).not.to.include('Chromium');
- expect(spy.calledOnce).to.be.eql(true);
+ expect(title).toBe('Example Domain');
+ expect(version).toMatch('Chrome');
+ expect(version).not.toMatch('Chromium');
+ expect(spy.calledOnce).toBe(true);
} finally {
spy.restore();
if (browser) await browser.close();
@@ -249,7 +248,7 @@ describe('Apify.launchPuppeteer()', () => {
headless: true,
};
- expect(Apify.launchPuppeteer(opts)).to.be.rejectedWith(Error);
- }
+ expect(Apify.launchPuppeteer(opts)).rejects.toThrow(Error);
+ },
);
});
diff --git a/test/puppeteer_pool.test.js b/test/puppeteer_pool.test.js
index 5b08c368c..d92a94193 100644
--- a/test/puppeteer_pool.test.js
+++ b/test/puppeteer_pool.test.js
@@ -538,7 +538,7 @@ describe('PuppeteerPool', () => {
await pool.newPage();
throw new Error('Invalid error.');
} catch (err) {
- expect(err.stack).toEqual(expect.arrayContaining(['useApifyProxy']));
+ expect(err.stack).toMatch('useApifyProxy');
}
});
@@ -550,7 +550,7 @@ describe('PuppeteerPool', () => {
});
throw new Error('Invalid error.');
} catch (err) {
- expect(err.message).toEqual(expect.arrayContaining(['must not be empty']));
+ expect(err.message).toMatch('must not be empty');
}
});
});
@@ -579,7 +579,7 @@ describe('PuppeteerPool', () => {
await pool._openNewTab(); // eslint-disable-line no-underscore-dangle
throw new Error('invalid error');
} catch (err) {
- expect(err.stack).toEqual(expect.arrayContaining(['PuppeteerPool: browser.newPage() timed out.']));
+ expect(err.stack).toMatch('PuppeteerPool: browser.newPage() timed out.');
}
});
});
diff --git a/test/puppeteer_utils.test.js b/test/puppeteer_utils.test.js
index 61b149057..ea792495f 100644
--- a/test/puppeteer_utils.test.js
+++ b/test/puppeteer_utils.test.js
@@ -111,30 +111,6 @@ describe('Apify.utils.puppeteer', () => {
}
});
- test('hideWebDriver()', async () => {
- const browser = await Apify.launchPuppeteer({ headless: true });
-
- try {
- const page = await browser.newPage();
- await page.goto('about:blank');
-
- // TODO: Jarda, please can you add unit test for this?
- /*
- const result1 = await page.evaluate(() => {
- return { isDefined: window._ !== undefined };
- });
- expect(result1).to.eql({ isDefined: false });
-
- await Apify.utils.puppeteer.hideWebDriver(page);
- const result2 = await page.evaluate(() => {
- return { isDefined: _.isEmpty({}) };
- });
- expect(result2).to.eql({ isDefined: true }); */
- } finally {
- browser.close();
- }
- });
-
// TODO Remove with 1.0.0. This is here as a backwards comp for moving
// the function from utils.puppeteer to utils.
test('enqueueLinks() exists in this namespace', async () => {
@@ -142,9 +118,7 @@ describe('Apify.utils.puppeteer', () => {
try {
await Apify.utils.puppeteer.enqueueLinks({ page: {}, $: () => {} });
} catch (err) {
- expect(err.message).toBe(
- 'Only one of the parameters "options.page" or "options.$" must be provided!'
- );
+ expect(err.message).toBe('Only one of the parameters "options.page" or "options.$" must be provided!');
}
});
@@ -165,9 +139,7 @@ describe('Apify.utils.puppeteer', () => {
} finally {
await browser.close();
}
- expect(loadedUrls).toEqual(expect.arrayContaining([
- 'https://example.com/script.js',
- ]));
+ expect(loadedUrls).toEqual(['https://example.com/script.js']);
});
test('blockRequests() works with overridden values', async () => {
@@ -297,7 +269,7 @@ describe('Apify.utils.puppeteer', () => {
await testRuleType([]);
await testRuleType(['']);
await testRuleType(() => {});
- }
+ },
);
test('compileScript() works', async () => {
@@ -306,7 +278,7 @@ describe('Apify.utils.puppeteer', () => {
const scriptStringBad = 'for const while';
const script = compileScript(scriptStringGood);
- expect(script).toBeInstanceOf(Function);
+ expect(typeof script).toBe('function');
expect(script.toString()).toEqual(`async ({ page, request }) => {${scriptStringGood}}`);
try {
@@ -314,7 +286,7 @@ describe('Apify.utils.puppeteer', () => {
throw new Error('Should fail.');
} catch (err) {
// TODO figure out why the err.message comes out empty in the logs.
- expect(err.message).toEqual(expect.arrayContaining(['Unexpected token const']));
+ expect(err.message).toMatch('Unexpected token const');
}
const browser = await Apify.launchPuppeteer({ headless: true });
try {
diff --git a/test/request.test.js b/test/request.test.js
index 0703a611b..17aadf81d 100644
--- a/test/request.test.js
+++ b/test/request.test.js
@@ -30,7 +30,7 @@ describe('Apify.Request', () => {
const uniqueKey = `POST(${payloadHash}):${normalizedUrl}`;
expect(request.uniqueKey).toEqual(uniqueKey);
- }
+ },
);
test('works', () => {
@@ -53,7 +53,7 @@ describe('Apify.Request', () => {
},
handledAt: new Date(),
};
- expect(new Apify.Request(data)).toEqual(expect.arrayContaining([data]));
+ expect(new Apify.Request(data)).toMatchObject(data);
data.handledAt = (new Date()).toISOString();
expect((new Apify.Request(data)).handledAt).toBeInstanceOf(Date);
@@ -110,9 +110,9 @@ describe('Apify.Request', () => {
request.pushErrorMessage(new Error('error message.'));
const last = request.errorMessages.pop();
- expect(last).toEqual(expect.arrayContaining(['error message.']));
- expect(last).toEqual(expect.arrayContaining([' at ']));
- expect(last).toEqual(expect.arrayContaining([__filename.split(/[\\/]/g).pop()]));
+ expect(last).toMatch('error message.');
+ expect(last).toMatch(' at ');
+ expect(last).toMatch(__filename.split(/[\\/]/g).pop());
});
test('should not allow to have a GET request with payload', () => {
diff --git a/test/request_list.test.js b/test/request_list.test.js
index be9c9c3d2..c7e53f652 100644
--- a/test/request_list.test.js
+++ b/test/request_list.test.js
@@ -48,22 +48,22 @@ describe('Apify.RequestList', () => {
const requestList = new Apify.RequestList({ sources: [{ url: 'https://example.com' }] });
const requestObj = new Apify.Request({ url: 'https://example.com' });
- await expect(requestList.isEmpty()).to.be.rejectedWith();
- await expect(requestList.isFinished()).to.be.rejectedWith();
+ await expect(requestList.isEmpty()).rejects.toThrow();
+ await expect(requestList.isFinished()).rejects.toThrow();
expect(() => requestList.getState()).toThrowError();
- await expect(requestList.markRequestHandled(requestObj)).to.be.rejectedWith();
- await expect(requestList.reclaimRequest(requestObj)).to.be.rejectedWith();
- await expect(requestList.fetchNextRequest()).to.be.rejectedWith();
+ await expect(requestList.markRequestHandled(requestObj)).rejects.toThrow();
+ await expect(requestList.reclaimRequest(requestObj)).rejects.toThrow();
+ await expect(requestList.fetchNextRequest()).rejects.toThrow();
await requestList.initialize();
- await expect(requestList.isEmpty()).to.not.be.rejectedWith();
- await expect(requestList.isFinished()).to.not.be.rejectedWith();
+ await expect(requestList.isEmpty()).resolves.not.toThrow();
+ await expect(requestList.isFinished()).resolves.not.toThrow();
expect(() => requestList.getState()).not.toThrowError();
- await expect(requestList.fetchNextRequest()).to.not.be.rejectedWith();
- await expect(requestList.reclaimRequest(requestObj)).to.not.be.rejectedWith();
- await expect(requestList.fetchNextRequest()).to.not.be.rejectedWith();
- await expect(requestList.markRequestHandled(requestObj)).to.not.be.rejectedWith();
+ await expect(requestList.fetchNextRequest()).resolves.not.toThrow();
+ await expect(requestList.reclaimRequest(requestObj)).resolves.not.toThrow();
+ await expect(requestList.fetchNextRequest()).resolves.not.toThrow();
+ await expect(requestList.markRequestHandled(requestObj)).resolves.not.toThrow();
});
test('should correctly initialize itself', async () => {
@@ -149,7 +149,7 @@ describe('Apify.RequestList', () => {
mock.verify();
mock.restore();
- }
+ },
);
test('should use regex parameter to parse urls', async () => {
@@ -248,7 +248,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toMatchObject(requestList.reclaimed);
//
// Mark 1st, 2nd handled
@@ -271,7 +271,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Mark 5th handled
@@ -289,7 +289,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Fetch 3rd and 4th
@@ -311,7 +311,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Mark 3rd handled
@@ -326,7 +326,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Fetch 6th
@@ -345,7 +345,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(true);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Reclaim 6th
@@ -362,7 +362,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(false);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Fetch 6th
@@ -380,7 +380,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(true);
expect(await requestList.isFinished()).toBe(false);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
//
// Mark 6th handled
@@ -395,7 +395,7 @@ describe('Apify.RequestList', () => {
});
expect(await requestList.isEmpty()).toBe(true);
expect(await requestList.isFinished()).toBe(true);
- expect(requestList.inProgress).toEqual(expect.arrayContaining([requestList.reclaimed]));
+ expect(requestList.inProgress).toEqual(expect.objectContaining(requestList.reclaimed));
});
test(
@@ -463,7 +463,7 @@ describe('Apify.RequestList', () => {
expect(requestList2.getState()).toEqual(requestList.getState());
mock.verify();
- }
+ },
);
test(
@@ -526,7 +526,7 @@ describe('Apify.RequestList', () => {
expect(requestList2.requests).toEqual(requestList.requests);
mock.verify();
- }
+ },
);
test(
@@ -574,7 +574,7 @@ describe('Apify.RequestList', () => {
kvsMock.verify();
publicUtilsMock.verify();
- }
+ },
);
test('handles correctly inconsistent inProgress fields in state', async () => {
@@ -701,11 +701,11 @@ describe('Apify.RequestList', () => {
await requestList.initialize();
expect(requestList.length()).toBe(6);
expect(logStub.called).toBe(true);
- expect(logStub.getCall(0).args[0]).toEqual(expect.arrayContaining(['Check your sources\' unique keys.']));
+ expect(logStub.getCall(0).args[0]).toMatch('Check your sources\' unique keys.');
logStub.restore();
log.setLevel(log.LEVELS.ERROR);
- }
+ },
);
describe('Apify.openRequestList()', () => {
@@ -796,8 +796,8 @@ describe('Apify.RequestList', () => {
throw new Error('wrong error');
} catch (err) {
expect(err.message).not.toBe('wrong error');
- expect(err.message).toEqual(expect.arrayContaining(['Parameter']));
- expect(err.message).not.toBe('must');
+ expect(err.message).toMatch('Parameter');
+ expect(err.message).toMatch('must');
}
}
});
diff --git a/test/request_queue.test.js b/test/request_queue.test.js
index 692d6bde9..a70b7e71d 100644
--- a/test/request_queue.test.js
+++ b/test/request_queue.test.js
@@ -22,7 +22,7 @@ describe('RequestQueue', () => {
beforeEach(() => emptyLocalStorageSubdir(LOCAL_STORAGE_SUBDIR));
afterEach(() => emptyLocalStorageSubdir(LOCAL_STORAGE_SUBDIR));
- describe('local', async () => {
+ describe('local', () => {
test('should work', async () => {
const queue = new RequestQueueLocal('my-queue-0', LOCAL_STORAGE_DIR);
@@ -69,8 +69,8 @@ describe('RequestQueue', () => {
.catch(err => expect(err.message).toMatch(/Cannot reclaim request XXX, because it is not in progress/));
await queue.addRequest(new Apify.Request({ id: 'id-already-set', url: 'dummy' }))
.catch(err => expect(err.message).toMatch(
- /Request already has the "id" field set so it cannot be added to the queue/
- ));
+ /Request already has the "id" field set so it cannot be added to the queue/,
+ ));
// Check that changes to Requests are persisted to Queue.
request1.errorMessages = ['Hello'];
@@ -123,7 +123,7 @@ describe('RequestQueue', () => {
await queue.addRequest({ url: '' });
expect(false).toBe(true);
} catch (e) {
- expect(e.message).toEqual(expect.arrayContaining(['The "url" option cannot be empty string']));
+ expect(e.message).toMatch('The "url" option cannot be empty string');
}
await queue.addRequest(new Apify.Request({ url: 'something' }));
await Apify.utils.sleep(20);
@@ -293,7 +293,7 @@ describe('RequestQueue', () => {
});
});
- describe('remote', async () => {
+ describe('remote', () => {
test('should work', async () => {
expectNotUsingLocalStorage();
@@ -377,8 +377,8 @@ describe('RequestQueue', () => {
.catch(err => expect(err.message).toMatch(/Cannot reclaim request XXX, because it is not in progress/));
await queue.addRequest(new Request({ id: 'id-already-set', url: 'dummy' }))
.catch(err => expect(err.message).toMatch(
- /Request already has the "id" field set so it cannot be added to the queue/
- ));
+ /Request already has the "id" field set so it cannot be added to the queue/,
+ ));
// getRequest() returns null if object was not found.
mock.expects('getRequest')
@@ -560,7 +560,7 @@ describe('RequestQueue', () => {
mock.verify();
mock.restore();
- }
+ },
);
test('should cache requests from queue head', async () => {
@@ -670,7 +670,7 @@ describe('RequestQueue', () => {
mock.verify();
mock.restore();
- }
+ },
);
test('should not add handled request to queue head dict', async () => {
@@ -790,7 +790,7 @@ describe('RequestQueue', () => {
mock.verify();
mock.restore();
- }
+ },
);
test(
@@ -918,7 +918,7 @@ describe('RequestQueue', () => {
mock.verify();
mock.restore();
- }
+ },
);
test('getInfo() should work', async () => {
@@ -963,7 +963,7 @@ describe('RequestQueue', () => {
});
});
- describe('Apify.openRequestQueue', async () => {
+ describe('Apify.openRequestQueue', () => {
test('should work', () => {
const mock = sinon.mock(utils);
diff --git a/test/session_pool/session.test.js b/test/session_pool/session.test.js
index 9e6e302f1..7bdaacb41 100644
--- a/test/session_pool/session.test.js
+++ b/test/session_pool/session.test.js
@@ -5,7 +5,7 @@ import EVENTS from '../../build/session_pool/events';
import Apify from '../../build';
-describe('Session - testing session behaviour ', async () => {
+describe('Session - testing session behaviour ', () => {
let sessionPool;
let session;
diff --git a/test/session_pool/session_pool.test.js b/test/session_pool/session_pool.test.js
index faa18add4..ba04c4304 100644
--- a/test/session_pool/session_pool.test.js
+++ b/test/session_pool/session_pool.test.js
@@ -6,7 +6,7 @@ import events from '../../build/events';
import { ACTOR_EVENT_NAMES_EX } from '../../build/constants';
import { Session } from '../../src/session_pool/session';
-describe('SessionPool - testing session pool', async () => {
+describe('SessionPool - testing session pool', () => {
let sessionPool;
beforeAll(() => {
@@ -147,7 +147,7 @@ describe('SessionPool - testing session pool', async () => {
const loadedSessionPool = new SessionPool();
await loadedSessionPool.initialize();
- expect(loadedSessionPool).toEqual(expect.arrayContaining(Object.keys(sessionPool)));
+ expect(loadedSessionPool).toEqual(expect.objectContaining(sessionPool));
});
test('should create only maxPoolSize number of sessions', async () => {
diff --git a/test/stealth/stealth.test.js b/test/stealth/stealth.test.js
index a1d339f13..dd248129c 100644
--- a/test/stealth/stealth.test.js
+++ b/test/stealth/stealth.test.js
@@ -159,7 +159,7 @@ describe('Stealth - testing headless chrome hiding tricks', () => {
const { hasChrome } = await getFingerPrint(page);
const chrome = await page.evaluate(() => window.chrome); //eslint-disable-line
expect(chrome).toBeInstanceOf(Object);
- expect(chrome.runtime).toHaveLength(0); // eslint-disable-line
+ expect(chrome.runtime).toEqual({}); // eslint-disable-line
expect(hasChrome).toBe(true);
return browser.close();
diff --git a/test/utils.test.js b/test/utils.test.js
index 3dbdac23c..33976b609 100644
--- a/test/utils.test.js
+++ b/test/utils.test.js
@@ -524,7 +524,7 @@ describe('Apify.utils.downloadListOfUrls()', () => {
return expect(downloadListOfUrls({
url: 'nowhere',
- })).toEqual(arr);
+ })).resolves.toEqual(arr);
});
});
@@ -536,7 +536,7 @@ describe('Apify.utils.getRandomUserAgent()', () => {
});
});
-describe('utils.openLocalStorage()', async () => {
+describe('utils.openLocalStorage()', () => {
test(
'should return item from cache if available and create new one otherwise',
async () => {
@@ -602,7 +602,7 @@ describe('utils.openLocalStorage()', async () => {
);
});
-describe('utils.openRemoteStorage()', async () => {
+describe('utils.openRemoteStorage()', () => {
test(
'should return item from cache if available and create new one otherwise',
async () => {
diff --git a/test/utils_request.test.js b/test/utils_request.test.js
index d5c2d6ef6..6f31fe788 100644
--- a/test/utils_request.test.js
+++ b/test/utils_request.test.js
@@ -11,12 +11,9 @@ const CONTENT = 'CONTENT';
const HOST = '127.0.0.1';
describe('Apify.utils_request', () => {
- let mochaListener;
let port;
let server;
beforeAll(async () => {
- mochaListener = process.listeners('uncaughtException').shift();
- process.removeListener('uncaughtException', mochaListener);
const app = express();
app.get('/406', (req, res) => {
@@ -58,7 +55,7 @@ describe('Apify.utils_request', () => {
port = server.address().port; //eslint-disable-line
});
- describe('Apify.requestAsBrowser', async () => {
+ describe('Apify.requestAsBrowser', () => {
test(
'it uses mobile user-agent whe mobile property is set to true ',
async () => {
@@ -69,7 +66,7 @@ describe('Apify.utils_request', () => {
const response = await requestAsBrowser(data);
expect(response.statusCode).toBe(200);
expect(JSON.parse(response.body)['user-agent']).toEqual(FIREFOX_MOBILE_USER_AGENT);
- }
+ },
);
test('uses desktop user-agent by default ', async () => {
diff --git a/test/utils_social.test.js b/test/utils_social.test.js
index c3c71b116..62298a9a9 100644
--- a/test/utils_social.test.js
+++ b/test/utils_social.test.js
@@ -7,11 +7,11 @@ const { social } = Apify.utils;
describe('utils.social', () => {
describe('emailsFromText()', () => {
const testEmailsFromText = (text, phones) => {
- expect(social.emailsFromText(text)).to.eql(phones);
+ expect(social.emailsFromText(text)).toEqual(phones);
};
test('works with arg with no emails or invalid', () => {
- expect(social.emailsFromText()).to.eql([]);
+ expect(social.emailsFromText()).toEqual([]);
testEmailsFromText('', []);
testEmailsFromText(null, []);
testEmailsFromText(undefined, []);
@@ -54,28 +54,28 @@ describe('utils.social', () => {
test('throws on invalid arg', () => {
expect(() => {
social.emailsFromUrls();
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.emailsFromUrls({});
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.emailsFromUrls('fwefwef');
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.emailsFromUrls(12345);
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
});
test('extracts emails correctly', () => {
- expect(social.emailsFromUrls([])).to.eql([]);
- expect(social.emailsFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
+ expect(social.emailsFromUrls([])).toEqual([]);
+ expect(social.emailsFromUrls([1, 2, {}, 'fwef', null, undefined])).toEqual([]);
expect(social.emailsFromUrls([
- ])).to.eql([
+ ])).toEqual([
]);
@@ -86,7 +86,7 @@ describe('utils.social', () => {
'',
'\n\n\n',
- ])).to.eql([
+ ])).toEqual([
]);
@@ -98,7 +98,7 @@ describe('utils.social', () => {
'',
'\n\n\n',
- ])).to.eql([
+ ])).toEqual([
]);
@@ -107,11 +107,11 @@ describe('utils.social', () => {
describe('phonesFromText()', () => {
const testPhonesFromText = (text, phones) => {
- expect(social.phonesFromText(text)).to.eql(phones);
+ expect(social.phonesFromText(text)).toEqual(phones);
};
test('works with arg with no phones or invalid', () => {
- expect(social.phonesFromText()).to.eql([]);
+ expect(social.phonesFromText()).toEqual([]);
testPhonesFromText('', []);
testPhonesFromText(null, []);
@@ -243,24 +243,24 @@ describe('utils.social', () => {
test('throws on invalid arg', () => {
expect(() => {
social.phonesFromUrls();
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.phonesFromUrls({});
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.phonesFromUrls('fwefwef');
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
expect(() => {
social.phonesFromUrls(12345);
- }).to.throw(/must be an array/);
+ }).toThrowError(/must be an array/);
});
test('extracts phones correctly', () => {
- expect(social.phonesFromUrls([])).to.eql([]);
- expect(social.phonesFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
+ expect(social.phonesFromUrls([])).toEqual([]);
+ expect(social.phonesFromUrls([1, 2, {}, 'fwef', null, undefined])).toEqual([]);
expect(social.phonesFromUrls([
'tel:12345678',
@@ -275,7 +275,7 @@ describe('utils.social', () => {
'callto:97345678',
'CALLTO:/+98345678',
'callto://9992345678',
- ])).to.eql([
+ ])).toEqual([
'12345678',
'22345678',
'32345678',
@@ -298,7 +298,7 @@ describe('utils.social', () => {
'tel://+42012345678',
'tel://+420.123.456',
'http://www.example.com',
- ])).to.eql([
+ ])).toEqual([
'+42012345678',
'+420.123.456',
]);
@@ -317,16 +317,16 @@ describe('utils.social', () => {
};
test('handles invalid arg', () => {
- expect(social.parseHandlesFromHtml()).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(undefined)).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(null)).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml({})).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(1234)).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml()).toEqual(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(undefined)).toEqual(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(null)).toEqual(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml({})).toEqual(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(1234)).toEqual(EMPTY_RESULT);
});
test('works', () => {
- expect(social.parseHandlesFromHtml('')).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(' ')).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml('')).toEqual(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(' ')).toEqual(EMPTY_RESULT);
expect(social.parseHandlesFromHtml(`
<html>
@@ -382,7 +382,7 @@ describe('utils.social', () => {
</body>
</html>
- `)).to.eql({
+ `)).toEqual({
phones: ['+42077533333'],
phonesUncertain: ['+4207751111111', '+420775222222'],
@@ -431,93 +431,91 @@ describe('utils.social', () => {
</html>
`, data);
- expect(data.$('body').text().trim()).to.eql('Body content');
- expect(data.text.trim()).to.eql('Body content');
+ expect(data.$('body').text().trim()).toBe('Body content');
+ expect(data.text.trim()).toBe('Body content');
});
});
describe('EMAIL_REGEX', () => {
test('works', () => {
- expect(_.isRegExp(social.EMAIL_REGEX)).to.eql(true);
- expect(_.isRegExp(social.EMAIL_REGEX_GLOBAL)).to.eql(true);
+ expect(_.isRegExp(social.EMAIL_REGEX)).toBe(true);
+ expect(_.isRegExp(social.EMAIL_REGEX_GLOBAL)).toBe(true);
- expect(social.EMAIL_REGEX.flags).to.eql('i');
- expect(social.EMAIL_REGEX_GLOBAL.flags).to.eql('gi');
+ expect(social.EMAIL_REGEX.flags).toBe('i');
+ expect(social.EMAIL_REGEX_GLOBAL.flags).toBe('gi');
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).toBe(true);
- expect(social.EMAIL_REGEX.test('a [email protected]')).to.eql(false);
- expect(social.EMAIL_REGEX.test('[email protected] [email protected]')).to.eql(false);
- expect(social.EMAIL_REGEX.test('')).to.eql(false);
- expect(social.EMAIL_REGEX.test('dummy')).to.eql(false);
+ expect(social.EMAIL_REGEX.test('a [email protected]')).toBe(false);
+ expect(social.EMAIL_REGEX.test('[email protected] [email protected]')).toBe(false);
+ expect(social.EMAIL_REGEX.test('')).toBe(false);
+ expect(social.EMAIL_REGEX.test('dummy')).toBe(false);
- expect(social.EMAIL_REGEX_GLOBAL.test('[email protected]')).to.eql(true);
- expect('[email protected] [email protected]'.match(social.EMAIL_REGEX_GLOBAL))
+ expect(social.EMAIL_REGEX_GLOBAL.test('[email protected]')).toBe(true);
+ expect('[email protected] [email protected]'.match(social.EMAIL_REGEX_GLOBAL)).toEqual(['[email protected]', '[email protected]']);
- expect(''.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
- expect(' dummy '.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.EMAIL_REGEX_GLOBAL)).toBe(null);
+ expect(' dummy '.match(social.EMAIL_REGEX_GLOBAL)).toBe(null);
});
});
describe('LINKEDIN_REGEX', () => {
test('works', () => {
- expect(_.isRegExp(social.LINKEDIN_REGEX)).to.eql(true);
- expect(_.isRegExp(social.LINKEDIN_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.LINKEDIN_REGEX.flags).to.eql('i');
- expect(social.LINKEDIN_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('http://www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('http://ie.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/carl-newman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first-last-123456a')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first_last_1%23456a')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('HTTPS://WWW.LINKEDIN.COM/IN/CARL-NEWMAN')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('linkedin.com/in/bobnewman')).to.eql(true);
-
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/alan-turing')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('en.linkedin.com/in/alan-turing')).to.eql(true);
- expect(social.LINKEDIN_REGEX.test('linkedin.com/in/alan-turing')).to.eql(true);
+ expect(_.isRegExp(social.LINKEDIN_REGEX)).toBe(true);
+ expect(_.isRegExp(social.LINKEDIN_REGEX_GLOBAL)).toBe(true);
+
+ expect(social.LINKEDIN_REGEX.flags).toBe('i');
+ expect(social.LINKEDIN_REGEX_GLOBAL.flags).toBe('gi');
+
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('http://www.linkedin.com/in/bobnewman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('http://ie.linkedin.com/in/bobnewman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/carl-newman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first-last-123456a')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first_last_1%23456a')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('HTTPS://WWW.LINKEDIN.COM/IN/CARL-NEWMAN')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('www.linkedin.com/in/bobnewman')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('linkedin.com/in/bobnewman')).toBe(true);
+
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/alan-turing')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('en.linkedin.com/in/alan-turing')).toBe(true);
+ expect(social.LINKEDIN_REGEX.test('linkedin.com/in/alan-turing')).toBe(true);
// Test there is just on matching group for the username
- expect('https://www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
- expect('http://www.linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
- expect('www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
- expect('linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
-
- expect(social.LINKEDIN_REGEX.test('')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('dummy')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('a https://www.linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman/sub-page')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('xhttps://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('0https://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('_https://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('xlinkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('_linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('0linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/?param=bla')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('://linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bob https://www.linkedin.com/in/alice')).to.eql(false);
-
- expect(social.LINKEDIN_REGEX_GLOBAL.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
+ expect('https://www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).toBe('bobnewman');
+ expect('http://www.linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).toBe('bobnewman');
+ expect('www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).toBe('bobnewman');
+ expect('linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).toBe('bobnewman');
+
+ expect(social.LINKEDIN_REGEX.test('')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('dummy')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('a https://www.linkedin.com/in/bobnewman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman/sub-page')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('xhttps://www.linkedin.com/in/carl-newman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('0https://www.linkedin.com/in/carl-newman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('_https://www.linkedin.com/in/carl-newman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('xlinkedin.com/in/bobnewman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('_linkedin.com/in/bobnewman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('0linkedin.com/in/bobnewman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/?param=bla')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('://linkedin.com/in/bobnewman')).toBe(false);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bob https://www.linkedin.com/in/alice')).toBe(false);
+
+ expect(social.LINKEDIN_REGEX_GLOBAL.test('https://www.linkedin.com/in/bobnewman')).toBe(true);
expect(`
https://www.linkedin.com/in/bobnewman
"http://ie.linkedin.com/in/alicenewman"
https://www.linkedin.com/in/someverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongname
linkedin.com/in/carlnewman
- `.match(social.LINKEDIN_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.LINKEDIN_REGEX_GLOBAL)).toEqual([
'https://www.linkedin.com/in/bobnewman',
'http://ie.linkedin.com/in/alicenewman',
'linkedin.com/in/carlnewman',
@@ -528,64 +526,62 @@ describe('utils.social', () => {
xlinkedin.com/in/carlnewman
alinkedin.com/in/carlnewman
_linkedin.com/in/carlnewman
- `.match(social.LINKEDIN_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.LINKEDIN_REGEX_GLOBAL)).toEqual([
'https://www.linkedin.com/in/bobnewman/',
'http://ie.linkedin.com/in/alicenewman',
]);
- expect(''.match(social.LINKEDIN_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.LINKEDIN_REGEX_GLOBAL)).toBe(null);
});
});
describe('INSTAGRAM_REGEX', () => {
test('works', () => {
- expect(_.isRegExp(social.INSTAGRAM_REGEX)).to.eql(true);
- expect(_.isRegExp(social.INSTAGRAM_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.INSTAGRAM_REGEX.flags).to.eql('i');
- expect(social.INSTAGRAM_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('https://instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('HTTPS://INSTAGR.AM/OLD_PRAGUE/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('http://instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('https://www.instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('www.instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_REGEX.test('instagr.am/old_prague/')).to.eql(true);
+ expect(_.isRegExp(social.INSTAGRAM_REGEX)).toBe(true);
+ expect(_.isRegExp(social.INSTAGRAM_REGEX_GLOBAL)).toBe(true);
+
+ expect(social.INSTAGRAM_REGEX.flags).toBe('i');
+ expect(social.INSTAGRAM_REGEX_GLOBAL.flags).toBe('gi');
+
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('https://instagram.com/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('HTTPS://INSTAGR.AM/OLD_PRAGUE/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('http://instagr.am/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagr.am/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('www.instagram.com/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('instagram.com/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('www.instagr.am/old_prague/')).toBe(true);
+ expect(social.INSTAGRAM_REGEX.test('instagr.am/old_prague/')).toBe(true);
// Test there is just on matching group for the username
- expect('https://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
- expect('http://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
- expect('www.instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
- expect('instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
-
- expect(social.INSTAGRAM_REGEX.test('')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('dummy')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('a https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/a')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/sub-page')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('xhttps://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('0https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('_https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('xinstagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('_instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('0instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/?param=bla')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague http://www.instagram.com/old_brno')).to.eql(false);
-
- expect(social.INSTAGRAM_REGEX_GLOBAL.test('https://www.instagram.com/old_prague')).to.eql(true);
+ expect('https://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).toBe('old_prague');
+ expect('http://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).toBe('old_prague');
+ expect('www.instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).toBe('old_prague');
+ expect('instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).toBe('old_prague');
+
+ expect(social.INSTAGRAM_REGEX.test('')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('dummy')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('a https://www.instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/a')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/sub-page')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('xhttps://www.instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('0https://www.instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('_https://www.instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('xinstagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('_instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('0instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/?param=bla')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('://www.instagram.com/old_prague')).toBe(false);
+ expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague http://www.instagram.com/old_brno')).toBe(false);
+
+ expect(social.INSTAGRAM_REGEX_GLOBAL.test('https://www.instagram.com/old_prague')).toBe(true);
expect(`
https://www.instagram.com/old_prague
https://www.instagram.com/someverylongusernamethatisnotgood
"instagram.com/old_brno"
http://instagr.am/old_plzen
- `.match(social.INSTAGRAM_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.INSTAGRAM_REGEX_GLOBAL)).toEqual([
'https://www.instagram.com/old_prague',
'instagram.com/old_brno',
'http://instagr.am/old_plzen',
@@ -596,63 +592,61 @@ describe('utils.social', () => {
xinstagram.com/old_brno
ainstagram.com/old_brno
_instagram.com/old_brno
- `.match(social.INSTAGRAM_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.INSTAGRAM_REGEX_GLOBAL)).toEqual([
'https://www.instagram.com/old_prague/',
'instagr.am/old_plzen',
]);
- expect(''.match(social.INSTAGRAM_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.INSTAGRAM_REGEX_GLOBAL)).toBe(null);
});
});
describe('TWITTER_REGEX', () => {
test('works', () => {
- expect(_.isRegExp(social.TWITTER_REGEX)).to.eql(true);
- expect(_.isRegExp(social.TWITTER_REGEX_GLOBAL)).to.eql(true);
+ expect(_.isRegExp(social.TWITTER_REGEX)).toBe(true);
+ expect(_.isRegExp(social.TWITTER_REGEX_GLOBAL)).toBe(true);
- expect(social.TWITTER_REGEX.flags).to.eql('i');
- expect(social.TWITTER_REGEX_GLOBAL.flags).to.eql('gi');
+ expect(social.TWITTER_REGEX.flags).toBe('i');
+ expect(social.TWITTER_REGEX_GLOBAL.flags).toBe('gi');
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/')).to.eql(true);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/aa_bb_123')).to.eql(true);
- expect(social.TWITTER_REGEX.test('http://www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_REGEX.test('https://twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_REGEX.test('http://twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_REGEX.test('www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_REGEX.test('twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify')).toBe(true);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/')).toBe(true);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/aa_bb_123')).toBe(true);
+ expect(social.TWITTER_REGEX.test('http://www.twitter.com/apify')).toBe(true);
+ expect(social.TWITTER_REGEX.test('https://twitter.com/apify')).toBe(true);
+ expect(social.TWITTER_REGEX.test('http://twitter.com/apify')).toBe(true);
+ expect(social.TWITTER_REGEX.test('www.twitter.com/apify')).toBe(true);
+ expect(social.TWITTER_REGEX.test('twitter.com/apify')).toBe(true);
// Test there is just on matching group for the username
- expect('https://www.twitter.com/apify/'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
- expect('http://www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
- expect('www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
- expect('twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
-
- expect(social.TWITTER_REGEX.test('')).to.eql(false);
- expect(social.TWITTER_REGEX.test('dummy')).to.eql(false);
- expect(social.TWITTER_REGEX.test('a https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/sub-page')).to.eql(false);
- expect(social.TWITTER_REGEX.test('xhttps://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('0https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('_https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('xtwitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('_twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('0twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify?param=bla')).to.eql(false);
- expect(social.TWITTER_REGEX.test('://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify https://www.twitter.com/jack')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/oauth')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/account')).to.eql(false);
- expect(social.TWITTER_REGEX.test('https://www.twitter.com/privacy/')).to.eql(false);
-
- expect(social.TWITTER_REGEX_GLOBAL.test('https://www.twitter.com/apify')).to.eql(true);
+ expect('https://www.twitter.com/apify/'.match(social.TWITTER_REGEX)[1]).toBe('apify');
+ expect('http://www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).toBe('apify');
+ expect('www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).toBe('apify');
+ expect('twitter.com/apify'.match(social.TWITTER_REGEX)[1]).toBe('apify');
+
+ expect(social.TWITTER_REGEX.test('')).toBe(false);
+ expect(social.TWITTER_REGEX.test('dummy')).toBe(false);
+ expect(social.TWITTER_REGEX.test('a https://www.twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/sub-page')).toBe(false);
+ expect(social.TWITTER_REGEX.test('xhttps://www.twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('0https://www.twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('_https://www.twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('xtwitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('_twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('0twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify?param=bla')).toBe(false);
+ expect(social.TWITTER_REGEX.test('://www.twitter.com/apify')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify https://www.twitter.com/jack')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/oauth')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/account')).toBe(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/privacy/')).toBe(false);
+
+ expect(social.TWITTER_REGEX_GLOBAL.test('https://www.twitter.com/apify')).toBe(true);
expect(`
https://www.twitter.com/apify
www.twitter.com/jack/sub-dir
www.twitter.com/invalidverylongtwitterhandlenotgood
twitter.com/bob123?param=1
- `.match(social.TWITTER_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.TWITTER_REGEX_GLOBAL)).toEqual([
'https://www.twitter.com/apify',
'www.twitter.com/jack/',
'twitter.com/bob123',
@@ -664,75 +658,73 @@ describe('utils.social', () => {
xtwitter.com/bob
atwitter.com/bob
_twitter.com/bob
- `.match(social.TWITTER_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.TWITTER_REGEX_GLOBAL)).toEqual([
'https://www.twitter.com/apify',
'twitter.com/jack',
'twitter.com/carl123',
]);
- expect(''.match(social.TWITTER_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.TWITTER_REGEX_GLOBAL)).toBe(null);
});
});
describe('FACEBOOK_REGEX', () => {
test('works', () => {
- expect(_.isRegExp(social.FACEBOOK_REGEX)).to.eql(true);
- expect(_.isRegExp(social.FACEBOOK_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.FACEBOOK_REGEX.flags).to.eql('i');
- expect(social.FACEBOOK_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/some.username123')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('www.facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername/')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('http://www.fb.com/some.username123')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('www.fb.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('fb.com/someusername')).to.eql(true);
-
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_REGEX.test('fb.com/profile.php?id=1155802082')).to.eql(true);
+ expect(_.isRegExp(social.FACEBOOK_REGEX)).toBe(true);
+ expect(_.isRegExp(social.FACEBOOK_REGEX_GLOBAL)).toBe(true);
+
+ expect(social.FACEBOOK_REGEX.flags).toBe('i');
+ expect(social.FACEBOOK_REGEX_GLOBAL.flags).toBe('gi');
+
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/some.username123')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('www.facebook.com/someusername')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('facebook.com/someusername')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername/')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.fb.com/some.username123')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('www.fb.com/someusername')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('fb.com/someusername')).toBe(true);
+
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/profile.php?id=1155802082')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php?id=1155802082')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('www.facebook.com/profile.php?id=1155802082')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('facebook.com/profile.php?id=1155802082')).toBe(true);
+ expect(social.FACEBOOK_REGEX.test('fb.com/profile.php?id=1155802082')).toBe(true);
// Test there is just on matching group for the username
- expect('https://www.facebook.com/someusername/'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
- expect('https://www.facebook.com/someusername'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
- expect('https://www.facebook.com/profile.php?id=1155802082'.match(social.FACEBOOK_REGEX)[1]).to.eql('profile.php?id=1155802082');
- expect('fb.com/someusername'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
-
- expect(social.FACEBOOK_REGEX.test('')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('dummy')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('a https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/a')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/sub-page')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('xhttps://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('0https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('_https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('xfacebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('_facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('0facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername?param=bla')).to.eql(false);
-
- expect(social.FACEBOOK_REGEX.test('://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername https://www.facebook.com/jack')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/groups')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/events')).to.eql(false);
- expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/policies/')).to.eql(false);
-
- expect(social.FACEBOOK_REGEX_GLOBAL.test('https://www.facebook.com/someusername')).to.eql(true);
+ expect('https://www.facebook.com/someusername/'.match(social.FACEBOOK_REGEX)[1]).toBe('someusername');
+ expect('https://www.facebook.com/someusername'.match(social.FACEBOOK_REGEX)[1]).toBe('someusername');
+ expect('https://www.facebook.com/profile.php?id=1155802082'.match(social.FACEBOOK_REGEX)[1]).toBe('profile.php?id=1155802082');
+ expect('fb.com/someusername'.match(social.FACEBOOK_REGEX)[1]).toBe('someusername');
+
+ expect(social.FACEBOOK_REGEX.test('')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('dummy')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('a https://www.facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/a')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/sub-page')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('xhttps://www.facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('0https://www.facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('_https://www.facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('xfacebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('_facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('0facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername?param=bla')).toBe(false);
+
+ expect(social.FACEBOOK_REGEX.test('://www.facebook.com/someusername')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername https://www.facebook.com/jack')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/groups')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/events')).toBe(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/policies/')).toBe(false);
+
+ expect(social.FACEBOOK_REGEX_GLOBAL.test('https://www.facebook.com/someusername')).toBe(true);
expect(`
https://www.facebook.com/someusername?param=123
www.facebook.com/another123/sub-dir
https://www.facebook.com/waytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusername
fb.com/bob123
- `.match(social.FACEBOOK_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.FACEBOOK_REGEX_GLOBAL)).toEqual([
'https://www.facebook.com/someusername',
'www.facebook.com/another123/',
'fb.com/bob123',
@@ -744,13 +736,12 @@ describe('utils.social', () => {
xfacebook.com/bob
afacebook.com/bob
_facebook.com/bob
- `.match(social.FACEBOOK_REGEX_GLOBAL))
- .to.eql([
+ `.match(social.FACEBOOK_REGEX_GLOBAL)).toEqual([
'https://www.facebook.com/someusername/',
'facebook.com/jack4567',
'fb.com/carl123',
]);
- expect(''.match(social.FACEBOOK_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.FACEBOOK_REGEX_GLOBAL)).toBe(null);
});
});
});