Skip to content

Commit

Permalink
perf(tests): use cy.runExCommand in all tests
Browse files Browse the repository at this point in the history
Instead of typing into the terminal to run ex commands, use the
`cy.runExCommand` command. I added it to tui-sandbox today, and it uses
the neovim node api via a socket connection. This seems to speed up the
entire integration test suite by about 3-7 seconds (~47 s now on my
machine).

The speedup comes from the fact that we don't have to wait for the
characters to be typed into the terminal, and we don't have to wait for
the output to appear on the screen in order to assert on it.

It also makes the tests more reliable, as in some cases
`cy.typeIntoTerminal` cannot be used to assert that something does not
exist in the output (since we don't know when the output is done).
  • Loading branch information
mikavilpas committed Nov 24, 2024
1 parent 80cb526 commit 97093b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion integration-tests/cypress/e2e/healthcheck.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("the healthcheck", () => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")

cy.typeIntoTerminal(":checkhealth yazi{enter}")
cy.runExCommand({ command: "checkhealth yazi" })

// the version of yazi.nvim itself should be shown
cy.readFile("../.release-please-manifest.json").then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,18 @@ describe("highlighting the buffer with 'hover' events", () => {
)

cy.typeIntoTerminal("q")
cy.typeIntoTerminal(":messages{enter}")

// Hovering a new file should have triggered the integration
//
// the main message from the integration in the
// startupScriptModifications script should be visible. Check the file
// to see the full integration.
cy.contains("Just received a YaziDDSHover event!")

// some event data should be visible. See the lua type YaziHoverEvent for
// the structure
cy.contains(`type = "hover"`)
cy.runExCommand({ command: "messages" }).then((result) => {
// Hovering a new file should have triggered the integration
//
// the main message from the integration in the
// startupScriptModifications script should be visible. Check the file
// to see the full integration.
expect(result.value).to.contain("Just received a YaziDDSHover event!")

// some event data should be visible. See the lua type YaziHoverEvent for
// the structure
expect(result.value).to.contain(`type = "hover"`)
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("grug-far integration (search and replace)", () => {
cy.typeIntoTerminal("{esc}")

// close the split on the right so we can get some more space
cy.typeIntoTerminal(":only{enter}")
cy.runExCommand({ command: "only" })

// the selected files should be visible in the view, used as the files to
// whitelist into the search and replace operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ describe("opening directories", () => {
cy.typeIntoTerminal("q")
cy.contains("-- TERMINAL --").should("not.exist")

cy.typeIntoTerminal(":CountBuffers{enter}")
cy.contains("Number of open buffers: 2")
cy.runExCommand({ command: "CountBuffers" }).then((result) => {
expect(result.value).to.equal("Number of open buffers: 2")
})
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MyTestDirectoryFile } from "MyTestDirectory"
import {
isFileNotSelectedInYazi,
isFileSelectedInYazi,
Expand Down Expand Up @@ -84,7 +85,7 @@ describe("opening files", () => {
// match some text from inside the file
"Hello",
)
cy.typeIntoTerminal(":tabnext{enter}")
cy.runExCommand({ command: "tabnext" })

cy.contains("If you see this text, Neovim is ready!")

Expand Down Expand Up @@ -174,9 +175,9 @@ describe("opening files", () => {
cy.typeIntoTerminal("q")

// the file should now be renamed - ask neovim to confirm this
cy.typeIntoTerminal(":buffers{enter}")

cy.contains("renamed-file.txt")
cy.runExCommand({ command: "buffers" }).then((result) => {
expect(result.value).to.contain("renamed-file.txt")
})
})
})
})
Expand Down Expand Up @@ -260,9 +261,11 @@ describe("opening files", () => {
// the file to verify this.
// NOTE: the test-setup configures the `"` register to be the clipboard
cy.typeIntoTerminal("o{enter}{esc}")
cy.typeIntoTerminal(':normal ""p{enter}')

cy.contains("routes/posts.$postId/adjacent-file.txt")
cy.runLuaCode({ luaCode: `return vim.fn.getreg('"')` }).then((result) => {
expect(result.value).to.contain(
"routes/posts.$postId/adjacent-file.txt" satisfies MyTestDirectoryFile,
)
})
})
})

Expand Down Expand Up @@ -299,12 +302,17 @@ describe("opening files", () => {
// the file to verify this.
// NOTE: the test-setup configures the `"` register to be the clipboard
cy.typeIntoTerminal("o{enter}{esc}")
cy.typeIntoTerminal(':normal ""p{enter}')

// all selected files should now be visible
cy.contains("routes/posts.$postId/adjacent-file.txt")
cy.contains("routes/posts.$postId/route.tsx")
cy.contains("routes/posts.$postId/adjacent-file.txt")
cy.runLuaCode({ luaCode: `return vim.fn.getreg('"')` }).then((result) => {
expect(result.value).to.eql(
(
[
"routes/posts.$postId/adjacent-file.txt",
"routes/posts.$postId/route.tsx",
"routes/posts.$postId/should-be-excluded-file.txt",
] satisfies MyTestDirectoryFile[]
).join("\n"),
)
})
})
})

Expand All @@ -319,11 +327,14 @@ describe("opening files", () => {
cy.typeIntoTerminal("{control+a}")
cy.typeIntoTerminal("{enter}")

cy.typeIntoTerminal(":buffers{enter}")

// all files should now be visible
cy.contains("dir with spaces/file1.txt")
cy.contains("dir with spaces/file2.txt")
cy.runExCommand({ command: "buffers" }).then((result) => {
expect(result.value).to.match(
new RegExp("dir with spaces/file1.txt" satisfies MyTestDirectoryFile),
)
expect(result.value).to.match(
new RegExp("dir with spaces/file2.txt" satisfies MyTestDirectoryFile),
)
})
})
})

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"cy:run": "concurrently --success command-cypress --kill-others --names 'app,cypress' --prefix-colors 'blue,yellow' 'pnpm tui start' 'wait-on --timeout 60000 http://127.0.0.1:3000 && npx cypress run'",
"dev": "concurrently --kill-others --names 'app,cypress' --prefix-colors 'blue,yellow' 'pnpm tui start' 'pnpm cypress open --e2e'",
"dev": "concurrently --kill-others --names 'app,cypress' --prefix-colors 'blue,yellow' 'pnpm tui start' 'pnpm cypress open --e2e --browser=electron'",
"eslint": "eslint --max-warnings=0 ."
},
"dependencies": {
Expand Down

0 comments on commit 97093b1

Please sign in to comment.