Skip to content

Commit

Permalink
chore: update tui-sandbox from 2.1.0 to 5.1.0 (#35)
Browse files Browse the repository at this point in the history
The ci setup needs to work around
cypress-io/github-action#1246
  • Loading branch information
mikavilpas authored Nov 15, 2024
1 parent 6834f61 commit 1bf569f
Show file tree
Hide file tree
Showing 15 changed files with 1,345 additions and 870 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,35 @@ jobs:
sudo apt-get install ripgrep
}
- name: Run tests
- name: Run lua tests
uses: nvim-neorocks/[email protected]
with:
nvim_version: ${{ matrix.neovim_version }}
luarocks_version: "3.11.1"

# https://github.com/cypress-io/github-action?tab=readme-ov-file#pnpm-workspaces
- uses: pnpm/[email protected]
- uses: actions/[email protected]
with:
node-version-file: .nvmrc
cache: "pnpm"
- uses: actions/cache@v4
with:
path: |
~/.cache/Cypress
key: my-cache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
- run: pnpm install

- name: Install dependencies
uses: cypress-io/github-action@v6
with:
runTests: false
# https://github.com/cypress-io/github-action/blob/bff0ae58f02476fbc4b13229bcaac2767f645b3e/README.md#pnpm-workspaces
- name: initialize neovim dependencies
run: |
echo "Initializing neovim dependencies..."
cd integration-tests/test-environment/
# execute the lazy installation script and exit right away
nvim -u test-setup.lua -c "exit"
- name: Cypress test
uses: cypress-io/github-action@v6
with:
install: false
command: pnpm cy:run
# need to work around https://github.com/cypress-io/github-action/issues/1246
- run: pnpm --filter integration-tests exec cypress install
- run: pnpm cy:run

- uses: actions/[email protected]
# add the line below to store screenshots only on failures
Expand Down
40 changes: 24 additions & 16 deletions integration-tests/MyTestDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,45 @@
import { z } from "zod"

export const MyTestDirectorySchema = z.object({
name: z.literal("test-environment"),
name: z.literal("test-environment/"),
type: z.literal("directory"),
contents: z.object({
".config": z.object({
name: z.literal(".config/"),
type: z.literal("directory"),
contents: z.object({
nvim: z.object({
name: z.literal("nvim/"),
type: z.literal("directory"),
contents: z.object({
"init.lua": z.object({
name: z.literal("init.lua"),
type: z.literal("file"),
extension: z.literal("lua"),
stem: z.literal("init."),
}),
}),
}),
}),
}),
"initial-file.txt": z.object({
name: z.literal("initial-file.txt"),
type: z.literal("file"),
extension: z.literal("txt"),
stem: z.literal("initial-file."),
}),
limited: z.object({
name: z.literal("limited"),
name: z.literal("limited/"),
type: z.literal("directory"),
contents: z.object({
".git": z.object({
name: z.literal(".git"),
type: z.literal("directory"),
contents: z.object({}),
}),
"main-project-file.lua": z.object({
name: z.literal("main-project-file.lua"),
type: z.literal("file"),
extension: z.literal("lua"),
stem: z.literal("main-project-file."),
}),
subproject: z.object({
name: z.literal("subproject"),
name: z.literal("subproject/"),
type: z.literal("directory"),
contents: z.object({
"file1.lua": z.object({
Expand All @@ -61,12 +74,6 @@ export const MyTestDirectorySchema = z.object({
extension: z.literal("lua"),
stem: z.literal("other-file."),
}),
"test-setup.lua": z.object({
name: z.literal("test-setup.lua"),
type: z.literal("file"),
extension: z.literal("lua"),
stem: z.literal("test-setup."),
}),
}),
})

Expand All @@ -79,15 +86,16 @@ export type MyTestDirectoryContentsSchemaType = z.infer<
export type MyTestDirectory = MyTestDirectoryContentsSchemaType["contents"]

export const testDirectoryFiles = z.enum([
".config/nvim/init.lua",
".config/nvim",
".config",
"initial-file.txt",
"limited/.git",
"limited/main-project-file.lua",
"limited/subproject/file1.lua",
"limited/subproject/file2.lua",
"limited/subproject",
"limited",
"other-file.lua",
"test-setup.lua",
".",
])
export type MyTestDirectoryFile = z.infer<typeof testDirectoryFiles>
25 changes: 0 additions & 25 deletions integration-tests/client/__global.ts

This file was deleted.

46 changes: 0 additions & 46 deletions integration-tests/client/neovim-client.ts

This file was deleted.

24 changes: 1 addition & 23 deletions integration-tests/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import { defineConfig } from "cypress"
import { mkdir, readdir, rm } from "fs/promises"
import path from "path"
import { fileURLToPath } from "url"

const __dirname = fileURLToPath(new URL(".", import.meta.resolve(".")))

const testEnvironmentDir = path.join(__dirname, "test-environment")
const testdirs = path.join(testEnvironmentDir, "testdirs")

export default defineConfig({
e2e: {
setupNodeEvents(on, _config) {
on("after:browser:launch", async (): Promise<void> => {
// delete everything under the ./test-environment/testdirs/ directory
await mkdir(testdirs, { recursive: true })
const files = await readdir(testdirs)

console.log("Cleaning up testdirs directory...")

for (const file of files) {
const testdir = path.join(testdirs, file)
console.log(`Removing ${testdir}`)
await rm(testdir, { recursive: true })
}
})
},
baseUrl: "http://localhost:3000",
experimentalRunAllSpecs: true,
retries: {
runMode: 2,
Expand Down
43 changes: 23 additions & 20 deletions integration-tests/cypress/e2e/blink-ripgrep/basic_spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import { flavors } from "@catppuccin/palette"

export function rgbify(
color: (typeof flavors.macchiato.colors)["surface0"]["rgb"],
): string {
return `rgb(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()})`
}
import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities"
import type { MyTestDirectoryFile } from "MyTestDirectory"

describe("the basics", () => {
it("shows words in other files as suggestions", () => {
cy.visit("http://localhost:5173")
cy.visit("/")
cy.startNeovim().then((dir) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
cy.typeIntoTerminal(
// clear the current line and enter insert mode
"cc",
)
createFakeGitDirectoriesToLimitRipgrepScope()
cy.pause()

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

// this will match text from ../../../test-environment/other-file.txt
// this will match text from ../../../test-environment/other-file.lua
//
// If the plugin works, this text should show up as a suggestion.
cy.typeIntoTerminal(
// NOTE: need to break it into parts so that this test file itself does
// not match the search :)
"hip" + "234",
)
cy.typeIntoTerminal("hip234")

cy.contains("Hippopotamus" + "234 (rg)")

Expand All @@ -33,7 +26,7 @@ describe("the basics", () => {
// should show the text for the matched line
//
// the text should also be syntax highlighted
cy.contains("Hippopotamus" + "234 was my previous password").should(
cy.contains("Hippopotamus234 was my previous password").should(
"have.css",
"color",
rgbify(flavors.macchiato.colors.green.rgb),
Expand All @@ -52,11 +45,12 @@ describe("searching inside projects", () => {
// This limits the search to the nearest .git directory above the current
// file.
it("descends into subprojects", () => {
cy.visit("http://localhost:5173")
cy.visit("/")
cy.startNeovim({ filename: "limited/main-project-file.lua" }).then(() => {
// when completing from a file in a superproject, the search may descend
// to subprojects
cy.contains("this text is from main-project-file")
createFakeGitDirectoriesToLimitRipgrepScope()

cy.typeIntoTerminal("o")
cy.typeIntoTerminal("some")
Expand All @@ -70,12 +64,13 @@ describe("searching inside projects", () => {
})

it("limits the search to the nearest .git directory", () => {
cy.visit("http://localhost:5173")
cy.visit("/")
cy.startNeovim({ filename: "limited/subproject/file1.lua" }).then(() => {
// when opening a file from a subproject, the search should be limited to
// the nearest .git directory (only the files in the same project should
// be searched)
cy.contains("This is text from file1.lua")
createFakeGitDirectoriesToLimitRipgrepScope()

cy.typeIntoTerminal("o")
cy.typeIntoTerminal("some")
Expand All @@ -88,3 +83,11 @@ describe("searching inside projects", () => {
})
})
})

function createFakeGitDirectoriesToLimitRipgrepScope() {
cy.typeIntoTerminal(`:!mkdir %:h/.git{enter}`, { delay: 0 })
cy.typeIntoTerminal(
`:!mkdir %:h/${"limited" satisfies MyTestDirectoryFile}/.git{enter}`,
{ delay: 0 },
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("the healthcheck", () => {
it("does not show any errors when ripgrep is installed", () => {
cy.visit("http://localhost:5173")
cy.visit("/")
cy.startNeovim().then(() => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
Expand Down
35 changes: 30 additions & 5 deletions integration-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
/* eslint-disable @typescript-eslint/no-namespace */
/// <reference types="cypress" />

import "../../client/__global.ts"
import type { NeovimContext } from "../../client/__global.ts"
import type { MyStartNeovimServerArguments } from "../../client/neovim-client.ts"
import type { StartNeovimGenericArguments } from "@tui-sandbox/library/dist/src/server/neovim/NeovimApplication"
import type { OverrideProperties } from "type-fest"
import type {
MyTestDirectory,
MyTestDirectoryFile,
} from "../../MyTestDirectory"

export type NeovimContext = {
contents: MyTestDirectory
rootPathAbsolute: string
}

declare global {
interface Window {
startNeovim(
startArguments?: MyStartNeovimServerArguments,
): Promise<NeovimContext>
}
}

type MyStartNeovimServerArguments = OverrideProperties<
StartNeovimGenericArguments,
{
filename?:
| MyTestDirectoryFile
| { openInVerticalSplits: MyTestDirectoryFile[] }
}
>

Cypress.Commands.add(
"startNeovim",
(startArguments?: MyStartNeovimServerArguments) => {
cy.window().then((win) => {
return win.startNeovim(startArguments)
cy.window().then(async (win) => {
return await win.startNeovim(startArguments)
})
},
)
Expand Down
12 changes: 0 additions & 12 deletions integration-tests/index.html

This file was deleted.

Loading

0 comments on commit 1bf569f

Please sign in to comment.