docsify/test/config/server.js
John Hildenbiddle 1c5a7013f1
Chore: Clean up server implementation and update test docs (#2316)
- Replace live-server with existing Browsersync dependency as web server
- Remove duplicate `index.html` file
- Add `build:html` script to generate `/docs/preview.html`
2023-12-11 15:00:33 -06:00

33 lines
832 B
JavaScript

import * as process from 'node:process';
import { create } from 'browser-sync';
import config from '../../server.config.js';
const bsServer = create();
export async function startServer() {
// Wait for server to start
return new Promise(resolve => {
const settings = config.test;
console.log('\n');
bsServer.init(settings, () => {
// Exit process if specified port is not available. BrowserSync
// auto-selects a new port if the specified port is unavailable. This is
// problematic for testing and CI/CD.
if (bsServer.getOption('port') !== settings.port) {
console.log(
`\nPort ${settings.port} not available. Exiting process.\n`
);
process.exit(0);
}
resolve(bsServer);
});
});
}
export function stopServer() {
bsServer.exit();
}