Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions tests/run-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.

import serve from "./server.mjs";
import { serve, optionDefinitions as serverOptionDefinitions } from "./server.mjs";
import { Builder, Capabilities, logging } from "selenium-webdriver";
import { Options as ChromeOptions } from "selenium-webdriver/chrome.js";
import { Options as FirefoxOptions } from "selenium-webdriver/firefox.js";
Expand Down Expand Up @@ -80,8 +80,8 @@ function sleep(ms) {
}

const optionDefinitions = [
...serverOptionDefinitions,
{ name: "browser", type: String, description: "Set the browser to test, choices are [safari, firefox, chrome, edge]. By default the $BROWSER env variable is used." },
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
{ name: "help", alias: "h", description: "Print this help text." },
{ name: "suite", type: String, defaultOption: true, typeLabel: `{underline choices}: ${VALID_TAGS.join(", ")}`, description: "Run a specific suite by name." }
];
Expand Down Expand Up @@ -142,7 +142,7 @@ process.once("uncaughtException", (err) => {
});

const PORT = options.port;
const server = await serve(PORT);
const server = await serve(options);

async function runTests() {
let success = true;
Expand Down
14 changes: 9 additions & 5 deletions tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ import LocalWebServer from "local-web-server";

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

export default async function serve(port) {
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." },
];

export async function serve({ port, verbose }) {
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",
});
console.log(`Server started on http://localhost:${port}`);
process.on("exit", () => ws.server.close());
Expand All @@ -48,11 +55,8 @@ export default async function serve(port) {
}

function main() {
const optionDefinitions = [
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
];
const options = commandLineArgs(optionDefinitions);
serve(options.port);
serve(options);
}

if (esMain(import.meta))
Expand Down
Loading