From f0dec94e5b0d1f7e3f22cd528e5cc3fc1a392d98 Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Sun, 23 Feb 2025 09:42:36 +0200 Subject: [PATCH] refactor(tests): create real git repos to limit search scope Previously, a hack was used to create fake git directories, but now that tui-sandbox supports running actual shell commands nicely, we can just use that instead. --- .github/workflows/test.yml | 5 +++++ .../e2e/blink-ripgrep/basic_spec.cy.ts | 14 ++++++------- ...teFakeGitDirectoriesToLimitRipgrepScope.ts | 14 ------------- .../createGitReposToLimitSearchScope.ts | 11 ++++++++++ .../e2e/blink-ripgrep/debug-mode.cy.ts | 6 +++--- .../searching-inside-projects.cy.ts | 20 +++++++++---------- .../cypress/e2e/blink-ripgrep/toggling.cy.ts | 4 ++-- .../test-environment/.config/git/config | 6 ++++++ 8 files changed, 44 insertions(+), 36 deletions(-) delete mode 100644 integration-tests/cypress/e2e/blink-ripgrep/createFakeGitDirectoriesToLimitRipgrepScope.ts create mode 100644 integration-tests/cypress/e2e/blink-ripgrep/createGitReposToLimitSearchScope.ts create mode 100644 integration-tests/test-environment/.config/git/config diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9e0a5c6..6d49378 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,11 @@ jobs: } echo "Ripgrep version: $(rg --version)" + which git || { + sudo apt-get install git + } + echo "git version: $(git --version)" + - name: Run lua tests uses: nvim-neorocks/nvim-busted-action@v1.1.0 with: diff --git a/integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts b/integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts index e1e800c..02410a4 100644 --- a/integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts +++ b/integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts @@ -1,6 +1,6 @@ import { flavors } from "@catppuccin/palette" import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities" -import { createFakeGitDirectoriesToLimitRipgrepScope } from "./createFakeGitDirectoriesToLimitRipgrepScope" +import { createGitReposToLimitSearchScope } from "./createGitReposToLimitSearchScope" describe("the basics", () => { it("shows words in other files as suggestions", () => { @@ -8,7 +8,7 @@ describe("the basics", () => { cy.startNeovim().then((nvim) => { // wait until text on the start screen is visible cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // clear the current line and enter insert mode cy.typeIntoTerminal("cc") @@ -48,7 +48,7 @@ describe("the basics", () => { }).then(() => { // wait until text on the start screen is visible cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // clear the current line and enter insert mode cy.typeIntoTerminal("cc") @@ -69,7 +69,7 @@ describe("the basics", () => { cy.startNeovim({}).then(() => { // wait until text on the start screen is visible cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // clear the current line and enter insert mode cy.typeIntoTerminal("cc") @@ -97,7 +97,7 @@ describe("the basics", () => { }).then((nvim) => { // wait until text on the start screen is visible cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() const ignorePath = nvim.dir.rootPathAbsolute + "/limited" nvim.runLuaCode({ luaCode: `_G.set_ignore_paths({ "${ignorePath}" })`, @@ -137,7 +137,7 @@ describe("the basics", () => { cy.visit("/") cy.startNeovim().then(() => { cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("cc") @@ -172,7 +172,7 @@ describe("the basics", () => { }).then(() => { // wait until text on the start screen is visible cy.contains("this is file with spaces.txt") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("cc") // search for something that will be found in the additional words.txt file diff --git a/integration-tests/cypress/e2e/blink-ripgrep/createFakeGitDirectoriesToLimitRipgrepScope.ts b/integration-tests/cypress/e2e/blink-ripgrep/createFakeGitDirectoriesToLimitRipgrepScope.ts deleted file mode 100644 index 355b805..0000000 --- a/integration-tests/cypress/e2e/blink-ripgrep/createFakeGitDirectoriesToLimitRipgrepScope.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { MyTestDirectoryFile } from "MyTestDirectory" - -export function createFakeGitDirectoriesToLimitRipgrepScope(): void { - cy.nvim_runExCommand({ command: `!mkdir $HOME/.git` }).then((result) => { - expect(result.value).not.to.include("shell returned 1") - expect(result.value).not.to.include("returned 1") - }) - cy.nvim_runExCommand({ - command: `!mkdir $HOME/${"limited" satisfies MyTestDirectoryFile}/.git`, - }).then((result) => { - expect(result.value).not.to.include("shell returned 1") - expect(result.value).not.to.include("returned 1") - }) -} diff --git a/integration-tests/cypress/e2e/blink-ripgrep/createGitReposToLimitSearchScope.ts b/integration-tests/cypress/e2e/blink-ripgrep/createGitReposToLimitSearchScope.ts new file mode 100644 index 0000000..54fdc77 --- /dev/null +++ b/integration-tests/cypress/e2e/blink-ripgrep/createGitReposToLimitSearchScope.ts @@ -0,0 +1,11 @@ +// this works for both GitGrepBackend and RipgrepBackend +export function createGitReposToLimitSearchScope(): void { + cy.nvim_runBlockingShellCommand({ + command: "git init && git add . && git commit -m 'initial commit'", + cwdRelative: ".", + }) + cy.nvim_runBlockingShellCommand({ + command: "git init && git add . && git commit -m 'initial commit'", + cwdRelative: "limited", + }) +} diff --git a/integration-tests/cypress/e2e/blink-ripgrep/debug-mode.cy.ts b/integration-tests/cypress/e2e/blink-ripgrep/debug-mode.cy.ts index 88808c9..2313d8c 100644 --- a/integration-tests/cypress/e2e/blink-ripgrep/debug-mode.cy.ts +++ b/integration-tests/cypress/e2e/blink-ripgrep/debug-mode.cy.ts @@ -1,6 +1,6 @@ import { flavors } from "@catppuccin/palette" import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities" -import { createFakeGitDirectoriesToLimitRipgrepScope } from "./createFakeGitDirectoriesToLimitRipgrepScope" +import { createGitReposToLimitSearchScope } from "./createGitReposToLimitSearchScope" describe("debug mode", () => { it("can execute the debug command in a shell", () => { @@ -59,7 +59,7 @@ describe("debug mode", () => { cy.startNeovim({}).then((nvim) => { // wait until text on the start screen is visible cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // clear the current line and enter insert mode cy.typeIntoTerminal("cc") @@ -116,7 +116,7 @@ describe("debug mode", () => { cy.startNeovim({}).then((nvim) => { // wait until text on the start screen is visible cy.contains("If you see this text, Neovim is ready!") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // clear the current line and enter insert mode cy.typeIntoTerminal("cc") diff --git a/integration-tests/cypress/e2e/blink-ripgrep/searching-inside-projects.cy.ts b/integration-tests/cypress/e2e/blink-ripgrep/searching-inside-projects.cy.ts index 2d95769..7ecc204 100644 --- a/integration-tests/cypress/e2e/blink-ripgrep/searching-inside-projects.cy.ts +++ b/integration-tests/cypress/e2e/blink-ripgrep/searching-inside-projects.cy.ts @@ -1,9 +1,9 @@ import { flavors } from "@catppuccin/palette" import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities" -import { createFakeGitDirectoriesToLimitRipgrepScope } from "./createFakeGitDirectoriesToLimitRipgrepScope" +import { createGitReposToLimitSearchScope } from "./createGitReposToLimitSearchScope" -describe("searching inside projects", () => { - // NOTE: the tests setup fake git repositories in the test environment using +describe("searching inside projects with the RipgrepBackend", () => { + // NOTE: the tests setup git repositories in the test environment using // ../../../server/server.ts // // This limits the search to the nearest .git directory above the current @@ -14,7 +14,7 @@ describe("searching inside projects", () => { // when completing from a file in a superproject, the search may descend // to subprojects cy.contains("this text is from main-project-file") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("o") cy.typeIntoTerminal("some") @@ -34,7 +34,7 @@ describe("searching inside projects", () => { // the nearest .git directory (only the files in the same project should // be searched) cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("o") cy.typeIntoTerminal("some") @@ -60,7 +60,7 @@ describe("searching inside projects", () => { // the nearest .git directory (only the files in the same project should // be searched) cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // make sure the preconditions for this case are met nvim.runLuaCode({ @@ -106,7 +106,7 @@ describe("searching inside projects", () => { filename: "limited/subproject/file1.lua", }).then((nvim) => { cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // the default is to use --ignore-case. Let's make sure that works first cy.typeIntoTerminal("o") @@ -141,7 +141,7 @@ describe("searching inside projects", () => { // This way the user can quickly get an idea of where the match was // found. cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("o") // match text inside ../../../test-environment/limited/subproject/example.clj @@ -170,7 +170,7 @@ describe("searching inside projects", () => { // the nearest .git directory (only the files in the same project should // be searched) cy.contains("This is text from file1.lua") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("o") // match text inside ../../../test-environment/limited/subproject/example.clj @@ -215,7 +215,7 @@ describe("searching inside projects", () => { }).then((nvim) => { // wait until text on the start screen is visible cy.contains("this is file with spaces.txt") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() cy.typeIntoTerminal("cc") // first, make sure that a file is included (so we can make sure it can diff --git a/integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts b/integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts index a5d45bf..c3bbcda 100644 --- a/integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts +++ b/integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts @@ -1,6 +1,6 @@ import { flavors } from "@catppuccin/palette" import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities" -import { createFakeGitDirectoriesToLimitRipgrepScope } from "./createFakeGitDirectoriesToLimitRipgrepScope" +import { createGitReposToLimitSearchScope } from "./createGitReposToLimitSearchScope" describe("toggling features on/off", () => { // Some features can be toggled on/off without restarting Neovim. This can be @@ -13,7 +13,7 @@ describe("toggling features on/off", () => { // when completing from a file in a superproject, the search may descend // to subprojects cy.contains("this text is from main-project-file") - createFakeGitDirectoriesToLimitRipgrepScope() + createGitReposToLimitSearchScope() // first verify that the plugin is enabled cy.typeIntoTerminal("o") diff --git a/integration-tests/test-environment/.config/git/config b/integration-tests/test-environment/.config/git/config new file mode 100644 index 0000000..7133c56 --- /dev/null +++ b/integration-tests/test-environment/.config/git/config @@ -0,0 +1,6 @@ +[user] + email=john.doe@example.com + name=John Doe +[init] + defaultBranch=main +# vim: set ft=gitconfig: