Skip to content

Commit

Permalink
🌿 add module that resolves testdata path or URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Sep 13, 2024
1 parent f32f028 commit ee31acf
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 94 deletions.
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// NOTE: Import maps should only be used from test modules.
"imports": {
"/denops-private/": "./denops/@denops-private/",
"/denops-testdata/": "./tests/denops/testdata/",
"/denops-testutil/": "./tests/denops/testutil/"
}
}
26 changes: 14 additions & 12 deletions denops/@denops-private/service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ import {
spy,
stub,
} from "jsr:@std/testing@^1.0.0/mock";
import { toFileUrl } from "jsr:@std/path@^1.0.2/to-file-url";
import type { Meta } from "jsr:@denops/core@^7.0.0";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
import { resolveTestDataURL } from "/denops-testdata/resolve.ts";
import type { Host } from "./denops.ts";
import { Service } from "./service.ts";
import { toFileUrl } from "jsr:@std/path@^1.0.2/to-file-url";

const NOOP = () => {};

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalid = resolve("dummy_invalid_plugin.ts");
const scriptValidDispose = resolve("dummy_valid_dispose_plugin.ts");
const scriptInvalidDispose = resolve("dummy_invalid_dispose_plugin.ts");
const scriptInvalidConstraint = resolve("dummy_invalid_constraint_plugin.ts");
const scriptInvalidConstraint2 = resolve("dummy_invalid_constraint_plugin2.ts");
const scriptValid = resolveTestDataURL("dummy_valid_plugin.ts");
const scriptInvalid = resolveTestDataURL("dummy_invalid_plugin.ts");
const scriptValidDispose = resolveTestDataURL("dummy_valid_dispose_plugin.ts");
const scriptInvalidDispose = resolveTestDataURL(
"dummy_invalid_dispose_plugin.ts",
);
const scriptInvalidConstraint = resolveTestDataURL(
"dummy_invalid_constraint_plugin.ts",
);
const scriptInvalidConstraint2 = resolveTestDataURL(
"dummy_invalid_constraint_plugin2.ts",
);

