astro/packages/astro/test/config.test.js
Fred K. Schott 6386c14d00
Astro Integration System (#2820)
* update examples

* add initial integrations

* update tests

* update astro

* update ci

* get final tests working

* update injectelement todo

* update ben code review

* respond to final code review feedback
2022-03-18 15:35:45 -07:00

79 lines
2.6 KiB
JavaScript

import { expect } from 'chai';
import { cli, loadFixture, cliServerLogSetup } from './test-utils.js';
import { fileURLToPath } from 'url';
import { isIPv4 } from 'net';
describe('config', () => {
let hostnameFixture;
let hostFixture;
let portFixture;
before(async () => {
[hostnameFixture, hostFixture, portFixture] = await Promise.all([
loadFixture({
projectRoot: './fixtures/config-host/',
devOptions: {
hostname: '0.0.0.0',
},
}),
loadFixture({
projectRoot: './fixtures/config-host/',
devOptions: {
host: true,
},
}),
loadFixture({
projectRoot: './fixtures/config-host/',
devOptions: {
port: 5006,
},
}),
]);
});
// TODO: remove test once --hostname is baselined
describe('hostname', () => {
it('can be specified in astro.config.mjs', async () => {
expect(hostnameFixture.config.devOptions.hostname).to.equal('0.0.0.0');
});
it('can be specified via --hostname flag', async () => {
const projectRootURL = new URL('./fixtures/astro-basic/', import.meta.url);
const { network } = await cliServerLogSetup(['--project-root', fileURLToPath(projectRootURL), '--hostname', '0.0.0.0']);
const networkURL = new URL(network);
expect(isIPv4(networkURL.hostname)).to.be.equal(true, `Expected network URL to respect --hostname flag`);
});
});
describe('host', () => {
it('can be specified in astro.config.mjs', async () => {
expect(hostFixture.config.devOptions.host).to.equal(true);
});
it('can be specified via --host flag', async () => {
const projectRootURL = new URL('./fixtures/astro-basic/', import.meta.url);
const { network } = await cliServerLogSetup(['--project-root', fileURLToPath(projectRootURL), '--host']);
const networkURL = new URL(network);
expect(isIPv4(networkURL.hostname)).to.be.equal(true, `Expected network URL to respect --hostname flag`);
});
});
describe('path', () => {
it('can be passed via --config', async () => {
const projectRootURL = new URL('./fixtures/astro-basic/', import.meta.url);
const configFileURL = new URL('./fixtures/config-path/config/my-config.mjs', import.meta.url);
const { network } = await cliServerLogSetup(['--project-root', fileURLToPath(projectRootURL), '--config', configFileURL.pathname]);
const networkURL = new URL(network);
expect(isIPv4(networkURL.hostname)).to.be.equal(true, `Expected network URL to respect --hostname flag`);
});
});
describe('port', () => {
it('can be specified in astro.config.mjs', async () => {
expect(portFixture.config.devOptions.port).to.deep.equal(5006);
});
});
});