Skip to content

Commit cb60ca8

Browse files
authored
Merge pull request #84 from higashi000/add-load-test
Add load() test
2 parents 8e46a92 + 6d7fdec commit cb60ca8

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

denops_std/helper/load.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async function ensureLocalFile(url: URL): Promise<string> {
2828
}
2929
const response = await fetch(url);
3030
if (response.status !== 200) {
31+
await response.body?.cancel();
3132
throw new Error(`Failed to fetch '${url}'`);
3233
}
3334
const content = await response.arrayBuffer();

denops_std/helper/load_test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { assertEquals, assertThrowsAsync, test } from "../deps_test.ts";
2+
import { load } from "./load.ts";
3+
4+
const loadScriptUrlBase =
5+
"https://raw.githubusercontent.com/vim-denops/deno-denops-std/4df988237b3ea04aaa665974b44c8e7df8e237cb/denops_std/helper/";
6+
7+
test({
8+
mode: "any",
9+
name: "load() load local Vim script file",
10+
fn: async (denops) => {
11+
await load(denops, new URL("./load_test.vim", import.meta.url));
12+
assertEquals(await denops.eval("g:denops_std_load_test") as number, 1);
13+
},
14+
});
15+
16+
test({
17+
mode: "any",
18+
name: "load() load remote Vim script file",
19+
fn: async (denops) => {
20+
const loadScriptUrl = new URL("load_test.vim", loadScriptUrlBase);
21+
await load(
22+
denops,
23+
loadScriptUrl,
24+
);
25+
assertEquals(await denops.eval("g:denops_std_load_test") as number, 1);
26+
},
27+
});
28+
29+
test({
30+
mode: "any",
31+
name: "load() load not exists local Vim script file",
32+
fn: async (denops) => {
33+
await assertThrowsAsync(
34+
async () => {
35+
await load(
36+
denops,
37+
new URL("./load_test_not_exists.vim", import.meta.url),
38+
);
39+
},
40+
undefined,
41+
`Failed to call 'call' with`,
42+
);
43+
},
44+
});
45+
46+
test({
47+
mode: "any",
48+
name: "load() load not exists remote Vim script file",
49+
fn: async (denops) => {
50+
await assertThrowsAsync(
51+
async () => {
52+
const loadScriptUrl = new URL(
53+
"load_test_not_exists.vim",
54+
loadScriptUrlBase,
55+
);
56+
await load(
57+
denops,
58+
loadScriptUrl,
59+
);
60+
},
61+
Error,
62+
"Failed to fetch",
63+
);
64+
},
65+
});

denops_std/helper/load_test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let g:denops_std_load_test = 1

0 commit comments

Comments
 (0)