Skip to content

Commit c33f40a

Browse files
committed
pre-format
1 parent a4a42ba commit c33f40a

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

JetStreamDriver.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ if (typeof(URLSearchParams) !== "undefined") {
5959
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
6060
}
6161

62-
63-
6462
// Used for the promise representing the current benchmark run.
6563
this.currentResolve = null;
6664
this.currentReject = null;

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
},
1616
"license": "SEE LICENSE IN LICENSE",
1717
"scripts": {
18-
"dev": "http-server ./ -c-1 --cors",
19-
"server": "http-server ./ --cors",
18+
"server": "node tests/server.mjs",
2019
"lint:check": "eslint **/*.{js,mjs,jsx,ts,tsx}",
2120
"pretty:check": "prettier --check ./",
2221
"format:check": "npm run pretty:check && npm run lint:check",
@@ -34,6 +33,7 @@
3433
"eslint": "^8.38.0",
3534
"http-server": "^14.1.1",
3635
"prettier": "^2.8.3",
37-
"selenium-webdriver": "^4.8.0"
36+
"selenium-webdriver": "^4.8.0",
37+
"es-main":"^1.3.0"
3838
}
3939
}

tests/server.mjs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import * as fs from "fs";
33
import * as http from "http";
44
import * as path from "path";
5+
import commandLineArgs from "command-line-args";
6+
import esMain from 'es-main';
7+
58
const MIME_TYPES = {
69
default: "application/octet-stream",
710
html: "text/html; charset=UTF-8",
@@ -23,8 +26,8 @@ export default function serve(port) {
2326
throw new Error("Port is required");
2427

2528
const prepareFile = async (url) => {
26-
const paths = [STATIC_PATH, url];
27-
if (url.endsWith("/"))
29+
const paths = [STATIC_PATH, url.pathname];
30+
if (url.pathname.endsWith("/"))
2831
paths.push("index.html");
2932
const filePath = path.join(...paths);
3033
const pathTraversal = !filePath.startsWith(STATIC_PATH);
@@ -38,14 +41,32 @@ export default function serve(port) {
3841

3942
const server = http
4043
.createServer(async (req, res) => {
41-
const file = await prepareFile(req.url);
44+
const url = new URL(`http://localhost${req.url}`);
45+
const file = await prepareFile(url);
4246
const statusCode = file.found ? 200 : 404;
4347
const mimeType = MIME_TYPES[file.ext] || MIME_TYPES.default;
44-
res.writeHead(statusCode, { "Content-Type": mimeType });
48+
res.writeHead(statusCode, {
49+
"Content-Type": mimeType,
50+
"Cross-Origin-Embedder-Policy": "require-corp",
51+
"Cross-Origin-Opener-Policy": "same-origin",
52+
});
4553
file.stream.pipe(res);
4654
})
4755
.listen(port);
4856

4957
console.log(`Server running at http://127.0.0.1:${port}/`);
5058
return server;
5159
}
60+
61+
62+
function main() {
63+
const optionDefinitions = [
64+
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
65+
];
66+
const options = commandLineArgs(optionDefinitions);
67+
serve(options.port);
68+
}
69+
70+
if (esMain(import.meta)) {
71+
main();
72+
}

0 commit comments

Comments
 (0)