@tui-sandbox/library 3.0.0 → 4.0.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 +11 -0
- package/dist/browser/assets/DejaVuSansMNerdFontMono-Regular-CRJgiq0O.ttf +0 -0
- package/dist/browser/assets/index-Bf37MeF1.css +32 -0
- package/dist/browser/assets/index-hNatvKyq.js +9 -0
- package/dist/browser/index.html +12 -0
- package/dist/src/browser/neovim-client.d.ts +7 -0
- package/dist/src/browser/neovim-client.js +14 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/neovim-client.js +4 -4
- package/dist/src/client/websocket-client.js +1 -1
- package/dist/src/scripts/tui.d.ts +1 -0
- package/dist/src/scripts/tui.js +25 -0
- package/dist/src/server/TestServer.d.ts +6 -4
- package/dist/src/server/TestServer.js +35 -11
- package/dist/src/server/dirtree/index.js +1 -1
- package/dist/src/server/dirtree/index.test.js +2 -2
- package/dist/src/server/index.d.ts +4 -4
- package/dist/src/server/index.js +3 -3
- package/dist/src/server/neovim/NeovimApplication.d.ts +2 -2
- package/dist/src/server/neovim/NeovimApplication.js +3 -3
- package/dist/src/server/neovim/NeovimJavascriptApiClient.d.ts +1 -1
- package/dist/src/server/neovim/NeovimJavascriptApiClient.js +1 -1
- package/dist/src/server/neovim/NeovimJavascriptApiClient.test.js +1 -1
- package/dist/src/server/neovim/environment/createTempDir.d.ts +2 -2
- package/dist/src/server/neovim/environment/createTempDir.js +2 -2
- package/dist/src/server/neovim/environment/createTempDir.test.js +75 -11
- package/dist/src/server/neovim/index.d.ts +4 -4
- package/dist/src/server/neovim/index.js +3 -3
- package/dist/src/server/server.d.ts +4 -3
- package/dist/src/server/server.js +80 -12
- package/dist/src/server/server.test.js +2 -2
- package/dist/src/server/updateTestdirectorySchemaFile.d.ts +0 -1
- package/dist/src/server/updateTestdirectorySchemaFile.js +1 -2
- package/dist/src/server/updateTestdirectorySchemaFile.test.js +2 -2
- package/dist/src/server/utilities/DisposableSingleApplication.d.ts +1 -1
- package/dist/src/server/utilities/DisposableSingleApplication.test.js +1 -1
- package/dist/src/server/utilities/TerminalApplication.d.ts +1 -1
- package/dist/src/server/utilities/applicationAvailable.test.js +1 -1
- package/dist/src/server/utilities/generator.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.html +11 -0
- package/package.json +14 -4
- package/src/browser/neovim-client.ts +26 -0
- package/src/client/index.ts +1 -1
- package/src/client/neovim-client.ts +4 -4
- package/src/client/websocket-client.ts +1 -1
- package/src/scripts/tui.ts +29 -0
- package/src/server/TestServer.ts +50 -15
- package/src/server/dirtree/index.test.ts +2 -2
- package/src/server/dirtree/index.ts +1 -1
- package/src/server/index.ts +4 -5
- package/src/server/neovim/NeovimApplication.ts +5 -5
- package/src/server/neovim/NeovimJavascriptApiClient.test.ts +2 -2
- package/src/server/neovim/NeovimJavascriptApiClient.ts +1 -1
- package/src/server/neovim/environment/createTempDir.test.ts +2 -2
- package/src/server/neovim/environment/createTempDir.ts +4 -4
- package/src/server/neovim/index.ts +7 -7
- package/src/server/server.test.ts +2 -2
- package/src/server/server.ts +10 -7
- package/src/server/updateTestdirectorySchemaFile.test.ts +3 -3
- package/src/server/updateTestdirectorySchemaFile.ts +1 -2
- package/src/server/utilities/DisposableSingleApplication.test.ts +2 -2
- package/src/server/utilities/DisposableSingleApplication.ts +1 -1
- package/src/server/utilities/TerminalApplication.ts +1 -1
- package/src/server/utilities/applicationAvailable.test.ts +1 -1
- package/src/server/utilities/generator.test.ts +1 -1
- package/tsconfig.json +10 -4
- package/vite.config.js +26 -0
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/vitest.config.ts +0 -9
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>tui-sandbox integration tests</title>
|
|
6
|
+
<script type="module" crossorigin src="/assets/index-hNatvKyq.js"></script>
|
|
7
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Bf37MeF1.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StartNeovimGenericArguments } from "../server/neovim/NeovimApplication.js";
|
|
2
|
+
import type { TestDirectory } from "../server/types.js";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
startNeovim(startArguments?: StartNeovimGenericArguments): Promise<TestDirectory>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NeovimClient } from "../client/index.js";
|
|
2
|
+
const app = document.querySelector("#app");
|
|
3
|
+
if (!app) {
|
|
4
|
+
throw new Error("No app element found");
|
|
5
|
+
}
|
|
6
|
+
const client = new NeovimClient(app);
|
|
7
|
+
/** Entrypoint for the test runner (cypress) */
|
|
8
|
+
window.startNeovim = async function (startArgs) {
|
|
9
|
+
const testDirectory = await client.startNeovim({
|
|
10
|
+
filename: startArgs?.filename ?? "initial-file.txt",
|
|
11
|
+
startupScriptModifications: startArgs?.startupScriptModifications ?? [],
|
|
12
|
+
});
|
|
13
|
+
return testDirectory;
|
|
14
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { NeovimClient } from "./neovim-client";
|
|
1
|
+
export { NeovimClient } from "./neovim-client.js";
|
package/dist/src/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This is the public client api. Semantic versioning will be applied to this.
|
|
2
|
-
export { NeovimClient } from "./neovim-client";
|
|
2
|
+
export { NeovimClient } from "./neovim-client.js";
|
|
@@ -13,10 +13,10 @@ export class NeovimClient {
|
|
|
13
13
|
splitLink({
|
|
14
14
|
condition: operation => operation.type === "subscription",
|
|
15
15
|
true: unstable_httpSubscriptionLink({
|
|
16
|
-
url: "
|
|
16
|
+
url: "/trpc",
|
|
17
17
|
}),
|
|
18
18
|
false: httpBatchLink({
|
|
19
|
-
url: "
|
|
19
|
+
url: "/trpc",
|
|
20
20
|
}),
|
|
21
21
|
}),
|
|
22
22
|
],
|
|
@@ -54,7 +54,7 @@ export class NeovimClient {
|
|
|
54
54
|
}
|
|
55
55
|
async startNeovim(args) {
|
|
56
56
|
await this.ready;
|
|
57
|
-
const
|
|
57
|
+
const testDirectory = await this.trpc.neovim.start.mutate({
|
|
58
58
|
startNeovimArguments: {
|
|
59
59
|
...args,
|
|
60
60
|
terminalDimensions: {
|
|
@@ -64,6 +64,6 @@ export class NeovimClient {
|
|
|
64
64
|
},
|
|
65
65
|
tabId: this.tabId,
|
|
66
66
|
});
|
|
67
|
-
return
|
|
67
|
+
return testDirectory;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -4,7 +4,7 @@ import { Terminal } from "@xterm/xterm";
|
|
|
4
4
|
import "@xterm/xterm/css/xterm.css";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
import "./style.css";
|
|
7
|
-
import { validateMouseEvent } from "./validateMouseEvent";
|
|
7
|
+
import { validateMouseEvent } from "./validateMouseEvent.js";
|
|
8
8
|
export function startTerminal(app, options) {
|
|
9
9
|
const terminal = new Terminal({
|
|
10
10
|
cursorBlink: false,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { startTestServer } from "../server/index.js";
|
|
4
|
+
//
|
|
5
|
+
// This is the main entrypoint to tui-sandbox
|
|
6
|
+
//
|
|
7
|
+
// the arguments passed to this script start at index 2
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
if (args[0] !== "start") {
|
|
10
|
+
throw new Error(`Usage: tui start`);
|
|
11
|
+
}
|
|
12
|
+
/** The cwd in the user's directory when they are running this script. Not the
|
|
13
|
+
* cwd of the script itself. */
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
console.log(`🚀 Starting test server in ${cwd}`);
|
|
16
|
+
await stat(path.join(cwd, "MyTestDirectory.ts"));
|
|
17
|
+
try {
|
|
18
|
+
await startTestServer({
|
|
19
|
+
testEnvironmentPath: path.join(cwd, "test-environment/"),
|
|
20
|
+
outputFilePath: path.join(cwd, "MyTestDirectory.ts"),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AnyTRPCRouter } from "@trpc/server";
|
|
2
|
-
import "
|
|
3
|
-
|
|
2
|
+
import type { TestServerConfig } from "./updateTestdirectorySchemaFile.js";
|
|
3
|
+
export type TestServerSettings = {
|
|
4
|
+
port: number;
|
|
5
|
+
};
|
|
4
6
|
export declare class TestServer {
|
|
5
|
-
private readonly
|
|
6
|
-
constructor(
|
|
7
|
+
private readonly settings;
|
|
8
|
+
constructor(settings: TestServerSettings);
|
|
7
9
|
startAndRun(appRouter: AnyTRPCRouter, config: TestServerConfig): Promise<void>;
|
|
8
10
|
}
|
|
@@ -1,31 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "core-js/proposals/async-explicit-resource-management";
|
|
1
|
+
import * as trpcExpress from "@trpc/server/adapters/express";
|
|
3
2
|
import cors from "cors";
|
|
4
3
|
import { once } from "events";
|
|
5
|
-
import
|
|
4
|
+
import express from "express";
|
|
5
|
+
import { accessSync } from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
6
11
|
export class TestServer {
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
12
|
+
settings;
|
|
13
|
+
constructor(settings) {
|
|
14
|
+
this.settings = settings;
|
|
10
15
|
}
|
|
11
16
|
async startAndRun(appRouter, config) {
|
|
12
17
|
console.log("🚀 Server starting");
|
|
13
18
|
await updateTestdirectorySchemaFile(config);
|
|
14
|
-
const
|
|
19
|
+
const app = express();
|
|
20
|
+
app.use("/trpc", trpcExpress.createExpressMiddleware({
|
|
15
21
|
router: appRouter,
|
|
16
22
|
createContext: () => ({}),
|
|
17
23
|
middleware: cors({
|
|
18
24
|
origin: "*",
|
|
19
25
|
}),
|
|
26
|
+
}));
|
|
27
|
+
{
|
|
28
|
+
const publicPath = path.resolve(__dirname, "..", "..", "browser");
|
|
29
|
+
try {
|
|
30
|
+
accessSync(publicPath);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// This is normal when developing the tui-sandbox library locally. It
|
|
34
|
+
// should always exist when using it as an npm package, however.
|
|
35
|
+
console.log(`⚠️ Warning: the tui-sandbox root contents directory is not accessible at: ${publicPath}`);
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line import-x/no-named-as-default-member
|
|
38
|
+
app.use(express.static(publicPath));
|
|
39
|
+
}
|
|
40
|
+
app.use("/ping", (_, res) => {
|
|
41
|
+
console.log("🏓 received /ping");
|
|
42
|
+
res.send("pong");
|
|
20
43
|
});
|
|
21
|
-
server.listen(this.port);
|
|
44
|
+
const server = app.listen(this.settings.port, "0.0.0.0");
|
|
22
45
|
server.on("connection", socket => {
|
|
23
|
-
|
|
46
|
+
const connectionInfo = `${socket.remoteAddress}:${socket.remotePort}`;
|
|
47
|
+
console.log(`➕➕ Connection from ${connectionInfo}`);
|
|
24
48
|
socket.once("close", () => {
|
|
25
|
-
console.log(`➖➖ Connection`);
|
|
49
|
+
console.log(`➖➖ Connection from ${connectionInfo}`);
|
|
26
50
|
});
|
|
27
51
|
});
|
|
28
|
-
console.log(`✅ Server listening on
|
|
52
|
+
console.log(`✅ Server listening on port ${this.settings.port}`);
|
|
29
53
|
await Promise.race([once(process, "SIGTERM"), once(process, "SIGINT")]);
|
|
30
54
|
console.log("Shutting down...");
|
|
31
55
|
server.close(error => {
|
|
@@ -2,7 +2,7 @@ import assert from "assert";
|
|
|
2
2
|
import { scan, Type } from "dree";
|
|
3
3
|
import { format, resolveConfig } from "prettier";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import { jsonToZod } from "./json-to-zod";
|
|
5
|
+
import { jsonToZod } from "./json-to-zod.js";
|
|
6
6
|
/** Convert a directory tree to a TypeScript type. This is useful for testing
|
|
7
7
|
* as the initial state of the test directory is fully known in tests. */
|
|
8
8
|
export function getDirectoryTree(path) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { Lazy } from "../utilities/Lazy.js";
|
|
5
|
+
import { buildSchemaForDirectoryTree, getDirectoryTree } from "./index.js";
|
|
6
6
|
describe("dirtree", () => {
|
|
7
7
|
const output = new Lazy(() => getDirectoryTree(path.join(__dirname, "..", "..", "..", "..", "integration-tests", "test-environment")));
|
|
8
8
|
it("can get a list of all the files", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
|
|
1
|
+
export { startTestServer } from "./server.js";
|
|
2
|
+
export { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js";
|
|
3
|
+
export type { TestServerConfig } from "./updateTestdirectorySchemaFile.js";
|
|
4
|
+
import "core-js/proposals/async-explicit-resource-management.js";
|
package/dist/src/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "core-js/proposals/async-explicit-resource-management";
|
|
2
1
|
// This is the public server api. Semantic versioning will be applied to this.
|
|
3
|
-
export { startTestServer } from "./server";
|
|
4
|
-
export { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile";
|
|
2
|
+
export { startTestServer } from "./server.js";
|
|
3
|
+
export { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js";
|
|
4
|
+
import "core-js/proposals/async-explicit-resource-management.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
|
-
import type { TestDirectory } from "../types";
|
|
3
|
-
import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication";
|
|
2
|
+
import type { TestDirectory } from "../types.js";
|
|
3
|
+
import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication.js";
|
|
4
4
|
export type StdoutMessage = "stdout";
|
|
5
5
|
export type StartNeovimGenericArguments = {
|
|
6
6
|
terminalDimensions: {
|
|
@@ -4,9 +4,9 @@ import EventEmitter from "events";
|
|
|
4
4
|
import { access } from "fs/promises";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication";
|
|
8
|
-
import { TerminalApplication } from "../utilities/TerminalApplication";
|
|
9
|
-
import { connectNeovimApi } from "./NeovimJavascriptApiClient";
|
|
7
|
+
import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication.js";
|
|
8
|
+
import { TerminalApplication } from "../utilities/TerminalApplication.js";
|
|
9
|
+
import { connectNeovimApi } from "./NeovimJavascriptApiClient.js";
|
|
10
10
|
export class NeovimApplication {
|
|
11
11
|
testEnvironmentPath;
|
|
12
12
|
application;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NeovimClient as NeovimApiClient } from "neovim";
|
|
2
|
-
import { Lazy } from "../utilities/Lazy";
|
|
2
|
+
import { Lazy } from "../utilities/Lazy.js";
|
|
3
3
|
export type NeovimJavascriptApiClient = NeovimApiClient;
|
|
4
4
|
export type PollingInterval = 100;
|
|
5
5
|
export declare function connectNeovimApi(socketPath: string): Lazy<Promise<NeovimJavascriptApiClient>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { access } from "fs/promises";
|
|
2
2
|
import { attach } from "neovim";
|
|
3
|
-
import { Lazy } from "../utilities/Lazy";
|
|
3
|
+
import { Lazy } from "../utilities/Lazy.js";
|
|
4
4
|
export function connectNeovimApi(socketPath) {
|
|
5
5
|
// it takes about 100ms for the socket file to be created - best make this
|
|
6
6
|
// Lazy so that we don't wait for it unnecessarily.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { access } from "fs/promises";
|
|
2
2
|
import { attach } from "neovim";
|
|
3
|
-
import { connectNeovimApi } from "./NeovimJavascriptApiClient";
|
|
3
|
+
import { connectNeovimApi } from "./NeovimJavascriptApiClient.js";
|
|
4
4
|
vi.mock("neovim");
|
|
5
5
|
vi.mock("fs/promises");
|
|
6
6
|
const mocked = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TestDirectory } from "../../types";
|
|
2
|
-
import type { TestServerConfig } from "../../updateTestdirectorySchemaFile";
|
|
1
|
+
import type { TestDirectory } from "../../types.js";
|
|
2
|
+
import type { TestServerConfig } from "../../updateTestdirectorySchemaFile.js";
|
|
3
3
|
export declare function createTempDir(config: TestServerConfig): Promise<TestDirectory>;
|
|
4
4
|
export type TestDirsPath = "testdirs";
|
|
@@ -4,8 +4,8 @@ import { Type } from "dree";
|
|
|
4
4
|
import { constants, readdirSync } from "fs";
|
|
5
5
|
import { access, mkdir, mkdtemp } from "fs/promises";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import { convertDree, getDirectoryTree } from "../../dirtree";
|
|
8
|
-
import { updateTestdirectorySchemaFile } from "../../updateTestdirectorySchemaFile";
|
|
7
|
+
import { convertDree, getDirectoryTree } from "../../dirtree/index.js";
|
|
8
|
+
import { updateTestdirectorySchemaFile } from "../../updateTestdirectorySchemaFile.js";
|
|
9
9
|
export async function createTempDir(config) {
|
|
10
10
|
try {
|
|
11
11
|
const dir = await createUniqueDirectory(config.testEnvironmentPath);
|
|
@@ -1,7 +1,59 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import fs, { rmdirSync } from "fs";
|
|
2
54
|
import nodePath from "path";
|
|
3
55
|
import { expect, it } from "vitest";
|
|
4
|
-
import { createTempDir } from "./createTempDir";
|
|
56
|
+
import { createTempDir } from "./createTempDir.js";
|
|
5
57
|
vi.spyOn(console, "log").mockImplementation(vi.fn());
|
|
6
58
|
class TempDirectory {
|
|
7
59
|
path;
|
|
@@ -17,14 +69,26 @@ class TempDirectory {
|
|
|
17
69
|
}
|
|
18
70
|
}
|
|
19
71
|
it("should create a temp dir with no contents", async () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
72
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
73
|
+
try {
|
|
74
|
+
// typically the user will want to have contents, but this should not be an error
|
|
75
|
+
const dir = __addDisposableResource(env_1, TempDirectory.create(), true);
|
|
76
|
+
const result = await createTempDir({
|
|
77
|
+
testEnvironmentPath: dir.path,
|
|
78
|
+
outputFilePath: nodePath.join(dir.path, "MyTestDirectory.ts"),
|
|
79
|
+
});
|
|
80
|
+
expect(result.contents).toEqual({});
|
|
81
|
+
expect(result.testEnvironmentPath).toEqual(dir.path);
|
|
82
|
+
expect(result.testEnvironmentPath.startsWith("test-temp-dir-")).toBeTruthy();
|
|
83
|
+
expect(result.testEnvironmentPathRelative.startsWith("testdirs")).toBeTruthy();
|
|
84
|
+
}
|
|
85
|
+
catch (e_1) {
|
|
86
|
+
env_1.error = e_1;
|
|
87
|
+
env_1.hasError = true;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
const result_1 = __disposeResources(env_1);
|
|
91
|
+
if (result_1)
|
|
92
|
+
await result_1;
|
|
93
|
+
}
|
|
30
94
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TestDirectory } from "../types";
|
|
2
|
-
import type { TestServerConfig } from "../updateTestdirectorySchemaFile";
|
|
3
|
-
import type { TabId } from "../utilities/tabId";
|
|
4
|
-
import type { StartNeovimGenericArguments } from "./NeovimApplication";
|
|
1
|
+
import type { TestDirectory } from "../types.js";
|
|
2
|
+
import type { TestServerConfig } from "../updateTestdirectorySchemaFile.js";
|
|
3
|
+
import type { TabId } from "../utilities/tabId.js";
|
|
4
|
+
import type { StartNeovimGenericArguments } from "./NeovimApplication.js";
|
|
5
5
|
export declare function onStdout(options: {
|
|
6
6
|
client: TabId;
|
|
7
7
|
}, signal: AbortSignal | undefined, testEnvironmentPath: string): Promise<AsyncGenerator<string, void, unknown>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import { convertEventEmitterToAsyncGenerator } from "../utilities/generator";
|
|
3
|
-
import { createTempDir } from "./environment/createTempDir";
|
|
4
|
-
import { NeovimApplication } from "./NeovimApplication";
|
|
2
|
+
import { convertEventEmitterToAsyncGenerator } from "../utilities/generator.js";
|
|
3
|
+
import { createTempDir } from "./environment/createTempDir.js";
|
|
4
|
+
import { NeovimApplication } from "./NeovimApplication.js";
|
|
5
5
|
const neovims = new Map();
|
|
6
6
|
export async function onStdout(options, signal, testEnvironmentPath) {
|
|
7
7
|
const tabId = options.client.tabId;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { inferRouterInputs } from "@trpc/server";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import "core-js/proposals/async-explicit-resource-management.js";
|
|
3
|
+
import { TestServer } from "./TestServer.js";
|
|
4
|
+
import type { TestServerConfig } from "./updateTestdirectorySchemaFile.js";
|
|
4
5
|
/** Stack for managing resources that need to be disposed of when the server
|
|
5
6
|
* shuts down */
|
|
6
7
|
declare const autocleanup: AsyncDisposableStack;
|
|
@@ -34,7 +35,7 @@ export declare function createAppRouter(config: TestServerConfig): Promise<impor
|
|
|
34
35
|
startupScriptModifications?: string[] | undefined;
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
output: import("./types").TestDirectory;
|
|
38
|
+
output: import("./types.js").TestDirectory;
|
|
38
39
|
}>;
|
|
39
40
|
onStdout: import("@trpc/server").TRPCSubscriptionProcedure<{
|
|
40
41
|
input: {
|
|
@@ -1,15 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
12
52
|
});
|
|
53
|
+
import "core-js/proposals/async-explicit-resource-management.js";
|
|
54
|
+
import { z } from "zod";
|
|
55
|
+
import { trpc } from "./connection/trpc.js";
|
|
56
|
+
import * as neovim from "./neovim/index.js";
|
|
57
|
+
import { TestServer } from "./TestServer.js";
|
|
58
|
+
import { applicationAvailable } from "./utilities/applicationAvailable.js";
|
|
59
|
+
import { tabIdSchema } from "./utilities/tabId.js";
|
|
13
60
|
export { autocleanup };
|
|
14
61
|
/** @private */
|
|
15
62
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
@@ -50,8 +97,29 @@ export async function createAppRouter(config) {
|
|
|
50
97
|
return appRouter;
|
|
51
98
|
}
|
|
52
99
|
export async function startTestServer(config) {
|
|
53
|
-
const testServer = new TestServer(
|
|
100
|
+
const testServer = new TestServer({
|
|
101
|
+
port: 3000,
|
|
102
|
+
});
|
|
54
103
|
const appRouter = await createAppRouter(config);
|
|
55
104
|
await testServer.startAndRun(appRouter, config);
|
|
56
105
|
return testServer;
|
|
57
106
|
}
|
|
107
|
+
var autocleanup;
|
|
108
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
109
|
+
try {
|
|
110
|
+
/** Stack for managing resources that need to be disposed of when the server
|
|
111
|
+
* shuts down */
|
|
112
|
+
autocleanup = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
|
|
113
|
+
autocleanup.defer(() => {
|
|
114
|
+
console.log("Closing any open test applications");
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch (e_1) {
|
|
118
|
+
env_1.error = e_1;
|
|
119
|
+
env_1.hasError = true;
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
const result_1 = __disposeResources(env_1);
|
|
123
|
+
if (result_1)
|
|
124
|
+
await result_1;
|
|
125
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createAppRouter } from "./server";
|
|
2
|
-
import { applicationAvailable } from "./utilities/applicationAvailable";
|
|
1
|
+
import { createAppRouter } from "./server.js";
|
|
2
|
+
import { applicationAvailable } from "./utilities/applicationAvailable.js";
|
|
3
3
|
vi.mock("./utilities/applicationAvailable");
|
|
4
4
|
const mocked = {
|
|
5
5
|
applicationAvailable: vi.mocked(applicationAvailable),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import "core-js/proposals/async-explicit-resource-management";
|
|
2
1
|
import { readFileSync, writeFileSync } from "fs";
|
|
3
|
-
import { buildTestDirectorySchema } from "./dirtree";
|
|
2
|
+
import { buildTestDirectorySchema } from "./dirtree/index.js";
|
|
4
3
|
export async function updateTestdirectorySchemaFile({ testEnvironmentPath, outputFilePath, }) {
|
|
5
4
|
const newSchema = await buildTestDirectorySchema(testEnvironmentPath);
|
|
6
5
|
let oldSchema = "";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import { buildTestDirectorySchema } from "./dirtree";
|
|
3
|
-
import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile";
|
|
2
|
+
import { buildTestDirectorySchema } from "./dirtree/index.js";
|
|
3
|
+
import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js";
|
|
4
4
|
vi.mock("fs");
|
|
5
5
|
vi.mock("./dirtree");
|
|
6
6
|
vi.spyOn(console, "log").mockImplementation(vi.fn());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TerminalApplication } from "./TerminalApplication";
|
|
1
|
+
import type { TerminalApplication } from "./TerminalApplication.js";
|
|
2
2
|
export type StartableApplication = Pick<TerminalApplication, "write" | "processId" | "killAndWait">;
|
|
3
3
|
/** A testable application that can be started, killed, and given input. For a
|
|
4
4
|
* single instance of this interface, only a single instance can be running at
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DisposableSingleApplication } from "./DisposableSingleApplication";
|
|
1
|
+
import { DisposableSingleApplication } from "./DisposableSingleApplication.js";
|
|
2
2
|
vi.spyOn(console, "log").mockImplementation(vi.fn());
|
|
3
3
|
class TestDisposableSingleApplication extends DisposableSingleApplication {
|
|
4
4
|
getApplication() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type winston from "winston";
|
|
2
2
|
import type { ITerminalDimensions } from "@xterm/addon-fit";
|
|
3
|
-
import type { StartableApplication } from "./DisposableSingleApplication";
|
|
3
|
+
import type { StartableApplication } from "./DisposableSingleApplication.js";
|
|
4
4
|
export declare class TerminalApplication implements StartableApplication {
|
|
5
5
|
private readonly subProcess;
|
|
6
6
|
readonly onStdoutOrStderr: (data: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applicationAvailable } from "./applicationAvailable";
|
|
1
|
+
import { applicationAvailable } from "./applicationAvailable.js";
|
|
2
2
|
describe("sanity checks for mocking", () => {
|
|
3
3
|
// because it makes no sense to mock the actual implementation if we don't
|
|
4
4
|
// know what it does in the current version, we better check what it's
|