Skip to content

Commit

Permalink
🌿 add cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly authored and lambdalisue committed Jun 1, 2024
1 parent 1f291e1 commit 67b35a6
Show file tree
Hide file tree
Showing 5 changed files with 904 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"check": "deno check **/*.ts",
"test": "LANG=C deno test -A --parallel --shuffle --doc",
"test:coverage": "deno task test --coverage=.coverage",
"coverage": "deno coverage .coverage --exclude=cli.ts --exclude=worker.ts --exclude=testdata/",
"coverage": "deno coverage .coverage",
"update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli **/*.ts",
"update:commit": "deno task -q update --commit --pre-commit=fmt,lint"
},
Expand Down
16 changes: 8 additions & 8 deletions denops/@denops-private/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { parseArgs } from "jsr:@std/cli/parse-args";
// https://github.com/denoland/deno/issues/23792
Deno.env.set("MSGPACKR_NATIVE_ACCELERATION_DISABLED", "true");

const script = import.meta.resolve("./worker.ts");
const WORKER_SCRIPT = import.meta.resolve("./worker.ts");

async function handleConn(
conn: Deno.Conn,
conn: Deno.TcpConn,
{ quiet }: { quiet?: boolean },
): Promise<void> {
const remoteAddr = conn.remoteAddr as Deno.NetAddr;
const remoteAddr = conn.remoteAddr;
const name = `${remoteAddr.hostname}:${remoteAddr.port}`;
if (!quiet) {
console.info(`${name} is connected`);
}

const worker = new Worker(script, {
const worker = new Worker(WORKER_SCRIPT, {
name,
type: "module",
});
Expand All @@ -38,8 +38,8 @@ async function handleConn(
}
}

async function main(): Promise<void> {
const { hostname, port, quiet, identity } = parseArgs(Deno.args, {
export async function main(args: string[]): Promise<void> {
const { hostname, port, quiet, identity } = parseArgs(args, {
string: ["hostname", "port"],
boolean: ["quiet", "identity"],
});
Expand All @@ -48,7 +48,7 @@ async function main(): Promise<void> {
hostname: hostname ?? "127.0.0.1",
port: Number(port ?? "32123"),
});
const localAddr = listener.addr as Deno.NetAddr;
const localAddr = listener.addr;

if (identity) {
// WARNING:
Expand All @@ -72,5 +72,5 @@ async function main(): Promise<void> {
}

if (import.meta.main) {
await main();
await main(Deno.args);
}
Loading

0 comments on commit 67b35a6

Please sign in to comment.