|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { after, before, describe, it } from 'node:test'; |
| 3 | +import nodejs from '../dist/index.js'; |
| 4 | +import { loadFixture } from './test-utils.js'; |
| 5 | + |
| 6 | +describe('Astro preview host', () => { |
| 7 | + it('defaults to localhost', async () => { |
| 8 | + const fixture = await loadFixture({ |
| 9 | + root: './fixtures/preview-headers/', |
| 10 | + output: 'server', |
| 11 | + adapter: nodejs({ mode: 'standalone' }), |
| 12 | + }); |
| 13 | + await fixture.build(); |
| 14 | + const devPreview = await fixture.preview(); |
| 15 | + assert.equal(devPreview.host, 'localhost'); |
| 16 | + await devPreview.stop(); |
| 17 | + }); |
| 18 | + |
| 19 | + it('uses default when set to false', async () => { |
| 20 | + const fixture = await loadFixture({ |
| 21 | + root: './fixtures/preview-headers/', |
| 22 | + output: 'server', |
| 23 | + adapter: nodejs({ mode: 'standalone' }), |
| 24 | + server: { |
| 25 | + host: false, |
| 26 | + }, |
| 27 | + }); |
| 28 | + await fixture.build(); |
| 29 | + const devPreview = await fixture.preview(); |
| 30 | + assert.equal(devPreview.host, 'localhost'); |
| 31 | + await devPreview.stop(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('sets wildcard host if set to true', async () => { |
| 35 | + const fixture = await loadFixture({ |
| 36 | + root: './fixtures/preview-headers/', |
| 37 | + output: 'server', |
| 38 | + adapter: nodejs({ mode: 'standalone' }), |
| 39 | + server: { |
| 40 | + host: true, |
| 41 | + }, |
| 42 | + }); |
| 43 | + await fixture.build(); |
| 44 | + const devPreview = await fixture.preview(); |
| 45 | + assert.equal(devPreview.host, '0.0.0.0'); |
| 46 | + await devPreview.stop(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('allows setting specific host', async () => { |
| 50 | + const fixture = await loadFixture({ |
| 51 | + root: './fixtures/preview-headers/', |
| 52 | + output: 'server', |
| 53 | + adapter: nodejs({ mode: 'standalone' }), |
| 54 | + server: { |
| 55 | + host: '127.0.0.1', |
| 56 | + }, |
| 57 | + }); |
| 58 | + await fixture.build(); |
| 59 | + const devPreview = await fixture.preview(); |
| 60 | + assert.equal(devPreview.host, '127.0.0.1'); |
| 61 | + await devPreview.stop(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments