Skip to content

Commit

Permalink
Merge pull request #45 from vim-denops/fix-tester
Browse files Browse the repository at this point in the history
Add DENOPS_PATH to specify denops.vim and add notes
  • Loading branch information
lambdalisue authored Jun 5, 2021
2 parents aedfb5f + bb0ee1b commit b4949d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: deno

env:
DENO_VERSION: 1.x
DENOPS_PATH: "./"

on:
schedule:
Expand Down
16 changes: 16 additions & 0 deletions denops/@denops/denops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,29 @@ export class Denops {
* and the containing module looks like a test module.
*
* `fn` receive `denops` instance which communicate with real Vim/Neovim.
*
* To use this function, developer must provides the following environment variables:
*
* DENOPS_PATH - A path to `denops.vim` for adding to Vim's `runtimepath`
* DENOPS_TEST_VIM - An executable of Vim
* DENOPS_TEST_NVIM - An executable of Neovim
*
* Otherwise tests using this static method will be ignored.
*/
static test(t: TestDefinition): void;
/**
* Register a test which will berun when `deno test` is used on the command line
* and the containing module looks like a test module.
*
* `fn` receive `denops` instance which communicate with real Vim/Neovim.
*
* To use this function, developer must provides the following environment variables:
*
* DENOPS_PATH - A path to `denops.vim` for adding to Vim's `runtimepath`
* DENOPS_TEST_VIM - An executable of Vim
* DENOPS_TEST_NVIM - An executable of Neovim
*
* Otherwise tests using this static method will be ignored.
*/
static test(
mode: "vim" | "nvim",
Expand Down
19 changes: 15 additions & 4 deletions denops/@denops/test/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ import { path } from "../deps.ts";
import { Denops } from "../denops.ts";
import { DENOPS_TEST_NVIM, DENOPS_TEST_VIM, run } from "./runner.ts";

const SCRIPT_PATH = path.fromFileUrl(new URL("cli/bypass.ts", import.meta.url));
const DENOPS_PATH = path.fromFileUrl(new URL("../../..", import.meta.url));
const DENOPS_PATH = Deno.env.get("DENOPS_PATH");

async function withDenops(
mode: "vim" | "nvim",
main: (denops: Denops) => Promise<void> | void,
) {
if (!DENOPS_PATH) {
throw new Error("`DENOPS_PATH` environment variable is not defined");
}
const denopsPath = path.resolve(DENOPS_PATH);
const scriptPath = path.join(
denopsPath,
"denops",
"@denops",
"test",
"cli",
"bypass.ts",
);
const listener = Deno.listen({
hostname: "127.0.0.1",
port: 0, // Automatically select free port
});
const proc = run(mode, {
commands: [
`set runtimepath^=${DENOPS_PATH}`,
`autocmd User DenopsReady call denops#plugin#register('denops-std-test', '${SCRIPT_PATH}')`,
`autocmd User DenopsReady call denops#plugin#register('denops-std-test', '${scriptPath}')`,
"call denops#server#start()",
],
env: {
Expand Down Expand Up @@ -54,7 +65,7 @@ export type TestDefinition = Omit<Deno.TestDefinition, "fn"> & {
export function test(t: TestDefinition): void {
Deno.test({
...t,
ignore: (t.mode === "vim" && !DENOPS_TEST_VIM) ||
ignore: !DENOPS_PATH || (t.mode === "vim" && !DENOPS_TEST_VIM) ||
(t.mode === "nvim" && !DENOPS_TEST_NVIM),
fn: async () => {
await withDenops(t.mode, t.fn);
Expand Down

0 comments on commit b4949d6

Please sign in to comment.