Skip to content

Commit fe485c0

Browse files
committed
Add verbose option to the node server.
This is somewhat handy when checking if network requests happen during the benchmark run itself. I clear the screen then click start and if any resources are fetched logging will be printed to the terminal session. It doesn't catch network requests but those are more obvious during development. For posterity, after a bit of debugging I realized that you have to pass options as `npm run server -- --verbose` rather than `npm run server --verbose`
1 parent a3f5c45 commit fe485c0

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

tests/server.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ import LocalWebServer from "local-web-server";
2929

3030
const ROOT_DIR = path.join(process.cwd(), "./");
3131

32-
export default async function serve(port) {
32+
const optionDefinitions = [
33+
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
34+
{ name: "verbose", type: Boolean, defaultValue: false, description: "Log all requests set to the server." },
35+
];
36+
37+
export default async function serve({ port, verbose }) {
3338
if (!port)
3439
throw new Error("Port is required");
40+
3541
const ws = await LocalWebServer.create({
3642
port: port,
3743
directory: ROOT_DIR,
3844
corsOpenerPolicy: "same-origin",
3945
corsEmbedderPolicy: "require-corp",
46+
logFormat: verbose ? "dev" : "none",
4047
});
4148
console.log(`Server started on http://localhost:${port}`);
4249
process.on("exit", () => ws.server.close());
@@ -48,11 +55,8 @@ export default async function serve(port) {
4855
}
4956

5057
function main() {
51-
const optionDefinitions = [
52-
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
53-
];
5458
const options = commandLineArgs(optionDefinitions);
55-
serve(options.port);
59+
serve(options);
5660
}
5761

5862
if (esMain(import.meta))

0 commit comments

Comments
 (0)