Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,39 @@ import LocalWebServer from "local-web-server";
const ROOT_DIR = path.join(process.cwd(), "./");

export const optionDefinitions = [
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
{ name: "verbose", type: Boolean, defaultValue: false, description: "Log all requests set to the server." },
{
name: "port",
type: Number,
defaultValue: 8010,
description: "Set the test-server port, The default value is 8010.",
},
{
name: "quiet",
alias: "q",
type: Boolean,
defaultValue: false,
description: "Silence the server output.",
},
];

export async function serve({ port, verbose }) {
if (!port)
throw new Error("Port is required");
export async function serve(options) {
let { port, quiet } = options;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Why make this change? we don't use options anywhere.


if (!port) throw new Error("Port is required");

const ws = await LocalWebServer.create({
port: port,
directory: ROOT_DIR,
corsOpenerPolicy: "same-origin",
corsEmbedderPolicy: "require-corp",
logFormat: verbose ? "dev" : "none",
logFormat: quiet ? undefined : "dev",
});
console.log(`Server started on http://localhost:${port}`);
process.on("exit", () => ws.server.close());
return {
close() {
ws.server.close();
}
},
};
}

Expand All @@ -59,5 +71,6 @@ function main() {
serve(options);
}

if (esMain(import.meta))
if (esMain(import.meta)) {
main();
}
Loading