@tui-sandbox/library 11.11.2 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/browser/assets/index-BITC1TRH.js +9 -0
  2. package/dist/browser/assets/index-CYUPHpRk.css +1 -0
  3. package/dist/browser/index.html +2 -2
  4. package/dist/src/browser/neovim-client.d.ts +5 -0
  5. package/dist/src/browser/neovim-client.js +4 -0
  6. package/dist/src/browser/neovim-client.js.map +1 -1
  7. package/dist/src/client/clipboard.d.ts +18 -0
  8. package/dist/src/client/clipboard.js +19 -0
  9. package/dist/src/client/clipboard.js.map +1 -0
  10. package/dist/src/client/index.d.ts +2 -0
  11. package/dist/src/client/index.js.map +1 -1
  12. package/dist/src/client/neovim-terminal-client.d.ts +2 -2
  13. package/dist/src/client/neovim-terminal-client.js +5 -2
  14. package/dist/src/client/neovim-terminal-client.js.map +1 -1
  15. package/dist/src/client/startTerminal.d.ts +2 -2
  16. package/dist/src/client/startTerminal.js +18 -15
  17. package/dist/src/client/startTerminal.js.map +1 -1
  18. package/dist/src/client/terminal-terminal-client.d.ts +3 -2
  19. package/dist/src/client/terminal-terminal-client.js +5 -1
  20. package/dist/src/client/terminal-terminal-client.js.map +1 -1
  21. package/dist/src/server/cypress-support/contents.js +38 -11
  22. package/dist/src/server/cypress-support/contents.js.map +1 -1
  23. package/dist/src/server/index.d.ts +4 -0
  24. package/dist/src/server/index.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +35 -8
  27. package/CHANGELOG.md +0 -941
  28. package/dist/browser/assets/index-BQzArJW3.js +0 -9
  29. package/dist/browser/assets/index-hkmOP7rU.css +0 -1
  30. package/index.html +0 -11
  31. package/src/browser/neovim-client.ts +0 -126
  32. package/src/client/MyNeovimConfigModification.test.ts +0 -25
  33. package/src/client/MyNeovimConfigModification.ts +0 -8
  34. package/src/client/color-utilities.test.ts +0 -10
  35. package/src/client/color-utilities.ts +0 -9
  36. package/src/client/cypress-assertions.ts +0 -35
  37. package/src/client/index.ts +0 -4
  38. package/src/client/neovim-terminal-client.ts +0 -130
  39. package/src/client/public/DejaVuSansMNerdFontMono-Regular.ttf +0 -0
  40. package/src/client/startTerminal.ts +0 -97
  41. package/src/client/style.css +0 -32
  42. package/src/client/terminal-config.ts +0 -25
  43. package/src/client/terminal-terminal-client.ts +0 -106
  44. package/src/client/validateMouseEvent.ts +0 -22
  45. package/src/scripts/commands/commandRun.ts +0 -68
  46. package/src/scripts/commands/commandTuiNeovimExec.ts +0 -36
  47. package/src/scripts/commands/commandTuiNeovimPrepare.ts +0 -12
  48. package/src/scripts/commands/commandTuiStart.ts +0 -36
  49. package/src/scripts/parseArguments.test.ts +0 -28
  50. package/src/scripts/parseArguments.ts +0 -66
  51. package/src/scripts/resolveConfig.test.ts +0 -78
  52. package/src/scripts/resolveTuiConfig.ts +0 -65
  53. package/src/scripts/tui.ts +0 -77
  54. package/src/server/TestServer.ts +0 -73
  55. package/src/server/applications/neovim/NeovimApplication.ts +0 -236
  56. package/src/server/applications/neovim/NeovimJavascriptApiClient.test.ts +0 -48
  57. package/src/server/applications/neovim/NeovimJavascriptApiClient.ts +0 -68
  58. package/src/server/applications/neovim/api.ts +0 -257
  59. package/src/server/applications/neovim/environment/TempDirectory.ts +0 -18
  60. package/src/server/applications/neovim/environment/createTempDir.test.ts +0 -29
  61. package/src/server/applications/neovim/environment/createTempDir.ts +0 -91
  62. package/src/server/applications/neovim/neovimRouter.ts +0 -100
  63. package/src/server/applications/neovim/prepareNewTestDirectory.test.ts +0 -32
  64. package/src/server/applications/neovim/prepareNewTestDirectory.ts +0 -21
  65. package/src/server/applications/terminal/TerminalTestApplication.ts +0 -101
  66. package/src/server/applications/terminal/api.ts +0 -89
  67. package/src/server/applications/terminal/runBlockingShellCommand.test.ts +0 -41
  68. package/src/server/applications/terminal/runBlockingShellCommand.ts +0 -64
  69. package/src/server/applications/terminal/terminalRouter.ts +0 -47
  70. package/src/server/blockingCommandInputSchema.test.ts +0 -24
  71. package/src/server/blockingCommandInputSchema.ts +0 -27
  72. package/src/server/config.test.ts +0 -7
  73. package/src/server/config.ts +0 -18
  74. package/src/server/connection/trpc.ts +0 -3
  75. package/src/server/cypress-support/contents.ts +0 -245
  76. package/src/server/cypress-support/createCypressSupportFile.test.ts +0 -69
  77. package/src/server/cypress-support/createCypressSupportFile.ts +0 -56
  78. package/src/server/dirtree/index.test.ts +0 -352
  79. package/src/server/dirtree/index.ts +0 -144
  80. package/src/server/dirtree/json-to-zod.ts +0 -60
  81. package/src/server/index.ts +0 -6
  82. package/src/server/server.ts +0 -34
  83. package/src/server/types.ts +0 -98
  84. package/src/server/updateTestdirectorySchemaFile.test.ts +0 -49
  85. package/src/server/updateTestdirectorySchemaFile.ts +0 -71
  86. package/src/server/utilities/DisposableSingleApplication.test.ts +0 -92
  87. package/src/server/utilities/DisposableSingleApplication.ts +0 -49
  88. package/src/server/utilities/Lazy.ts +0 -16
  89. package/src/server/utilities/TerminalApplication.ts +0 -100
  90. package/src/server/utilities/generator.test.ts +0 -50
  91. package/src/server/utilities/generator.ts +0 -12
  92. package/src/server/utilities/tabId.ts +0 -4
  93. package/src/server/utilities/timeout.ts +0 -3
  94. package/src/server/utilities/timeoutable.ts +0 -19
  95. package/tsconfig.json +0 -31
  96. package/vite.config.js +0 -27
