0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/node/test/url-protocol.test.js
Erika f14e48098a
nit: use node: prefix everywhere (#7692)
* nit: use `node:` prefix everywhere

* nit: fs/promises too

* test: workaround issue in node builtin detection
2023-07-18 02:17:59 +02:00

73 lines
1.9 KiB
JavaScript

import { expect } from 'chai';
import { TLSSocket } from 'node:tls';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, loadFixture } from './test-utils.js';
describe('URL protocol', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/url-protocol/',
output: 'server',
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
});
it('return http when non-secure', async () => {
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
url: '/',
});
handler(req, res);
req.send();
const html = await text();
expect(html).to.include('http:');
});
it('return https when secure', async () => {
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
socket: new TLSSocket(),
url: '/',
});
handler(req, res);
req.send();
const html = await text();
expect(html).to.include('https:');
});
it('return http when the X-Forwarded-Proto header is set to http', async () => {
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
headers: { 'X-Forwarded-Proto': 'http' },
url: '/',
});
handler(req, res);
req.send();
const html = await text();
expect(html).to.include('http:');
});
it('return https when the X-Forwarded-Proto header is set to https', async () => {
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
headers: { 'X-Forwarded-Proto': 'https' },
url: '/',
});
handler(req, res);
req.send();
const html = await text();
expect(html).to.include('https:');
});
});