Skip to content

neovim: catch neovim failed tests on CI from nvim exit code #2573

Open
@saidelike

Description

@saidelike

Atm we detect success or failure for the tests on CI by parsing the log file and searching for the line ==== TESTS FINISHED: code:. It would be more bullet proof to actually rely on the nvim exit code. See commented code below for ideas to implement it.

//packages\test-harness\src\launchNeovimAndRunTests.ts
    tailTest.on("line", function (data: string) {
      console.log(`neovim test: ${data}`);
      if (data.includes("==== TESTS FINISHED:")) {
        done = true;
        console.log(`done: ${done}`);
        const found = data.match(/.*==== TESTS FINISHED: code: (\d+).*/);
        console.log(`found: ${found}`);
        if (found !== null) {
          code = parseInt(found[1]);
          console.log(`code: ${code}`);
        }
      }
//packages\test-harness\src\runners\extensionTestsNeovim.ts
export async function run(plugin: NvimPlugin): Promise<void> {
  /**
   * We need to pass the neovim client to the tests that are executed through mocha,
   * so we add it to the global object.
   * @see https://github.com/mochajs/mocha/issues/3780#issuecomment-583064196
   * @see https://stackoverflow.com/questions/69427050/how-to-extend-globalthis-global-type
   */
  const client = plugin.nvim as NeovimClient;
  (global as any).additionalParameters = {
    client: client,
  };
  let code = 0;
  try {
    await runAllTests(TestType.neovim, TestType.unit);
    console.log(`==== TESTS FINISHED: code: ${code}`);
    // console.log(`index.ts: killing neovim with q!`);
    // await client.command(":q!");
  } catch (error) {
    console.log(`==== TESTS ERROR:`);
    console.error(error);
    code = 1;
    console.log(`==== TESTS FINISHED: code: ${code}`);
    // https://stackoverflow.com/questions/11828270/how-do-i-exit-vim
    // console.log(`index.ts: killing neovim with cq!`);
    // await client.command(":cq!");
  }
  // XXX: launchNeovimAndRunTests.ts will catch neovim exit code on CI

  // console.log(`index.ts: killing neovim with code ${code}`);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    app-neovimIssues related to neovim supportdevelopmentIssues related to Cursorless development (contributors only)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions