Skip to content

Commit

Permalink
chore: update tui-sandbox from 2.1.0 to 5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Nov 15, 2024
1 parent 6834f61 commit 3605bc8
Show file tree
Hide file tree
Showing 14 changed files with 1,335 additions and 859 deletions.
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.

16 changes: 5 additions & 11 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@
"scripts": {
"build": "tsc && vite build",
"cy:open": "cypress open --e2e",
"cy:run": "pnpm run cy:run:ci",
"cy:run:ci": "concurrently --success command-cypress --kill-others --names 'client,server,cypress' --prefix-colors 'blue,green,yellow' 'pnpm dev:client' 'pnpm dev:server' 'wait-on --timeout 60000 http://127.0.0.1:5173 && npx cypress run'",
"dev": "concurrently --kill-others --names 'client,server,cypress' --prefix-colors 'blue,green,yellow' 'pnpm dev:client' 'pnpm dev:server' 'pnpm cy:open'",
"dev:client": "vite",
"dev:server": "nodemon --watch server --ext '*' --exec 'npx tsx ./server/server.ts'",
"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 cy:open'",
"eslint": "eslint --max-warnings=0 ."
},
"dependencies": {
"@catppuccin/palette": "1.5.0",
"cypress": "13.15.1",
"tsx": "4.19.2",
"wait-on": "8.0.1",
"zod": "3.23.8"
},
"devDependencies": {
"@tui-sandbox/library": "2.1.0",
"@tui-sandbox/library": "5.1.0",
"@types/node": "22.8.7",
"@types/tinycolor2": "1.4.6",
"@typescript-eslint/eslint-plugin": "8.12.2",
Expand All @@ -30,12 +26,10 @@
"eslint": "9.13.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-no-only-tests": "3.3.0",
"nodemon": "3.1.7",
"prettier": "3.3.3",
"prettier-plugin-organize-imports": "4.1.0",
"prettier-plugin-packagejson": "2.5.3",
"tinycolor2": "1.6.0",
"typescript": "5.6.3",
"vite": "5.4.10"
"type-fest": "4.26.1",
"typescript": "5.6.3"
}
}
Loading

0 comments on commit 3605bc8

Please sign in to comment.