Skip to content

Commit

Permalink
test: e2e tests fix, better logging (#1713)
Browse files Browse the repository at this point in the history
- Fixes the e2e tests in regard to the new [apify.com](apify.com)
structure
- `stdout` + `stderr` from `execSync` in the e2e tests are UTF-8 decoded
now, no more byte arrays in error logs
- All e2e tests now have the new `.actor/actor.json` structure
- This was causing the PLATFORM issue, the new `apify-cli` version
automatically transforms the old config, but requires confirmation - no
interactive shell, no show, I guess 🤷🏻
  
TODO:
- random platform tests still failing, mostly because of request
timeouts - seems more like a platform issue though
  • Loading branch information
barjin authored Dec 14, 2022
1 parent e87eb1f commit fd74447
Show file tree
Hide file tree
Showing 61 changed files with 92 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-automatic-persist-value",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-autoscaling-max-tasks-per-minute",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/autoscaling-max-tasks-per-minute/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const { stats } = await runActor(testActorDirname);

await expect(stats.requestsFinished === 2, 'All requests finished');
await expect(
stats.crawlerRuntimeMillis > 60_000 && stats.crawlerRuntimeMillis < 65_000,
stats.crawlerRuntimeMillis > 60_000 && stats.crawlerRuntimeMillis < 70_000,
`Ran one task per minute, took ~1 minute to complete, but no more than that (${stats.crawlerRuntimeMillis}ms)`,
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-default-ts",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-default",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-enqueue-links",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-ignore-ssl-errors",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-initial-cookies",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-max-requests",
"version": "0.0",
"buildTag": "latest",
Expand Down
16 changes: 7 additions & 9 deletions test/e2e/cheerio-max-requests/actor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ await Actor.main(async () => {
const { url, userData: { label } } = request;

if (label === 'START') {
const links = $('.ActorStoreItem').toArray().map((item) => $(item).attr('href'));
const links = $('a.card').toArray().map((item) => $(item).attr('href'));
for (const link of links) {
const actorDetailUrl = `https://apify.com${link}`;
const actorDetailUrl = `https://crawlee.dev${link}`;
await crawler.addRequests([{
url: actorDetailUrl,
userData: { label: 'DETAIL' },
Expand All @@ -26,21 +26,19 @@ await Actor.main(async () => {
} else if (label === 'DETAIL') {
const uniqueIdentifier = url.split('/').slice(-2).join('/');
const title = $('header h1').text();
const description = $('header span.actor-description').text();
const modifiedDate = $('ul.ActorHeader-stats time').attr('datetime');
const runCount = $('ul.ActorHeader-stats > li:nth-of-type(3)').text().match(/[\d,]+/)[0].replace(/,/g, '');
const firstParagraph = $('header + p').text();
const modifiedDate = $('.theme-last-updated time').attr('datetime');

await Dataset.pushData({
url,
uniqueIdentifier,
title,
description,
modifiedDate: new Date(Number(modifiedDate)),
runCount: Number(runCount),
firstParagraph,
modifiedDate,
});
}
},
});

await crawler.run([{ url: 'https://apify.com/apify', userData: { label: 'START' } }]);
await crawler.run([{ url: 'https://crawlee.dev/docs/examples', userData: { label: 'START' } }]);
}, mainOptions);
2 changes: 1 addition & 1 deletion test/e2e/cheerio-max-requests/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ const { stats, datasetItems } = await runActor(testActorDirname);
await expect(stats.requestsFinished > 10, 'All requests finished');
await expect(datasetItems.length > 5 && datasetItems.length < 15, 'Number of dataset items');
await expect(
validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'description', 'modifiedDate', 'runCount']),
validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'firstParagraph', 'modifiedDate']),
'Dataset items validation',
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-page-info",
"version": "0.0",
"buildTag": "latest",
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/cheerio-page-info/actor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const router = createCheerioRouter();
router.addHandler('START', async ({ enqueueLinks }) => {
await enqueueLinks({
label: 'DETAIL',
globs: ['https://apify.com/apify/web-scraper'],
globs: ['**/examples/accept-user-input'],
});
});

Expand All @@ -21,17 +21,15 @@ router.addHandler('DETAIL', async ({ request, $ }) => {

const uniqueIdentifier = url.split('/').slice(-2).join('/');
const title = $('header h1').text();
const description = $('header span.actor-description').text();
const modifiedDate = $('ul.ActorHeader-stats time').attr('datetime');
const runCount = $('ul.ActorHeader-stats > li:nth-of-type(3)').text().match(/[\d,]+/)[0].replace(/,/g, '');
const firstParagraph = $('header + p').text();
const modifiedDate = $('.theme-last-updated time').attr('datetime');

await Dataset.pushData({
url,
uniqueIdentifier,
title,
description,
modifiedDate: new Date(Number(modifiedDate)),
runCount: Number(runCount),
firstParagraph,
modifiedDate,
});
});

Expand All @@ -40,5 +38,5 @@ await Actor.main(async () => {
requestHandler: router,
});

await crawler.run([{ url: 'https://apify.com/apify', userData: { label: 'START' } }]);
await crawler.run([{ url: 'https://crawlee.dev/docs/3.0/examples', userData: { label: 'START' } }]);
}, mainOptions);
2 changes: 1 addition & 1 deletion test/e2e/cheerio-page-info/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ const { stats, datasetItems } = await runActor(testActorDirname);
await expect(stats.requestsFinished === 2, 'All requests finished');
await expect(datasetItems.length === 1, 'Number of dataset items');
await expect(
validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'description', 'modifiedDate', 'runCount']),
validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'firstParagraph', 'modifiedDate']),
'Dataset items validation',
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-cheerio-throw-on-ssl-errors",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-input-json5",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-jsdom-default-ts",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-jsdom-react-ts",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-migration",
"version": "0.0",
"buildTag": "latest",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/migration/actor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (workerData !== '#actor') {
maxRequestsPerCrawl: 5,
async requestHandler({ enqueueLinks, request }) {
const { url } = request;
await enqueueLinks({ pseudoUrls: ['https://apify.com[(/[\\w-]+)?]'] });
await enqueueLinks();

await Dataset.pushData({ url });

Expand All @@ -48,6 +48,6 @@ if (workerData !== '#actor') {
// eslint-disable-next-line no-underscore-dangle
Configuration.getGlobalConfig().getStorageClient().__purged = false;

await crawler.run(['https://apify.com']);
await crawler.run(['https://crawlee.dev']);
}, mainOptions);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-playwright-chromium-experimental-containers",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-playwright-default",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/playwright-default/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/playwright-default/actor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ await Actor.main(async () => {
const { url } = request;
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
await enqueueLinks({ regexps: [/^https:\/\/apify\.com(\/[\w-]+)?$/i] });
await enqueueLinks({
globs: ['**/3.0/examples/*'],
});
},
});

