diff options
author | 2024-06-10 17:48:38 +0200 | |
---|---|---|
committer | 2024-06-10 17:48:38 +0200 | |
commit | 976a24c66d8dc329dc90624a7ad52eff315b2bbf (patch) | |
tree | 954e16476f395a709ddaab3eb20b146ea5fcad71 /packages/integrations/cloudflare/test/astro-env.test.js | |
parent | 41f1321c088592a429b785f935fd5c6c49c405a0 (diff) | |
download | astro-976a24c66d8dc329dc90624a7ad52eff315b2bbf.tar.gz astro-976a24c66d8dc329dc90624a7ad52eff315b2bbf.tar.zst astro-976a24c66d8dc329dc90624a7ad52eff315b2bbf.zip |
feat(cloudflare): support astro:env (#258)
Co-authored-by: Alexander Niebuhr <alexander@nbhr.io>
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Diffstat (limited to 'packages/integrations/cloudflare/test/astro-env.test.js')
-rw-r--r-- | packages/integrations/cloudflare/test/astro-env.test.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/astro-env.test.js b/packages/integrations/cloudflare/test/astro-env.test.js new file mode 100644 index 000000000..786583be8 --- /dev/null +++ b/packages/integrations/cloudflare/test/astro-env.test.js @@ -0,0 +1,65 @@ +import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; +import { astroCli, wranglerCli } from './_test-utils.js'; + +const root = new URL('./fixtures/astro-env/', import.meta.url); + +describe('AstroEnv', () => { + let wrangler; + + before(async () => { + process.env.PUBLIC_API_URL = 'https://google.de'; + process.env.PUBLIC_PORT = '4322'; + await astroCli(fileURLToPath(root), 'build'); + + wrangler = wranglerCli(fileURLToPath(root)); + await new Promise((resolve) => { + wrangler.stdout.on('data', (data) => { + // console.log('[stdout]', data.toString()); + if (data.toString().includes('http://127.0.0.1:8788')) resolve(); + }); + wrangler.stderr.on('data', (data) => { + // console.log('[stderr]', data.toString()); + }); + }); + }); + + after((done) => { + wrangler.kill(); + }); + + it('runtime', async () => { + const res = await fetch('http://127.0.0.1:8788/'); + const html = await res.text(); + const $ = cheerio.load(html); + assert.equal( + $('#runtime').text().includes('https://google.de') && + $('#runtime').text().includes('4322') && + $('#runtime').text().includes('123456789'), + true + ); + }); + + it('client', async () => { + const res = await fetch('http://127.0.0.1:8788/'); + const html = await res.text(); + const $ = cheerio.load(html); + assert.equal($('#client').text().includes('https://google.de'), true); + }); + + it('server', async () => { + const res = await fetch('http://127.0.0.1:8788/'); + const html = await res.text(); + const $ = cheerio.load(html); + assert.equal($('#server').text().includes('4322'), true); + }); + + it('secret', async () => { + const res = await fetch('http://127.0.0.1:8788/'); + const html = await res.text(); + const $ = cheerio.load(html); + assert.equal($('#secret').text().includes('123456789'), true); + }); +}); |