Skip to content

Commit

Permalink
refactor(tests): create real git repos to limit search scope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikavilpas committed Feb 23, 2025
1 parent 9d1351f commit f0dec94
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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", () => {
cy.visit("/")
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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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}" })`,
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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",
})
}
6 changes: 3 additions & 3 deletions integration-tests/cypress/e2e/blink-ripgrep/debug-mode.cy.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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({
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/test-environment/.config/git/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[user]
email=john.doe@example.com
name=John Doe
[init]
defaultBranch=main
# vim: set ft=gitconfig:

0 comments on commit f0dec94

Please sign in to comment.