-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable migration testing (#1583)
- Loading branch information
Showing
7 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea | ||
.DS_Store | ||
node_modules | ||
package-lock.json | ||
apify_storage | ||
crawlee_storage | ||
storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM apify/actor-node:16-beta | ||
|
||
COPY packages ./packages | ||
COPY package*.json ./ | ||
|
||
RUN npm --quiet set progress=false \ | ||
&& npm install --only=prod --no-optional \ | ||
&& npm update \ | ||
&& echo "Installed NPM packages:" \ | ||
&& (npm list --only=prod --no-optional --all || true) \ | ||
&& echo "Node.js version:" \ | ||
&& node --version \ | ||
&& echo "NPM version:" \ | ||
&& npm --version | ||
|
||
COPY . ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "test-migration", | ||
"version": "0.0", | ||
"buildTag": "latest", | ||
"env": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Actor } from 'apify'; | ||
import { CheerioCrawler, Configuration, Dataset } from '@crawlee/cheerio'; | ||
import { ApifyStorageLocal } from '@apify/storage-local'; | ||
|
||
process.env.CRAWLEE_PURGE_ON_START = '0'; | ||
|
||
const mainOptions = { | ||
exit: Actor.isAtHome(), | ||
storage: process.env.STORAGE_IMPLEMENTATION === 'LOCAL' ? new ApifyStorageLocal() : undefined, | ||
}; | ||
|
||
const run = async () => { | ||
await Actor.main(async () => { | ||
const crawler = new CheerioCrawler({ | ||
maxConcurrency: 1, | ||
maxRequestsPerCrawl: 5, | ||
async requestHandler({ enqueueLinks, request }) { | ||
const { url } = request; | ||
await enqueueLinks({ pseudoUrls: ['https://apify.com[(/[\\w-]+)?]'] }); | ||
|
||
await Dataset.pushData({ url }); | ||
|
||
process.emit('SIGINT'); | ||
}, | ||
}); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
Configuration.getGlobalConfig().getStorageClient().__purged = false; | ||
|
||
await crawler.run(['https://apify.com']); | ||
}, mainOptions); | ||
}; | ||
|
||
await run(); | ||
await run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "test-migration", | ||
"version": "0.0.1", | ||
"description": "Migration Test", | ||
"dependencies": { | ||
"apify": "next", | ||
"@apify/storage-local": "^2.1.0", | ||
"@crawlee/basic": "file:./packages/basic-crawler", | ||
"@crawlee/browser-pool": "file:./packages/browser-pool", | ||
"@crawlee/http": "file:./packages/http-crawler", | ||
"@crawlee/cheerio": "file:./packages/cheerio-crawler", | ||
"@crawlee/core": "file:./packages/core", | ||
"@crawlee/memory-storage": "file:./packages/memory-storage", | ||
"@crawlee/types": "file:./packages/types", | ||
"@crawlee/utils": "file:./packages/utils" | ||
}, | ||
"overrides": { | ||
"apify": { | ||
"@crawlee/core": "file:./packages/core", | ||
"@crawlee/utils": "file:./packages/utils" | ||
} | ||
}, | ||
"scripts": { | ||
"start": "node main.js" | ||
}, | ||
"type": "module", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { initialize, getActorTestDir, runActor, expect, validateDataset } from '../tools.mjs'; | ||
|
||
const testActorDirname = getActorTestDir(import.meta.url); | ||
await initialize(testActorDirname); | ||
|
||
const { datasetItems } = await runActor(testActorDirname); | ||
|
||
await expect(datasetItems.length === 2, 'Number of dataset items'); | ||
await expect(validateDataset(datasetItems, ['url']), 'Dataset items validation'); | ||
await expect(datasetItems[0].url !== datasetItems[1].url, 'Dataset items unique'); |