docsify/test/config/server.js
John Hildenbiddle f5412dc7b0
chore: Update lint configuration (ESLint 9, Prettier 3) (#2438)
* Update linting configuration (eslint, prettier)

* Fix lint issues following eslint prettier update

* Change ESLint config to allow boolean coercion

* Switch to default import name per docs

* Fix suppression of error details

* Update JSDoc comments

* Update waiForFunctin to provide error details

---------

Co-authored-by: Koy Zhuang <koy@ko8e24.top>
2024-05-28 15:27:29 -05:00

33 lines
841 B
JavaScript

import * as process from 'node:process';
import { create } from 'browser-sync';
import { testConfig } from '../../server.configs.js';
const bsServer = create();
export async function startServer() {
// Wait for server to start
return new Promise(resolve => {
const settings = testConfig;
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();
}