summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/_test-utils.js
blob: 4fe97184c25116ccc27587b6270110d21136a0ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { fileURLToPath } from 'node:url';
import { execa } from 'execa';
/**
 * @typedef {{ stop: Promise<void>, port: number }} WranglerCLI
 */

const astroPath = fileURLToPath(new URL('../node_modules/astro/astro.js', import.meta.url));
/** Returns a process running the Astro CLI. */
export function astroCli(cwd, /** @type {string[]} */ ...args) {
	const spawned = execa(astroPath, [...args], {
		env: { ASTRO_TELEMETRY_DISABLED: true },
		cwd: cwd,
	});

	spawned.stdout.setEncoding('utf8');

	return spawned;
}

const wranglerPath = fileURLToPath(
	new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
);
/** Returns a process running the Astro CLI. */
export function wranglerCli(cwd) {
	const spawned = execa(
		wranglerPath,
		[
			'pages',
			'dev',
			'dist',
			'--port',
			'8788',
			'--compatibility-date',
			new Date().toISOString().slice(0, 10),
			'--log-level',
			'info',
		],
		{
			env: { CI: 1, CF_PAGES: 1 },
			cwd: cwd,
		}
	);

	spawned.stdout.setEncoding('utf8');
	spawned.stderr.setEncoding('utf8');

	return spawned;
}