astro/packages/astro/test/config-port.test.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

import { fileURLToPath } from 'url';
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { runDevServer } from './helpers.js';
import { loadConfig } from '#astro/config';
const ConfigPort = suite('Config path');
2021-05-27 20:06:54 +00:00
const MAX_TEST_TIME = 10000; // max time this test suite may take
const root = new URL('./fixtures/config-port/', import.meta.url);
2021-05-27 20:06:54 +00:00
const timers = {};
ConfigPort.before.each(({ __test__ }) => {
timers[__test__] = setTimeout(() => {
throw new Error(`Test "${__test__}" did not finish within allowed time`);
}, MAX_TEST_TIME);
});
ConfigPort('can be specified in the astro config', async (context) => {
const astroConfig = await loadConfig(fileURLToPath(root));
assert.equal(astroConfig.devOptions.port, 3001);
});
ConfigPort('can be specified via --port flag', async (context) => {
const args = ['--port', '3002'];
2021-05-27 20:06:54 +00:00
const proc = runDevServer(root, args);
2021-05-27 20:06:54 +00:00
proc.stdout.setEncoding('utf8');
for await (const chunk of proc.stdout) {
2021-05-03 18:26:10 +00:00
if (/Local:/.test(chunk)) {
assert.ok(/:3002/.test(chunk), 'Using the right port');
break;
}
}
2021-05-27 20:06:54 +00:00
proc.kill();
});
ConfigPort.after.each(({ __test__ }) => {
clearTimeout(timers[__test__]);
});
ConfigPort.run();