summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/astro-env.test.js
blob: af1a366e0c9afea102a9c83ea75615d59c2dbdcf (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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('astro:env', () => {
	let wrangler;

	before(async () => {
		process.env.API_URL = 'https://google.de';
		process.env.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(() => {
		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);
	});

	it('action secret', async () => {
		const res = await fetch('http://127.0.0.1:8788/test');
		const html = await res.text();
		const $ = cheerio.load(html);
		assert.equal($('#secret').text().includes('123456789'), true);
	});
});