@tui-sandbox/library 11.3.2 → 11.4.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.
- package/CHANGELOG.md +14 -0
- package/dist/src/client/MyNeovimConfigModification.test.js +1 -0
- package/dist/src/client/MyNeovimConfigModification.test.js.map +1 -1
- package/dist/src/client/color-utilities.test.js +1 -0
- package/dist/src/client/color-utilities.test.js.map +1 -1
- package/dist/src/client/cypress-assertions.d.ts +14 -0
- package/dist/src/client/cypress-assertions.js +32 -0
- package/dist/src/client/cypress-assertions.js.map +1 -0
- package/dist/src/client/index.d.ts +1 -0
- package/dist/src/client/index.js +1 -0
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/scripts/parseArguments.d.ts +9 -0
- package/dist/src/scripts/parseArguments.js +38 -0
- package/dist/src/scripts/parseArguments.js.map +1 -0
- package/dist/src/scripts/parseArguments.test.d.ts +1 -0
- package/dist/src/scripts/parseArguments.test.js +20 -0
- package/dist/src/scripts/parseArguments.test.js.map +1 -0
- package/dist/src/scripts/tui.js +37 -36
- package/dist/src/scripts/tui.js.map +1 -1
- package/dist/src/server/applications/neovim/NeovimJavascriptApiClient.test.js +1 -0
- package/dist/src/server/applications/neovim/NeovimJavascriptApiClient.test.js.map +1 -1
- package/dist/src/server/applications/neovim/environment/createTempDir.test.js +1 -1
- package/dist/src/server/applications/neovim/environment/createTempDir.test.js.map +1 -1
- package/dist/src/server/applications/neovim/prepareNewTestDirectory.test.js +1 -0
- package/dist/src/server/applications/neovim/prepareNewTestDirectory.test.js.map +1 -1
- package/dist/src/server/applications/terminal/runBlockingShellCommand.test.js +1 -0
- package/dist/src/server/applications/terminal/runBlockingShellCommand.test.js.map +1 -1
- package/dist/src/server/blockingCommandInputSchema.test.js +1 -0
- package/dist/src/server/blockingCommandInputSchema.test.js.map +1 -1
- package/dist/src/server/cypress-support/createCypressSupportFile.test.js +1 -0
- package/dist/src/server/cypress-support/createCypressSupportFile.test.js.map +1 -1
- package/dist/src/server/updateTestdirectorySchemaFile.test.js +1 -0
- package/dist/src/server/updateTestdirectorySchemaFile.test.js.map +1 -1
- package/dist/src/server/utilities/DisposableSingleApplication.test.js +1 -0
- package/dist/src/server/utilities/DisposableSingleApplication.test.js.map +1 -1
- package/dist/src/server/utilities/generator.test.js +1 -0
- package/dist/src/server/utilities/generator.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/client/MyNeovimConfigModification.test.ts +1 -0
- package/src/client/color-utilities.test.ts +1 -0
- package/src/client/cypress-assertions.ts +37 -0
- package/src/client/index.ts +1 -0
- package/src/scripts/parseArguments.test.ts +23 -0
- package/src/scripts/parseArguments.ts +48 -0
- package/src/scripts/tui.ts +35 -39
- package/src/server/applications/neovim/NeovimJavascriptApiClient.test.ts +1 -0
- package/src/server/applications/neovim/environment/createTempDir.test.ts +1 -1
- package/src/server/applications/neovim/prepareNewTestDirectory.test.ts +1 -0
- package/src/server/applications/terminal/runBlockingShellCommand.test.ts +1 -0
- package/src/server/blockingCommandInputSchema.test.ts +1 -0
- package/src/server/cypress-support/createCypressSupportFile.test.ts +1 -0
- package/src/server/updateTestdirectorySchemaFile.test.ts +1 -0
- package/src/server/utilities/DisposableSingleApplication.test.ts +1 -0
- package/src/server/utilities/generator.test.ts +1 -0
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tui-sandbox/library",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/mikavilpas/tui-sandbox"
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@xterm/addon-unicode11": "0.8.0",
|
|
19
19
|
"@xterm/xterm": "5.5.0",
|
|
20
20
|
"cors": "2.8.5",
|
|
21
|
+
"cypress": "14.5.3",
|
|
21
22
|
"dree": "5.1.5",
|
|
22
23
|
"express": "5.1.0",
|
|
23
24
|
"neovim": "5.3.0",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
/** Problem: cypress provides the `contains` method, but it only checks the
|
|
4
|
+
* first match on the page.
|
|
5
|
+
*
|
|
6
|
+
* Solution: we need to check all elements on the page and filter them
|
|
7
|
+
* by the text we are looking for. Then we can check if the background
|
|
8
|
+
* color of the element is the same as the one we are looking for.
|
|
9
|
+
*
|
|
10
|
+
* Limitation: text spanning multiple lines will not be detected.
|
|
11
|
+
*/
|
|
12
|
+
export function textIsVisibleWithColor(text: string, color: string): Cypress.Chainable<JQuery> {
|
|
13
|
+
return cy.get("div.xterm-rows span").and($spans => {
|
|
14
|
+
const matching = $spans.filter((_, el) => !!el.textContent.includes(text))
|
|
15
|
+
|
|
16
|
+
const colors = matching.map((_, el) => {
|
|
17
|
+
return window.getComputedStyle(el).color
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
expect(JSON.stringify(colors.toArray())).to.contain(color)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Like `textIsVisibleWithColor`, but checks the background color instead
|
|
25
|
+
* of the text color.
|
|
26
|
+
*/
|
|
27
|
+
export function textIsVisibleWithBackgroundColor(text: string, color: string): Cypress.Chainable<JQuery> {
|
|
28
|
+
return cy.get("div.xterm-rows span").and($spans => {
|
|
29
|
+
const matching = $spans.filter((_, el) => !!el.textContent.includes(text))
|
|
30
|
+
|
|
31
|
+
const colors = matching.map((_, el) => {
|
|
32
|
+
return window.getComputedStyle(el).backgroundColor
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
expect(JSON.stringify(colors.toArray())).to.contain(color)
|
|
36
|
+
})
|
|
37
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// This is the public client api. Semantic versioning will be applied to this.
|
|
2
2
|
|
|
3
3
|
export { rgbify } from "./color-utilities.js"
|
|
4
|
+
export { textIsVisibleWithBackgroundColor, textIsVisibleWithColor } from "./cypress-assertions.js"
|
|
4
5
|
export { NeovimTerminalClient as TerminalClient } from "./neovim-terminal-client.js"
|
|
5
6
|
export { TerminalTerminalClient } from "./terminal-terminal-client.js"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { parseArguments } from "./parseArguments.js"
|
|
3
|
+
|
|
4
|
+
it(`can parse "neovim prepare"`, async () => {
|
|
5
|
+
expect(await parseArguments(["neovim", "prepare"])).toEqual({ action: "neovim prepare" })
|
|
6
|
+
expect(await parseArguments(["neovim", "prepare", "foo"])).toBeUndefined()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
describe("neovim exec", () => {
|
|
10
|
+
it(`can parse "neovim exec <command>"`, async () => {
|
|
11
|
+
expect(await parseArguments(["neovim", "exec", "foo"])).toEqual({ action: "neovim exec", command: "foo" })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it(`only allows one argument`, async () => {
|
|
15
|
+
expect(await parseArguments(["neovim", "exec"])).toBeUndefined()
|
|
16
|
+
expect(await parseArguments(["neovim", "exec", "foo", "bar"])).toBeUndefined()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it(`can parse "start"`, async () => {
|
|
21
|
+
expect(await parseArguments(["start"])).toEqual({ action: "start" })
|
|
22
|
+
expect(await parseArguments(["start", "foo"])).toBeUndefined()
|
|
23
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "assert"
|
|
2
|
+
import * as z from "zod"
|
|
3
|
+
|
|
4
|
+
export const parseArguments = async (args: string[]): Promise<ParseArgumentsResult | undefined> => {
|
|
5
|
+
{
|
|
6
|
+
// tui neovim prepare
|
|
7
|
+
const schema = z.tuple([z.literal("neovim"), z.literal("prepare")])
|
|
8
|
+
const prepareArguments = schema.safeParse(args)
|
|
9
|
+
if (prepareArguments.success) {
|
|
10
|
+
return {
|
|
11
|
+
action: "neovim prepare",
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
// tui neovim exec <command> [<args>...]
|
|
18
|
+
const schema = z.tuple([z.literal("neovim"), z.literal("exec"), z.string()])
|
|
19
|
+
const execArguments = schema.safeParse(args)
|
|
20
|
+
if (execArguments.success) {
|
|
21
|
+
const command = execArguments.data.at(2)
|
|
22
|
+
assert(command, "No command provided for neovim exec")
|
|
23
|
+
return {
|
|
24
|
+
action: "neovim exec",
|
|
25
|
+
command,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
{
|
|
31
|
+
// tui start
|
|
32
|
+
const schema = z.tuple([z.literal("start")])
|
|
33
|
+
const result = schema.safeParse(args)
|
|
34
|
+
if (result.success) {
|
|
35
|
+
return {
|
|
36
|
+
action: "start",
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ParseArgumentsResult =
|
|
43
|
+
| { action: "neovim prepare" }
|
|
44
|
+
| {
|
|
45
|
+
action: "neovim exec"
|
|
46
|
+
command: string
|
|
47
|
+
}
|
|
48
|
+
| { action: "start" }
|
package/src/scripts/tui.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import assert from "node:assert"
|
|
2
1
|
import path from "node:path"
|
|
3
2
|
import { installDependencies } from "../server/applications/neovim/api.js"
|
|
4
3
|
import type { StdoutOrStderrMessage } from "../server/applications/neovim/NeovimApplication.js"
|
|
@@ -7,6 +6,7 @@ import { prepareNewTestDirectory } from "../server/applications/neovim/prepareNe
|
|
|
7
6
|
import { createCypressSupportFile } from "../server/cypress-support/createCypressSupportFile.js"
|
|
8
7
|
import type { TestServerConfig } from "../server/index.js"
|
|
9
8
|
import { startTestServer, updateTestdirectorySchemaFile } from "../server/index.js"
|
|
9
|
+
import { parseArguments } from "./parseArguments.js"
|
|
10
10
|
|
|
11
11
|
//
|
|
12
12
|
// This is the main entrypoint to tui-sandbox
|
|
@@ -28,8 +28,10 @@ const config = {
|
|
|
28
28
|
// the arguments passed to this script start at index 2
|
|
29
29
|
const args = process.argv.slice(2)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const command = await parseArguments(args)
|
|
32
|
+
|
|
33
|
+
switch (command?.action) {
|
|
34
|
+
case "neovim prepare": {
|
|
33
35
|
const NVIM_APPNAME = process.env["NVIM_APPNAME"]
|
|
34
36
|
console.log(`🚀 Installing neovim dependencies${NVIM_APPNAME ? ` for NVIM_APPNAME=${NVIM_APPNAME}` : ""}...`)
|
|
35
37
|
await installDependencies(
|
|
@@ -42,15 +44,7 @@ if (args[0] === "neovim") {
|
|
|
42
44
|
})
|
|
43
45
|
process.exit(0)
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
if (!(args[1] === "exec" && args.length === 3)) {
|
|
47
|
-
showUsageAndExit()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const command = args[2]
|
|
51
|
-
assert(command, "No command provided")
|
|
52
|
-
|
|
53
|
-
{
|
|
47
|
+
case "neovim exec": {
|
|
54
48
|
// automatically dispose of the neovim instance when done
|
|
55
49
|
await using app = new NeovimApplication(config.directories.testEnvironmentPath)
|
|
56
50
|
app.events.on("stdout" satisfies StdoutOrStderrMessage, data => {
|
|
@@ -61,41 +55,42 @@ if (args[0] === "neovim") {
|
|
|
61
55
|
testDirectory,
|
|
62
56
|
{
|
|
63
57
|
filename: "empty.txt",
|
|
64
|
-
headlessCmd: command,
|
|
58
|
+
headlessCmd: command.command,
|
|
65
59
|
NVIM_APPNAME: process.env["NVIM_APPNAME"],
|
|
66
60
|
},
|
|
67
61
|
{ cols: 80, rows: 24 }
|
|
68
62
|
)
|
|
69
63
|
await app.application.untilExit()
|
|
64
|
+
break
|
|
70
65
|
}
|
|
66
|
+
case "start": {
|
|
67
|
+
try {
|
|
68
|
+
await createCypressSupportFile({
|
|
69
|
+
cypressSupportDirectoryPath: path.join(cwd, "cypress", "support"),
|
|
70
|
+
supportFileName: "tui-sandbox.ts",
|
|
71
|
+
})
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error("Failed to createCypressSupportFile", e)
|
|
74
|
+
}
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
console.log(`🚀 Starting test server in ${cwd} - this should be the root of your integration-tests directory 🤞🏻`)
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
await createCypressSupportFile({
|
|
82
|
-
cypressSupportDirectoryPath: path.join(cwd, "cypress", "support"),
|
|
83
|
-
supportFileName: "tui-sandbox.ts",
|
|
84
|
-
})
|
|
85
|
-
} catch (e) {
|
|
86
|
-
console.error("Failed to createCypressSupportFile", e)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await updateTestdirectorySchemaFile(config.directories)
|
|
91
|
-
} catch (e) {
|
|
92
|
-
console.error("Failed to updateTestdirectorySchemaFile", e)
|
|
93
|
-
}
|
|
76
|
+
try {
|
|
77
|
+
await updateTestdirectorySchemaFile(config.directories)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error("Failed to updateTestdirectorySchemaFile", e)
|
|
80
|
+
}
|
|
94
81
|
|
|
95
|
-
try {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
82
|
+
try {
|
|
83
|
+
console.log(`🚀 Starting test server in ${cwd} - this should be the root of your integration-tests directory 🤞🏻`)
|
|
84
|
+
await startTestServer(config)
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error("Failed to startTestServer", e)
|
|
87
|
+
}
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
91
|
+
command satisfies undefined
|
|
92
|
+
showUsageAndExit()
|
|
93
|
+
}
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
function showUsageAndExit() {
|
|
@@ -105,6 +100,7 @@ function showUsageAndExit() {
|
|
|
105
100
|
`Usage (pick one):`,
|
|
106
101
|
` tui start`,
|
|
107
102
|
` tui neovim exec '<ex-command>'`,
|
|
103
|
+
` tui neovim prepare`,
|
|
108
104
|
].join("\n")
|
|
109
105
|
)
|
|
110
106
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { access } from "fs/promises"
|
|
2
2
|
import { attach } from "neovim"
|
|
3
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest"
|
|
3
4
|
import type { PollingInterval } from "./NeovimJavascriptApiClient.js"
|
|
4
5
|
import { connectNeovimApi } from "./NeovimJavascriptApiClient.js"
|
|
5
6
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rm } from "fs/promises"
|
|
2
2
|
import path from "path"
|
|
3
|
+
import { assert, describe, expect, it } from "vitest"
|
|
3
4
|
import { prepareNewTestDirectory } from "./prepareNewTestDirectory.js"
|
|
4
5
|
|
|
5
6
|
describe("prepareNewTestDirectory when the testEnvironmentPath does not exist", () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from "fs"
|
|
2
2
|
import { mkdir, stat } from "fs/promises"
|
|
3
|
+
import { describe, expect, it, vi } from "vitest"
|
|
3
4
|
import { createCypressSupportFileContents } from "./contents.js"
|
|
4
5
|
import type { CreateCypressSupportFileResult } from "./createCypressSupportFile.js"
|
|
5
6
|
import { createCypressSupportFile } from "./createCypressSupportFile.js"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from "fs"
|
|
2
|
+
import { describe, expect, it, vi } from "vitest"
|
|
2
3
|
import { buildTestDirectorySchema } from "./dirtree/index.js"
|
|
3
4
|
import type { UpdateTestdirectorySchemaFileResult } from "./updateTestdirectorySchemaFile.js"
|
|
4
5
|
import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js"
|