MCPcopy
hub / github.com/apify/crawlee / run

Function run

test/e2e/run.mjs:33–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31let failure = false;
32
33async function run() {
34 if (!['LOCAL', 'MEMORY', 'PLATFORM'].includes(process.env.STORAGE_IMPLEMENTATION)) {
35 throw new Error(`Unknown storage provided: '${process.env.STORAGE_IMPLEMENTATION}'`);
36 }
37
38 console.log(`Running E2E tests with storage implementation '${process.env.STORAGE_IMPLEMENTATION}'`);
39
40 const paths = await readdir(basePath, { withFileTypes: true });
41 const dirs = paths.filter((dirent) => dirent.isDirectory());
42
43 for (const dir of dirs) {
44 if (process.argv.length === 3 && dir.name !== process.argv[2]) {
45 continue;
46 }
47
48 const now = Date.now();
49 console.log(`${colors.yellow(`[${dir.name}] `)}${colors.grey('Test starting...')}`);
50 const worker = new Worker(fileURLToPath(import.meta.url), {
51 workerData: dir.name,
52 stdout: true,
53 stderr: true,
54 });
55 let seenFirst = false;
56 const prefix = colors.yellow(`[${dir.name}] `);
57 // Surface only lines that start with a structured `[…]` marker (init,
58 // assertion, build, run, kv, test skipped, etc.). Everything else
59 // (crawler INFO logs, per-URL request handler logs, npm warnings, …)
60 // is noise on a green run; buffer it and re-emit from the exit
61 // handler iff the test failed.
62 const deferredOnSuccess = [];
63
64 // Line-buffered streaming so prefixed lines stay intact across chunk boundaries.
65 const streamLines = (stream, sink) => {
66 let buffer = '';
67 stream.on('data', (chunk) => {
68 buffer += chunk.toString();
69 const lines = buffer.split('\n');
70 buffer = lines.pop();
71 for (const line of lines) {
72 if (line === '') continue;
73
74 if (!line.startsWith('[')) {
75 if (!seenFirst) {
76 console.log(
77 `${colors.red('[fatal]')} test ${colors.yellow(
78 `[${dir.name}]`,
79 )} did not call "initialize(import.meta.url)"!`,
80 );
81 worker.terminate();
82 return;
83 }
84 deferredOnSuccess.push(line);
85 continue;
86 }
87
88 seenFirst = true;
89 sink(`${prefix}${line}`);
90 }

Callers 1

run.mjsFile · 0.85

Calls 3

streamLinesFunction · 0.85
exitHandlerFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected