diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/config-path.test.js | 24 | ||||
-rw-r--r-- | test/config-port.test.js | 29 | ||||
-rw-r--r-- | test/fixtures/config-path/config/my-config.mjs | 5 | ||||
-rw-r--r-- | test/fixtures/config-port/astro.config.mjs | 6 | ||||
-rw-r--r-- | test/helpers.js | 9 |
5 files changed, 73 insertions, 0 deletions
diff --git a/test/config-path.test.js b/test/config-path.test.js new file mode 100644 index 000000000..a13e099b3 --- /dev/null +++ b/test/config-path.test.js @@ -0,0 +1,24 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { runDevServer } from './helpers.js'; + +const ConfigPath = suite('Config path'); + +const root = new URL('./fixtures/config-path/', import.meta.url); +ConfigPath('can be passed via --config', async (context) => { + const configPath = new URL('./config/my-config.mjs', root).pathname; + const args = ['--config', configPath]; + const process = runDevServer(root, args); + + process.stdout.setEncoding('utf8'); + for await (const chunk of process.stdout) { + if(/Server running at/.test(chunk)) { + break; + } + } + + process.kill(); + assert.ok(true, 'Server started'); +}); + +ConfigPath.run(); diff --git a/test/config-port.test.js b/test/config-port.test.js new file mode 100644 index 000000000..9b5f7b14c --- /dev/null +++ b/test/config-port.test.js @@ -0,0 +1,29 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { runDevServer } from './helpers.js'; +import { loadConfig } from '../lib/config.js'; + +const ConfigPort = suite('Config path'); + +const root = new URL('./fixtures/config-port/', import.meta.url); +ConfigPort('can be specified in the astro config', async (context) => { + const astroConfig = await loadConfig(root.pathname); + assert.equal(astroConfig.devOptions.port, 3001); +}); + +ConfigPort('can be specified via --port flag', async (context) => { + const args = ['--port', '3002']; + const process = runDevServer(root, args); + + process.stdout.setEncoding('utf8'); + for await (const chunk of process.stdout) { + if(/Server running at/.test(chunk)) { + assert.ok(/:3002/.test(chunk), 'Using the right port'); + break; + } + } + + process.kill(); +}); + +ConfigPort.run(); diff --git a/test/fixtures/config-path/config/my-config.mjs b/test/fixtures/config-path/config/my-config.mjs new file mode 100644 index 000000000..f50751cfd --- /dev/null +++ b/test/fixtures/config-path/config/my-config.mjs @@ -0,0 +1,5 @@ +export default { + extensions: { + '.jsx': 'preact', + }, +}; diff --git a/test/fixtures/config-port/astro.config.mjs b/test/fixtures/config-port/astro.config.mjs new file mode 100644 index 000000000..61858cdae --- /dev/null +++ b/test/fixtures/config-port/astro.config.mjs @@ -0,0 +1,6 @@ + +export default { + devOptions: { + port: 3001 + } +}
\ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index 8ca42ea11..eb7cabb0b 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -4,6 +4,8 @@ import { readFile } from 'fs/promises'; import { createRuntime } from '../lib/runtime.js'; import { loadConfig } from '../lib/config.js'; import * as assert from 'uvu/assert'; +import execa from 'execa'; + /** setup fixtures for tests */ export function setup(Suite, fixturePath) { let runtime, setupError; @@ -62,3 +64,10 @@ export function setupBuild(Suite, fixturePath) { assert.equal(setupError, undefined); }); } + +const cliURL = new URL('../astro.mjs', import.meta.url); +export function runDevServer(root, additionalArgs = []) { + const args = [cliURL.pathname, 'dev', '--project-root', root.pathname].concat(additionalArgs); + const proc = execa('node', args); + return proc; +}
\ No newline at end of file |