Skip to content

Commit

Permalink
chore: update tui-sandbox from 7.6.0 to 8.0.1 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas authored Jan 13, 2025
1 parent 0a57ef0 commit f9f5624
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 93 deletions.
78 changes: 42 additions & 36 deletions integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MyTestDirectoryFile } from "MyTestDirectory"
describe("the basics", () => {
it("shows words in other files as suggestions", () => {
cy.visit("/")
cy.startNeovim().then((dir) => {
cy.startNeovim().then((nvim) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
createFakeGitDirectoriesToLimitRipgrepScope()
Expand All @@ -32,7 +32,7 @@ describe("the basics", () => {
)

// should show the file name
cy.contains(dir.contents["other-file.lua"].name)
cy.contains(nvim.dir.contents["other-file.lua"].name)
})
})

Expand Down Expand Up @@ -160,7 +160,7 @@ describe("searching inside projects", () => {
cy.visit("/")
cy.startNeovim({
filename: "limited/subproject/file1.lua",
}).then(() => {
}).then((nvim) => {
cy.contains("This is text from file1.lua")
createFakeGitDirectoriesToLimitRipgrepScope()

Expand All @@ -174,7 +174,7 @@ describe("searching inside projects", () => {

// now switch to using --smart-case, which should be case sensitive
// when uppercase letters are used
cy.runLuaCode({
nvim.runLuaCode({
luaCode: `vim.cmd("luafile config-modifications/use_case_sensitive_search.lua")`,
})
cy.typeIntoTerminal("{esc}cc")
Expand Down Expand Up @@ -267,26 +267,26 @@ describe("debug mode", () => {
cy.startNeovim({
// also test that the plugin can handle spaces in the file path
filename: "limited/dir with spaces/file with spaces.txt",
}).then(() => {
}).then((nvim) => {
// wait until text on the start screen is visible
cy.contains("this is file with spaces.txt")
cy.runExCommand({ command: `!mkdir "%:h/.git"` })
nvim.runExCommand({ command: `!mkdir "%:h/.git"` })

// clear the current line and enter insert mode
cy.typeIntoTerminal("cc")

cy.typeIntoTerminal("spa")
cy.contains("spaceroni-macaroni")

cy.runExCommand({ command: "messages" }).then((result) => {
nvim.runExCommand({ command: "messages" }).then((result) => {
// make sure the logged command can be run in a shell
expect(result.value)
cy.log(result.value ?? "")

cy.typeIntoTerminal("{esc}:term{enter}", { delay: 3 })

// get the current buffer name
cy.runExCommand({ command: "echo expand('%')" }).then((bufname) => {
nvim.runExCommand({ command: "echo expand('%')" }).then((bufname) => {
cy.log(bufname.value ?? "")
expect(bufname.value).to.contain("term://")
})
Expand All @@ -296,7 +296,7 @@ describe("debug mode", () => {

// Quickly send the text over instead of typing it out. Cypress is a
// bit slow when writing a lot of text.
cy.runLuaCode({
nvim.runLuaCode({
luaCode: `vim.api.nvim_feedkeys([[${result.value}]], "n", true)`,
})
cy.typeIntoTerminal("{enter}")
Expand All @@ -311,7 +311,7 @@ describe("debug mode", () => {

it("highlights the search word when a new ripgrep search is started", () => {
cy.visit("/")
cy.startNeovim({}).then(() => {
cy.startNeovim({}).then((nvim) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
createFakeGitDirectoriesToLimitRipgrepScope()
Expand All @@ -321,7 +321,7 @@ describe("debug mode", () => {

// debug mode should be on by default for all tests. Otherwise it doesn't
// make sense to test this, as nothing will be displayed.
cy.runLuaCode({
nvim.runLuaCode({
luaCode: `assert(require("blink-ripgrep").config.debug)`,
})

Expand Down Expand Up @@ -350,13 +350,15 @@ describe("debug mode", () => {
rgbify(flavors.macchiato.colors.base.rgb),
)

cy.runLuaCode({
luaCode: `return _G.blink_ripgrep_invocations`,
}).should((result) => {
// ripgrep should only have been invoked once
expect(result.value).to.be.an("array")
expect(result.value).to.have.length(1)
})
nvim
.runLuaCode({
luaCode: `return _G.blink_ripgrep_invocations`,
})
.should((result) => {
// ripgrep should only have been invoked once
expect(result.value).to.be.an("array")
expect(result.value).to.have.length(1)
})
})
})

Expand All @@ -366,7 +368,7 @@ describe("debug mode", () => {
// https://github.com/mikavilpas/blink-ripgrep.nvim/issues/102

cy.visit("/")
cy.startNeovim({}).then(() => {
cy.startNeovim({}).then((nvim) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
createFakeGitDirectoriesToLimitRipgrepScope()
Expand All @@ -376,22 +378,24 @@ describe("debug mode", () => {

// debug mode should be on by default for all tests. Otherwise it doesn't
// make sense to test this, as nothing will be displayed.
cy.runLuaCode({
nvim.runLuaCode({
luaCode: `assert(require("blink-ripgrep").config.debug)`,
})

// search for something that does not exist. This should start a couple
// of searches
cy.typeIntoTerminal("yyyyyy", { delay: 80 })
cy.runExCommand({ command: "messages" }).then((result) => {
nvim.runExCommand({ command: "messages" }).then((result) => {
expect(result.value).to.contain("killed previous invocation")
})
cy.runLuaCode({
luaCode: `return _G.blink_ripgrep_invocations`,
}).should((result) => {
expect(result.value).to.be.an("array")
expect(result.value).to.have.length.above(3)
})
nvim
.runLuaCode({
luaCode: `return _G.blink_ripgrep_invocations`,
})
.should((result) => {
expect(result.value).to.be.an("array")
expect(result.value).to.have.length.above(3)
})
})
})
})
Expand All @@ -404,7 +408,7 @@ describe("using .gitignore files to exclude files from searching", () => {
cy.visit("/")
cy.startNeovim({
filename: "limited/dir with spaces/file with spaces.txt",
}).then(() => {
}).then((nvim) => {
// wait until text on the start screen is visible
cy.contains("this is file with spaces.txt")
createFakeGitDirectoriesToLimitRipgrepScope()
Expand All @@ -417,12 +421,14 @@ describe("using .gitignore files to exclude files from searching", () => {

// add a .gitignore file that ignores the file we just searched for. This
// should cause the file to not show up in the search results.
cy.runExCommand({
command: `!echo "dir with spaces/other file with spaces.txt" > $HOME/limited/.gitignore`,
}).then((result) => {
expect(result.value).not.to.include("shell returned 1")
expect(result.value).not.to.include("returned 1")
})
nvim
.runExCommand({
command: `!echo "dir with spaces/other file with spaces.txt" > $HOME/limited/.gitignore`,
})
.then((result) => {
expect(result.value).not.to.include("shell returned 1")
expect(result.value).not.to.include("returned 1")
})

// clear the buffer and repeat the search
cy.typeIntoTerminal("{esc}ggVGc")
Expand All @@ -433,11 +439,11 @@ describe("using .gitignore files to exclude files from searching", () => {
})

function createFakeGitDirectoriesToLimitRipgrepScope() {
cy.runExCommand({ command: `!mkdir $HOME/.git` }).then((result) => {
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.runExCommand({
cy.nvim_runExCommand({
command: `!mkdir $HOME/${"limited" satisfies MyTestDirectoryFile}/.git`,
}).then((result) => {
expect(result.value).not.to.include("shell returned 1")
Expand Down
132 changes: 81 additions & 51 deletions integration-tests/cypress/support/tui-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// This file is autogenerated by tui-sandbox. Do not edit it directly.
//
import type { GenericNeovimBrowserApi } from "@tui-sandbox/library/dist/src/browser/neovim-client"
import type {
BlockingCommandClientInput,
ExCommandClientInput,
Expand All @@ -20,28 +21,41 @@ import type {
MyTestDirectoryFile,
} from "../../MyTestDirectory"

export type NeovimContext = TestDirectory<MyTestDirectory>

declare global {
interface Window {
startNeovim(
startArguments?: MyStartNeovimServerArguments,
): Promise<NeovimContext>
runBlockingShellCommand(
input: BlockingCommandClientInput,
): Promise<BlockingShellCommandOutput>
runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
}
/** The api that can be used in tests after a Neovim instance has been started. */
export type NeovimContext = {
/** Types text into the terminal, making the terminal application receive
* the keystrokes as input. Requires neovim to be running. */
typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): void

/** Runs a shell command in a blocking manner, waiting for the command to
* finish before returning. Requires neovim to be running. */
runBlockingShellCommand(
input: BlockingCommandClientInput,
): Cypress.Chainable<BlockingShellCommandOutput>

/** Runs a shell command in a blocking manner, waiting for the command to
* finish before returning. Requires neovim to be running. */
runLuaCode(input: LuaCodeClientInput): Cypress.Chainable<RunLuaCodeOutput>

/** Run an ex command in neovim.
* @example "echo expand('%:.')" current file, relative to the cwd
*/
runExCommand(
input: ExCommandClientInput,
): Cypress.Chainable<RunExCommandOutput>

/** The test directory, providing type-safe access to its file and directory structure */
dir: TestDirectory<MyTestDirectory>
}

/** Arguments for starting the neovim server. They are built based on your test
* environment in a type safe manner. */
type MyStartNeovimServerArguments = OverrideProperties<
StartNeovimGenericArguments,
{
filename?:
| MyTestDirectoryFile
| { openInVerticalSplits: MyTestDirectoryFile[] }
// NOTE: right now you need to make sure the config-modifications directory exists in your test directory
startupScriptModifications?: Array<
keyof MyTestDirectory["config-modifications"]["contents"]
>
Expand All @@ -52,17 +66,35 @@ Cypress.Commands.add(
"startNeovim",
(startArguments?: MyStartNeovimServerArguments) => {
cy.window().then(async (win) => {
testWindow = win
return await win.startNeovim(startArguments)
})
},
)
const underlyingNeovim: GenericNeovimBrowserApi = await win.startNeovim(
startArguments as StartNeovimGenericArguments,
)
testNeovim = underlyingNeovim

Cypress.Commands.add(
"runBlockingShellCommand",
(input: BlockingCommandClientInput) => {
cy.window().then(async (win) => {
return await win.runBlockingShellCommand(input)
// wrap everything so that Cypress can await all the commands
Cypress.Commands.addAll({
nvim_runBlockingShellCommand: underlyingNeovim.runBlockingShellCommand,
nvim_runExCommand: underlyingNeovim.runExCommand,
nvim_runLuaCode: underlyingNeovim.runLuaCode,
})

const api: NeovimContext = {
runBlockingShellCommand(input) {
return cy.nvim_runBlockingShellCommand(input)
},
runExCommand(input) {
return cy.nvim_runExCommand(input)
},
runLuaCode(input) {
return cy.nvim_runLuaCode(input)
},
typeIntoTerminal(text, options) {
cy.typeIntoTerminal(text, options)
},
dir: underlyingNeovim.dir as TestDirectory<MyTestDirectory>,
}

return api
})
},
)
Expand All @@ -76,19 +108,7 @@ Cypress.Commands.add(
},
)

Cypress.Commands.add("runLuaCode", (input: LuaCodeClientInput) => {
cy.window().then(async (win) => {
return await win.runLuaCode(input)
})
})

Cypress.Commands.add("runExCommand", (input: ExCommandClientInput) => {
cy.window().then(async (win) => {
return await win.runExCommand(input)
})
})

let testWindow: Window | undefined
let testNeovim: GenericNeovimBrowserApi | undefined

before(function () {
// disable Cypress's default behavior of logging all XMLHttpRequests and
Expand All @@ -111,35 +131,45 @@ declare global {

/** Runs a shell command in a blocking manner, waiting for the command to
* finish before returning. Requires neovim to be running. */
runBlockingShellCommand(
nvim_runBlockingShellCommand(
input: BlockingCommandClientInput,
): Chainable<BlockingShellCommandOutput>

runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
nvim_runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>

/** Run an ex command in neovim.
* @example "echo expand('%:.')" current file, relative to the cwd
*/
runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
nvim_runExCommand(
input: ExCommandClientInput,
): Chainable<RunExCommandOutput>
}
}
}

afterEach(async () => {
if (!testWindow) return
const timeout = new Promise<void>((resolve, reject) =>
setTimeout(() => {
if (!testNeovim) return

let timeoutId: NodeJS.Timeout | undefined = undefined
const timeout = new Promise<void>((_, reject) => {
timeoutId = setTimeout(() => {
Cypress.log({
name: "timeout when waiting for :messages to finish. Neovim might be stuck.",
name: "timeout when waiting for :messages to finish. Neovim might be stuck or showing a message.",
})
reject(
"timeout when waiting for :messages to finish. Neovim might be stuck.",
new Error(
"timeout when waiting for :messages to finish. Neovim might be stuck or showing a message.",
),
)
}, 5_000),
)
}, 5_000)
})

await Promise.race([
timeout,
testWindow.runExCommand({ command: "messages" }),
])
try {
await Promise.race([
timeout,
testNeovim.runExCommand({ command: "messages" }),
])
} finally {
clearTimeout(timeoutId) // Ensure the timeout is cleared
}
})
Loading

0 comments on commit f9f5624

Please sign in to comment.