@@ -1,245 +0,0 @@
1
- import { format, resolveConfig } from "prettier"
2
- import { fileURLToPath } from "url"
3
-
4
- const __filename = fileURLToPath(import.meta.url)
5
-
6
- export async function createCypressSupportFileContents(): Promise<string> {
7
- // this is the interface of tui-sandbox as far as cypress in the user's
8
- // application is concerned
9
- let text = `/// <reference types="cypress" />
10
- //
11
- // This file is autogenerated by tui-sandbox. Do not edit it directly.
12
- //
13
- import type {
14
- BrowserTerminalSettings,
15
- GenericNeovimBrowserApi,
16
- GenericTerminalBrowserApi,
17
- } from "@tui-sandbox/library/dist/src/browser/neovim-client"
18
- import type {
19
- AllKeys,
20
- BlockingShellCommandOutput,
21
- RunExCommandOutput,
22
- RunLuaCodeOutput,
23
- StartNeovimGenericArguments,
24
- TestDirectory,
25
- } from "@tui-sandbox/library/dist/src/server/types"
26
- import type { MyNeovimConfigModification } from "@tui-sandbox/library/src/client/MyNeovimConfigModification"
27
- import type {
28
- ExCommandClientInput,
29
- LuaCodeClientInput,
30
- PollLuaCodeClientInput,
31
- RunLuaFileClientInput,
32
- } from "@tui-sandbox/library/src/server/applications/neovim/neovimRouter"
33
- import type { StartTerminalGenericArguments } from "@tui-sandbox/library/src/server/applications/terminal/TerminalTestApplication"
34
- import type { BlockingCommandClientInput } from "@tui-sandbox/library/src/server/blockingCommandInputSchema"
35
- import type { OverrideProperties } from "type-fest"
36
- import type { MyNeovimAppName, MyTestDirectory, MyTestDirectoryFile } from "../../MyTestDirectory"
37
-
38
- export type TerminalTestApplicationContext = {
39
- /** Types text into the terminal, making the terminal application receive the
40
- * keystrokes as input. Requires the application to be running. */
41
- typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): void
42
-
43
- /** Runs a shell command in a blocking manner, waiting for the command to
44
- * finish before returning. Requires the terminal to be running. */
45
- runBlockingShellCommand(input: MyBlockingCommandClientInput): Cypress.Chainable<BlockingShellCommandOutput>
46
-
47
- /** The test directory, providing type-safe access to its file and directory structure */
48
- dir: TestDirectory<MyTestDirectory>
49
- }
50
-
51
- /** The api that can be used in tests after a Neovim instance has been started. */
52
- export type NeovimContext = {
53
- /** Types text into the terminal, making the terminal application receive
54
- * the keystrokes as input. Requires neovim to be running. */
55
- typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): void
56
-
57
- /** Runs a shell command in a blocking manner, waiting for the command to
58
- * finish before returning. Requires neovim to be running. */
59
- runBlockingShellCommand(input: MyBlockingCommandClientInput): Cypress.Chainable<BlockingShellCommandOutput>
60
-
61
- /** Runs a shell command in a blocking manner, waiting for the command to
62
- * finish before returning. Requires neovim to be running. */
63
- runLuaCode(input: LuaCodeClientInput): Cypress.Chainable<RunLuaCodeOutput>
64
-
65
- /** Runs a Lua file in neovim after it has started. Can be used to keep
66
- * complex lua logic in a separate file, still being able to run it after
67
- * startup. This way additional tools like lua LSP servers, linters, etc. can
68
- * be used to ensure the code is correct.
69
- */
70
- doFile(input: MyRunLuaFileClientInput): Cypress.Chainable<RunExCommandOutput>
71
-
72
- /**
73
- * Like runLuaCode, but waits until the given code (maybe using lua's return
74
- * assert()) does not raise an error, and returns the first successful result.
75
- *
76
- * Useful for waiting until Neovim's internal state has changed in a way that
77
- * means the test can continue executing. This can avoid timing issues that are
78
- * otherwise hard to catch.
79
- */
80
- waitForLuaCode(input: PollLuaCodeClientInput): Cypress.Chainable<RunLuaCodeOutput>
81
-
82
- /** Run an ex command in neovim.
83
- * @example "echo expand('%:.')" current file, relative to the cwd
84
- */
85
- runExCommand(input: ExCommandClientInput): Cypress.Chainable<RunExCommandOutput>
86
-
87
- /** The test directory, providing type-safe access to its file and directory structure */
88
- dir: TestDirectory<MyTestDirectory>
89
- }
90
-
91
- /** Arguments for starting the neovim server. They are built based on your test
92
- * environment in a type safe manner. */
93
- export type MyStartNeovimServerArguments = OverrideProperties<
94
- StartNeovimGenericArguments,
95
- {
96
- NVIM_APPNAME?: MyNeovimAppName
97
- filename?: MyTestDirectoryFile | { openInVerticalSplits: MyTestDirectoryFile[] }
98
- startupScriptModifications?: Array<MyNeovimConfigModification<MyTestDirectoryFile>>
99
- }
100
- >
101
-
102
- export type MyRunLuaFileClientInput = OverrideProperties<RunLuaFileClientInput, { luaFile: MyTestDirectoryFile }>
103
-
104
- Cypress.Commands.add("startNeovim", (startArguments?: MyStartNeovimServerArguments) => {
105
- cy.window().then(async win => {
106
- const underlyingNeovim: GenericNeovimBrowserApi = await win.startNeovim(
107
- startArguments as StartNeovimGenericArguments
108
- )
109
- testNeovim = underlyingNeovim
110
-
111
- // wrap everything so that Cypress can await all the commands
112
- Cypress.Commands.addAll({
113
- nvim_runBlockingShellCommand: underlyingNeovim.runBlockingShellCommand,
114
- nvim_runExCommand: underlyingNeovim.runExCommand,
115
- nvim_runLuaCode: underlyingNeovim.runLuaCode,
116
- nvim_waitForLuaCode: underlyingNeovim.waitForLuaCode,
117
- nvim_doFile: underlyingNeovim.doFile,
118
- })
119
-
120
- const api: NeovimContext = {
121
- runBlockingShellCommand(input) {
122
- return cy.nvim_runBlockingShellCommand(input)
123
- },
124
- runExCommand(input) {
125
- return cy.nvim_runExCommand(input)
126
- },
127
- runLuaCode(input) {
128
- return cy.nvim_runLuaCode(input)
129
- },
130
- doFile(input) {
131
- return cy.nvim_doFile(input)
132
- },
133
- waitForLuaCode(input) {
134
- return cy.nvim_waitForLuaCode(input)
135
- },
136
- typeIntoTerminal(text, options) {
137
- cy.typeIntoTerminal(text, options)
138
- },
139
- dir: underlyingNeovim.dir as TestDirectory<MyTestDirectory>,
140
- }
141
-
142
- return api
143
- })
144
- })
145
-
146
- Cypress.Commands.add("nvim_isRunning", () => {
147
- return cy.window().then(async _ => {
148
- return !!testNeovim
149
- })
150
- })
151
-
152
- Cypress.Commands.add("startTerminalApplication", (args: StartTerminalGenericArguments & BrowserTerminalSettings) => {
153
- cy.window().then(async win => {
154
- const terminal: GenericTerminalBrowserApi = await win.startTerminalApplication({
155
- serverSettings: {
156
- commandToRun: args.commandToRun,
157
- additionalEnvironmentVariables: args.additionalEnvironmentVariables,
158
- } satisfies AllKeys<StartTerminalGenericArguments>,
159
- browserSettings: {
160
- configureTerminal: args.configureTerminal,
161
- } satisfies AllKeys<BrowserTerminalSettings>,
162
- })
163
-
164
- Cypress.Commands.addAll({
165
- terminal_runBlockingShellCommand: terminal.runBlockingShellCommand,
166
- })
167
-
168
- const api: TerminalTestApplicationContext = {
169
- dir: terminal.dir as TestDirectory<MyTestDirectory>,
170
- runBlockingShellCommand(input) {
171
- return cy.terminal_runBlockingShellCommand(input)
172
- },
173
- typeIntoTerminal(text, options) {
174
- cy.typeIntoTerminal(text, options)
175
- },
176
- }
177
-
178
- return api
179
- })
180
- })
181
-
182
- Cypress.Commands.add("typeIntoTerminal", (text: string, options?: Partial<Cypress.TypeOptions>) => {
183
- // the syntax for keys is described here:
184
- // https://docs.cypress.io/api/commands/type
185
- cy.get("textarea").focus().type(text, options)
186
- })
187
-
188
- let testNeovim: GenericNeovimBrowserApi | undefined
189
-
190
- before(function () {
191
- // disable Cypress's default behavior of logging all XMLHttpRequests and
192
- // fetches to the Command Log
193
- // https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399?permalink_comment_id=4615046#gistcomment-4615046
194
- cy.intercept({ resourceType: /xhr|fetch/ }, { log: false })
195
- })
196
-
197
- export type MyBlockingCommandClientInput = OverrideProperties<
198
- BlockingCommandClientInput,
199
- { cwdRelative?: MyTestDirectoryFile | undefined }
200
- >
201
-
202
- declare global {
203
- namespace Cypress {
204
- interface Chainable {
205
- startNeovim(args?: MyStartNeovimServerArguments): Chainable<NeovimContext>
206
- startTerminalApplication(
207
- args: StartTerminalGenericArguments & BrowserTerminalSettings
208
- ): Chainable<TerminalTestApplicationContext>
209
-
210
- /** Types text into the terminal, making the terminal application receive
211
- * the keystrokes as input. Requires neovim to be running. */
212
- typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): Chainable<void>
213
-
214
- /** Runs a shell command in a blocking manner, waiting for the command to
215
- * finish before returning. Requires neovim to be running. */
216
- nvim_runBlockingShellCommand(input: MyBlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
217
-
218
- nvim_runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
219
- nvim_doFile(input: MyRunLuaFileClientInput): Chainable<RunExCommandOutput>
220
- nvim_waitForLuaCode(input: PollLuaCodeClientInput): Chainable<RunLuaCodeOutput>
221
-
222
- /** Run an ex command in neovim.
223
- * @example "echo expand('%:.')" current file, relative to the cwd
224
- */
225
- nvim_runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
226
-
227
- /** Returns true if neovim is running. Useful to conditionally run
228
- * afterEach actions based on whether it's running. */
229
- nvim_isRunning(): Chainable<boolean>
230
-
231
- terminal_runBlockingShellCommand(input: MyBlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
232
- }
233
- }
234
- }
235
-
236
- afterEach(async () => {
237
- testNeovim = undefined
238
- })
239
- `
240
-
241
- const options = await resolveConfig(__filename)
242
- text = await format(text, { ...options, parser: "typescript" })
243
-
244
- return text
245
- }
@@ -1,69 +0,0 @@
1
- import { readFileSync, writeFileSync } from "fs"
2
- import { mkdir, stat } from "fs/promises"
3
- import { describe, expect, it, vi } from "vitest"
4
- import { createCypressSupportFileContents } from "./contents.js"
5
- import type { CreateCypressSupportFileResult } from "./createCypressSupportFile.js"
6
- import { createCypressSupportFile } from "./createCypressSupportFile.js"
7
-
8
- vi.mock("fs")
9
- vi.mock("fs/promises")
10
- vi.mock("./contents.ts")
11
-
12
- const mocked = {
13
- readFileSync: vi.mocked(readFileSync),
14
- writeFileSync: vi.mocked(writeFileSync),
15
- createCypressSupportFileContents: vi.mocked(createCypressSupportFileContents),
16
- mkdir: vi.mocked(mkdir),
17
- stat: vi.mocked(stat),
18
- }
19
-
20
- describe("createCypressSupportFileContents", () => {
21
- it("should update the file if the schema has changed", async () => {
22
- mocked.readFileSync.mockImplementationOnce(() => "")
23
- mocked.writeFileSync.mockImplementationOnce(() => {
24
- //
25
- })
26
-
27
- const result = await createCypressSupportFile({
28
- cypressSupportDirectoryPath: "cypress/support",
29
- supportFileName: "tui-sandbox.ts",
30
- })
31
-
32
- expect(result).toBe("updated" satisfies CreateCypressSupportFileResult)
33
- })
34
-
35
- it("should not update the file if the schema has not changed", async () => {
36
- mocked.readFileSync.mockImplementationOnce(() => "contents")
37
- mocked.writeFileSync.mockImplementationOnce(() => {
38
- //
39
- })
40
- mocked.createCypressSupportFileContents.mockImplementationOnce(async () => "contents")
41
-
42
- const result = await createCypressSupportFile({
43
- cypressSupportDirectoryPath: "cypress/support",
44
- supportFileName: "tui-sandbox.ts",
45
- })
46
-
47
- expect(result).toBe("did-nothing" satisfies CreateCypressSupportFileResult)
48
- })
49
-
50
- it("should create the config-modifications directory if it does not exist", async () => {
51
- // This directory is required to exist so that a type safe schema of the
52
- // neovimArguments can be built and used.
53
- mocked.readFileSync.mockImplementationOnce(() => "")
54
- mocked.writeFileSync.mockImplementationOnce(() => {
55
- //
56
- })
57
- mocked.createCypressSupportFileContents.mockImplementationOnce(async () => "contents")
58
- mocked.stat.mockRejectedValueOnce(new Error("ENOENT"))
59
-
60
- const result = await createCypressSupportFile({
61
- cypressSupportDirectoryPath: "cypress/support",
62
- supportFileName: "tui-sandbox.ts",
63
- })
64
-
65
- expect(result).toBe("updated" satisfies CreateCypressSupportFileResult)
66
- expect(mocked.mkdir).toHaveBeenCalledWith("cypress/support/config-modifications", { recursive: true })
67
- expect(mocked.mkdir).toHaveBeenCalledTimes(1)
68
- })
69
- })
@@ -1,56 +0,0 @@
1
- import { readFileSync, writeFileSync } from "fs"
2
- import { mkdir, stat } from "fs/promises"
3
- import path from "path"
4
- import { debuglog } from "util"
5
- import { createCypressSupportFileContents } from "./contents.js"
6
-
7
- const log = debuglog("tui-sandbox.dirtree")
8
-
9
- export type CreateCypressSupportFileArgs = {
10
- cypressSupportDirectoryPath: string
11
- supportFileName: string
12
- }
13
-
14
- export type CreateCypressSupportFileResult = "updated" | "did-nothing"
15
-
16
- /**
17
- * This is the interface of tui-sandbox as far as cypress in the user's
18
- * application is concerned. It needs to be checked for changes once per
19
- * tui-sandbox version.
20
- */
21
- export async function createCypressSupportFile({
22
- cypressSupportDirectoryPath,
23
- supportFileName,
24
- }: CreateCypressSupportFileArgs): Promise<CreateCypressSupportFileResult> {
25
- // create config-modifications directory if it doesn't exist
26
- const configModificationsDirectoryPath = path.join(cypressSupportDirectoryPath, "config-modifications")
27
- try {
28
- await stat(configModificationsDirectoryPath)
29
- } catch {
30
- console.info(
31
- `Creating config-modifications directory at ${configModificationsDirectoryPath}. You can put Neovim startup scripts into this directory, and load them when starting your Neovim test.`
32
- )
33
- await mkdir(configModificationsDirectoryPath, { recursive: true })
34
- }
35
-
36
- const text = await createCypressSupportFileContents()
37
-
38
- let oldSchema = ""
39
- const outputFilePath = path.join(cypressSupportDirectoryPath, supportFileName)
40
- try {
41
- oldSchema = readFileSync(outputFilePath, "utf-8")
42
- } catch {
43
- console.warn(`No existing cypress support file found at ${outputFilePath}`)
44
- }
45
-
46
- if (oldSchema !== text) {
47
- // it's important to not write the file if the schema hasn't changed
48
- // because file watchers will trigger on file changes and we don't want to
49
- // trigger a build if the schema hasn't changed
50
- log(`🪛 Writing cypress support file to ${outputFilePath}`)
51
- writeFileSync(outputFilePath, text)
52
- return "updated"
53
- } else {
54
- return "did-nothing"
55
- }
56
- }