await crawler.run(['https://apify.com']);
await crawler.run(['https://crawlee.dev/docs/3.0/examples/']);
}, mainOptions);
4 changes: 2 additions & 2 deletions test/e2e/playwright-default/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ await initialize(testActorDirname);

const { stats, datasetItems } = await runActor(testActorDirname, 16384);

await expect(stats.requestsFinished > 50, 'All requests finished');
await expect(datasetItems.length > 50 && datasetItems.length < 150, 'Number of dataset items');
await expect(stats.requestsFinished > 15, 'All requests finished');
await expect(datasetItems.length > 15 && datasetItems.length < 25, 'Number of dataset items');
await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-playwright-enqueue-links",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/playwright-enqueue-links/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-playwright-firefox-experimental-containers",
"version": "0.0",
"buildTag": "latest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-playwright-initial-cookies",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/playwright-initial-cookies/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-proxy-rotation",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/proxy-rotation/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-puppeteer-default",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/puppeteer-default/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/puppeteer-default/actor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ await Actor.main(async () => {
const { url } = request;
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
await enqueueLinks({ regexps: [/^https:\/\/apify\.com(\/[\w-]+)?$/i] });
await enqueueLinks({
globs: ['**/3.0/examples/*'],
});
},
});

await crawler.run(['https://apify.com']);
await crawler.run(['https://crawlee.dev/docs/3.0/examples/']);
}, mainOptions);
4 changes: 2 additions & 2 deletions test/e2e/puppeteer-default/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ await initialize(testActorDirname);

const { stats, datasetItems } = await runActor(testActorDirname, 16384);

await expect(stats.requestsFinished > 50, 'All requests finished');
await expect(datasetItems.length > 50 && datasetItems.length < 150, 'Number of dataset items');
await expect(stats.requestsFinished > 15, 'All requests finished');
await expect(datasetItems.length > 15 && datasetItems.length < 25, 'Number of dataset items');
await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-puppeteer-enqueue-links",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/puppeteer-enqueue-links/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-puppeteer-ignore-ssl-errors",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/puppeteer-ignore-ssl-errors/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actorSpecification": 1,
"name": "test-puppeteer-initial-cookies",
"version": "0.0",
"buildTag": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/puppeteer-initial-cookies/actor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN rm -r node_modules
COPY --from=builder /node_modules ./node_modules
COPY --from=builder /packages ./packages
COPY --from=builder /package*.json ./
COPY /apify.json ./
COPY /.actor ./.actor
COPY /main.js ./

RUN echo "Installed NPM packages:" \
Expand Down
Loading

0 comments on commit fd74447

Please sign in to comment.