diff options
author | 2022-06-06 12:02:13 -0400 | |
---|---|---|
committer | 2022-06-06 12:02:13 -0400 | |
commit | c22a07db134a9d0741a05123fb506595aabf145b (patch) | |
tree | 1002ab32a8b124deb434de2a4cb38248e4ea1eca /packages/integrations/deno/test/helpers.js | |
parent | 9029c43549b7199fb816ccd0bac9171ee4e429c0 (diff) | |
download | astro-c22a07db134a9d0741a05123fb506595aabf145b.tar.gz astro-c22a07db134a9d0741a05123fb506595aabf145b.tar.zst astro-c22a07db134a9d0741a05123fb506595aabf145b.zip |
Fix use of dynamic imports / Astro.glob with Deno Deploy (#3532)
* Fix use of dynamic imports / Astro.glob with Deno Deploy
* Adds a changeset
* Mark the markdown package as external
Diffstat (limited to 'packages/integrations/deno/test/helpers.js')
-rw-r--r-- | packages/integrations/deno/test/helpers.js | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/packages/integrations/deno/test/helpers.js b/packages/integrations/deno/test/helpers.js index 3a3fb0c17..74c7f9fca 100644 --- a/packages/integrations/deno/test/helpers.js +++ b/packages/integrations/deno/test/helpers.js @@ -1,4 +1,4 @@ -import { fromFileUrl } from './deps.js'; +import { readableStreamFromReader, fromFileUrl } from './deps.js'; const dir = new URL('./', import.meta.url); export async function runBuild(fixturePath) { @@ -10,14 +10,52 @@ export async function runBuild(fixturePath) { return async () => await proc.close(); } -export async function runBuildAndStartApp(fixturePath, cb) { - const url = new URL(fixturePath, dir); - const close = await runBuild(fixturePath); - const mod = await import(new URL('./dist/server/entry.mjs', url)); +export async function startModFromImport(baseUrl) { + const entryUrl = new URL('./dist/server/entry.mjs', baseUrl); + const mod = await import(entryUrl); + if (!mod.running()) { mod.start(); } + + return () => mod.stop(); +} + +export async function startModFromSubprocess(baseUrl) { + const entryUrl = new URL('./dist/server/entry.mjs', baseUrl); + let proc = Deno.run({ + cmd: ['deno', 'run', '--allow-env', '--allow-net', fromFileUrl(entryUrl)], + cwd: fromFileUrl(baseUrl), + stderr: 'piped' + }); + const stderr = readableStreamFromReader(proc.stderr); + const dec = new TextDecoder(); + for await(let bytes of stderr) { + let msg = dec.decode(bytes); + if(msg.includes(`Server running`)) { + break; + } + } + return () => proc.close(); +} + +export async function runBuildAndStartApp(fixturePath, cb) { + const url = new URL(fixturePath, dir); + const close = await runBuild(fixturePath); + const stop = await startModFromImport(url); + + await cb(); + await stop(); + await close(); +} + + +export async function runBuildAndStartAppFromSubprocess(fixturePath, cb) { + const url = new URL(fixturePath, dir); + const close = await runBuild(fixturePath); + const stop = await startModFromSubprocess(url); + await cb(); - await mod.stop(); + await stop(); await close(); } |