summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/test-utils.js
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-07-27 16:15:19 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-27 16:15:19 -0400
commita198028b04234d0b8dcb0b6bcb47c5831d7a15f9 (patch)
tree6bc03ee0f68c823880cca458206d3e938df832b8 /packages/integrations/cloudflare/test/test-utils.js
parent13b4f8ad887d0d4e8efbf9f74185432f9cdf264e (diff)
downloadastro-a198028b04234d0b8dcb0b6bcb47c5831d7a15f9.tar.gz
astro-a198028b04234d0b8dcb0b6bcb47c5831d7a15f9.tar.zst
astro-a198028b04234d0b8dcb0b6bcb47c5831d7a15f9.zip
Fixes cloudflare throwing over process (#4072)
* Fixes cloudflare throwing over process * Up the timeout for slower CI servers * Fix linting * Up the timeout a bit
Diffstat (limited to 'packages/integrations/cloudflare/test/test-utils.js')
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js
index 6bb3e7c25..41cc8a2c9 100644
--- a/packages/integrations/cloudflare/test/test-utils.js
+++ b/packages/integrations/cloudflare/test/test-utils.js
@@ -1,4 +1,6 @@
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
+import { spawn } from 'child_process';
+import { fileURLToPath } from 'url';
export { fixLineEndings } from '../../../astro/test/test-utils.js';
@@ -8,3 +10,53 @@ export function loadFixture(config) {
}
return baseLoadFixture(config);
}
+
+const wranglerPath = fileURLToPath(new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url));
+
+export function runCLI(basePath, { silent }) {
+ const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
+ const p = spawn('node', [wranglerPath, 'dev', '-l', script]);
+
+ p.stderr.setEncoding('utf-8');
+ p.stdout.setEncoding('utf-8');
+
+ const timeout = 10000;
+
+ const ready = new Promise(async (resolve, reject) => {
+ const failed = setTimeout(() => reject(new Error(`Timed out starting the wrangler CLI`)), timeout);
+
+ (async function () {
+ for(const msg of p.stderr) {
+ if(!silent) {
+ // eslint-disable-next-line
+ console.error(msg);
+ }
+ }
+ })();
+
+ for await(const msg of p.stdout) {
+ if(!silent) {
+ // eslint-disable-next-line
+ console.log(msg);
+ }
+ if(msg.includes(`Listening on`)) {
+ break;
+ }
+ }
+
+ clearTimeout(failed);
+ resolve();
+ });
+
+ return {
+ ready,
+ stop() {
+ p.kill();
+ return new Promise(resolve => {
+ p.addListener('exit', () => {
+ resolve();
+ });
+ })
+ }
+ }
+}