diff options
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); + }); +}); |