Deno.test("Service", async (t) => {
const meta: Meta = {
Expand Down Expand Up @@ -1621,11 +1628,6 @@ Deno.test("Service", async (t) => {
});
});

/** Resolve testdata script URL. */
function resolve(path: string): string {
return new URL(`../../tests/denops/testdata/${path}`, import.meta.url).href;
}

async function useTempFile(options?: Deno.MakeTempOptions) {
const path = await Deno.makeTempFile(options);
return {
Expand Down
9 changes: 2 additions & 7 deletions tests/denops/runtime/functions/plugin/check_type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
assertNotMatch,
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");

testHost({
name: "denops#plugin#check_type()",
Expand Down Expand Up @@ -211,8 +211,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
9 changes: 2 additions & 7 deletions tests/denops/runtime/functions/plugin/discover_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
assertMatch,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const runtimepathPlugin = resolve("dummy_plugins");
const runtimepathPlugin = resolveTestDataPath("dummy_plugins");

testHost({
name: "denops#plugin#discover()",
Expand Down Expand Up @@ -83,8 +83,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
15 changes: 6 additions & 9 deletions tests/denops/runtime/functions/plugin/is_loaded_test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { assertEquals, assertRejects } from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalid = resolve("dummy_invalid_plugin.ts");
const scriptInvalidDispose = resolve("dummy_invalid_dispose_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");
const scriptInvalid = resolveTestDataPath("dummy_invalid_plugin.ts");
const scriptInvalidDispose = resolveTestDataPath(
"dummy_invalid_dispose_plugin.ts",
);

testHost({
name: "denops#plugin#is_loaded()",
Expand Down Expand Up @@ -309,8 +311,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
13 changes: 4 additions & 9 deletions tests/denops/runtime/functions/plugin/load_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalid = resolve("dummy_invalid_plugin.ts");
const scriptValidDispose = resolve("dummy_valid_dispose_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");
const scriptInvalid = resolveTestDataPath("dummy_invalid_plugin.ts");
const scriptValidDispose = resolveTestDataPath("dummy_valid_dispose_plugin.ts");

testHost({
name: "denops#plugin#load()",
Expand Down Expand Up @@ -387,8 +387,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
13 changes: 5 additions & 8 deletions tests/denops/runtime/functions/plugin/reload_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import {
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalidDispose = resolve("dummy_invalid_dispose_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");
const scriptInvalidDispose = resolveTestDataPath(
"dummy_invalid_dispose_plugin.ts",
);

testHost({
name: "denops#plugin#reload()",
Expand Down Expand Up @@ -360,8 +362,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
13 changes: 5 additions & 8 deletions tests/denops/runtime/functions/plugin/unload_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import {
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValidDispose = resolve("dummy_valid_dispose_plugin.ts");
const scriptInvalidDispose = resolve("dummy_invalid_dispose_plugin.ts");
const scriptValidDispose = resolveTestDataPath("dummy_valid_dispose_plugin.ts");
const scriptInvalidDispose = resolveTestDataPath(
"dummy_invalid_dispose_plugin.ts",
);

testHost({
name: "denops#plugin#unload()",
Expand Down Expand Up @@ -358,8 +360,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
15 changes: 5 additions & 10 deletions tests/denops/runtime/functions/plugin/wait_async_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalid = resolve("dummy_invalid_plugin.ts");
const scriptValidWait = resolve("dummy_valid_wait_plugin.ts");
const scriptInvalidWait = resolve("dummy_invalid_wait_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");
const scriptInvalid = resolveTestDataPath("dummy_invalid_plugin.ts");
const scriptValidWait = resolveTestDataPath("dummy_valid_wait_plugin.ts");
const scriptInvalidWait = resolveTestDataPath("dummy_invalid_wait_plugin.ts");

testHost({
name: "denops#plugin#wait_async()",
Expand Down Expand Up @@ -308,8 +308,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
15 changes: 5 additions & 10 deletions tests/denops/runtime/functions/plugin/wait_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import {
assertStringIncludes,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const MESSAGE_DELAY = 200; // msc

const scriptValid = resolve("dummy_valid_plugin.ts");
const scriptInvalid = resolve("dummy_invalid_plugin.ts");
const scriptValidWait = resolve("dummy_valid_wait_plugin.ts");
const scriptInvalidWait = resolve("dummy_invalid_wait_plugin.ts");
const scriptValid = resolveTestDataPath("dummy_valid_plugin.ts");
const scriptInvalid = resolveTestDataPath("dummy_invalid_plugin.ts");
const scriptValidWait = resolveTestDataPath("dummy_valid_wait_plugin.ts");
const scriptInvalidWait = resolveTestDataPath("dummy_invalid_wait_plugin.ts");

testHost({
name: "denops#plugin#wait()",
Expand Down Expand Up @@ -426,8 +426,3 @@ testHost({
});
},
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../../../testdata/${path}`);
}
8 changes: 2 additions & 6 deletions tests/denops/runtime/functions/server/start_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { AsyncDisposableStack } from "jsr:@nick/dispose@^1.1.0/async-disposable-stack";
import { resolveTestDataURL } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { useSharedServer } from "/denops-testutil/shared_server.ts";
import { wait } from "/denops-testutil/wait.ts";
Expand Down Expand Up @@ -404,7 +405,7 @@ testHost({
await host.call("execute", [
"silent! unlet g:__test_denops_process_stopped_fired",
`let g:denops#server#deno_args = ['${
resolve("no_check/cli_constraint_error_on_issue_401.ts")
resolveTestDataURL("no_check/cli_constraint_error_on_issue_401.ts")
}']`,
"let g:denops#server#restart_delay = 1000",
"let g:denops#server#restart_interval = 10000",
Expand Down Expand Up @@ -440,8 +441,3 @@ testHost({
);
},
});

/** Resolve testdata script URL. */
function resolve(path: string): string {
return new URL(`../../../testdata/${path}`, import.meta.url).href;
}
11 changes: 11 additions & 0 deletions tests/denops/testdata/resolve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { join } from "jsr:@std/path@^1.0.2/join";

/** Resolve testdata script path. */
export function resolveTestDataPath(path: string): string {
return join(import.meta.dirname!, path);
}

/** Resolve testdata script URL. */
export function resolveTestDataURL(path: string): string {
return new URL(path, import.meta.url).href;
}
11 changes: 3 additions & 8 deletions tests/denops/testutil/shared_server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { join } from "jsr:@std/path@^1.0.2/join";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { useSharedServer } from "./shared_server.ts";

Deno.test("useSharedServer()", async (t) => {
Expand Down Expand Up @@ -49,7 +49,7 @@ Deno.test("useSharedServer()", async (t) => {
"--allow-env",
"--allow-read",
"--allow-run",
resolve("shared_server_test_no_verbose.ts"),
resolveTestDataPath("shared_server_test_no_verbose.ts"),
],
stdout: "piped",
}).spawn();
Expand Down Expand Up @@ -94,7 +94,7 @@ Deno.test("useSharedServer()", async (t) => {
"--allow-env",
"--allow-read",
"--allow-run",
resolve("shared_server_test_verbose_true.ts"),
resolveTestDataPath("shared_server_test_verbose_true.ts"),
],
stdout: "piped",
}).spawn();
Expand All @@ -114,8 +114,3 @@ Deno.test("useSharedServer()", async (t) => {
);
});
});

/** Resolve testdata script path. */
function resolve(path: string): string {
return join(import.meta.dirname!, `../testdata/${path}`);
}

0 comments on commit ee31acf

Please sign in to comment.