@tui-sandbox/library 2.0.2 → 2.2.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 (56) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/src/client/neovim-client.d.ts +2 -1
  3. package/dist/src/client/neovim-client.js +12 -3
  4. package/dist/src/server/TestServer.d.ts +1 -1
  5. package/dist/src/server/TestServer.js +15 -24
  6. package/dist/src/server/connection/trpc.d.ts +7 -15
  7. package/dist/src/server/connection/trpc.js +0 -3
  8. package/dist/src/server/neovim/NeovimApplication.d.ts +3 -2
  9. package/dist/src/server/neovim/NeovimApplication.js +21 -13
  10. package/dist/src/server/neovim/environment/createTempDir.test.js +1 -0
  11. package/dist/src/server/neovim/index.d.ts +1 -2
  12. package/dist/src/server/neovim/index.js +15 -21
  13. package/dist/src/server/server.d.ts +8 -7
  14. package/dist/src/server/server.js +9 -3
  15. package/dist/src/server/server.test.d.ts +1 -0
  16. package/dist/src/server/server.test.js +23 -0
  17. package/dist/src/server/updateTestdirectorySchemaFile.d.ts +2 -1
  18. package/dist/src/server/updateTestdirectorySchemaFile.js +4 -0
  19. package/dist/src/server/updateTestdirectorySchemaFile.test.d.ts +1 -0
  20. package/dist/src/server/updateTestdirectorySchemaFile.test.js +34 -0
  21. package/dist/src/server/utilities/DisposableSingleApplication.d.ts +6 -8
  22. package/dist/src/server/utilities/DisposableSingleApplication.js +9 -9
  23. package/dist/src/server/utilities/DisposableSingleApplication.test.d.ts +1 -0
  24. package/dist/src/server/utilities/DisposableSingleApplication.test.js +55 -0
  25. package/dist/src/server/utilities/TerminalApplication.d.ts +2 -1
  26. package/dist/src/server/utilities/applicationAvailable.d.ts +1 -0
  27. package/dist/src/server/utilities/applicationAvailable.js +4 -0
  28. package/dist/src/server/utilities/applicationAvailable.test.d.ts +1 -0
  29. package/dist/src/server/utilities/applicationAvailable.test.js +12 -0
  30. package/dist/src/server/utilities/generator.d.ts +2 -0
  31. package/dist/src/server/utilities/generator.js +8 -0
  32. package/dist/src/server/utilities/generator.test.d.ts +1 -0
  33. package/dist/src/server/utilities/generator.test.js +41 -0
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/dist/vitest.config.d.ts +2 -0
  36. package/dist/vitest.config.js +8 -0
  37. package/package.json +13 -10
  38. package/src/client/neovim-client.ts +14 -4
  39. package/src/server/TestServer.ts +17 -25
  40. package/src/server/connection/trpc.ts +1 -15
  41. package/src/server/neovim/NeovimApplication.ts +24 -14
  42. package/src/server/neovim/environment/createTempDir.test.ts +2 -0
  43. package/src/server/neovim/index.ts +25 -27
  44. package/src/server/server.test.ts +34 -0
  45. package/src/server/server.ts +11 -4
  46. package/src/server/updateTestdirectorySchemaFile.test.ts +43 -0
  47. package/src/server/updateTestdirectorySchemaFile.ts +7 -2
  48. package/src/server/utilities/DisposableSingleApplication.test.ts +70 -0
  49. package/src/server/utilities/DisposableSingleApplication.ts +17 -12
  50. package/src/server/utilities/TerminalApplication.ts +2 -1
  51. package/src/server/utilities/applicationAvailable.test.ts +14 -0
  52. package/src/server/utilities/applicationAvailable.ts +5 -0
  53. package/src/server/utilities/generator.test.ts +49 -0
  54. package/src/server/utilities/generator.ts +13 -0
  55. package/tsconfig.json +2 -2
  56. package/vitest.config.ts +9 -0
@@ -1,6 +1,7 @@
1
1
  import type winston from "winston";
2
2
  import type { ITerminalDimensions } from "@xterm/addon-fit";
3
- export declare class TerminalApplication {
3
+ import type { StartableApplication } from "./DisposableSingleApplication";
4
+ export declare class TerminalApplication implements StartableApplication {
4
5
  private readonly subProcess;
5
6
  readonly onStdoutOrStderr: (data: string) => void;
6
7
  readonly processId: number;
@@ -0,0 +1 @@
1
+ export declare function applicationAvailable(command: string): Promise<string | null>;
@@ -0,0 +1,4 @@
1
+ import commandExists from "command-exists";
2
+ export async function applicationAvailable(command) {
3
+ return commandExists(command);
4
+ }
@@ -0,0 +1,12 @@
1
+ import { applicationAvailable } from "./applicationAvailable";
2
+ describe("sanity checks for mocking", () => {
3
+ // because it makes no sense to mock the actual implementation if we don't
4
+ // know what it does in the current version, we better check what it's
5
+ // expected to do
6
+ it("can find neovim using the actual implementation", async () => {
7
+ await expect(applicationAvailable("nvim")).resolves.toBe("nvim");
8
+ });
9
+ it("complains when a nonexistent command is checked", async () => {
10
+ await expect(applicationAvailable("thisCommandDoesNotExist")).rejects.toBe(null);
11
+ });
12
+ });
@@ -0,0 +1,2 @@
1
+ import type EventEmitter from "events";
2
+ export declare function convertEventEmitterToAsyncGenerator(emitter: EventEmitter, eventName: string): AsyncGenerator<string, void, unknown>;
@@ -0,0 +1,8 @@
1
+ export async function* convertEventEmitterToAsyncGenerator(emitter, eventName) {
2
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3
+ while (true) {
4
+ yield await new Promise(resolve => {
5
+ emitter.once(eventName, resolve);
6
+ });
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { EventEmitter } from "stream";
2
+ import { convertEventEmitterToAsyncGenerator } from "./generator";
3
+ describe("when a listener is attached", () => {
4
+ it("forwards events from an EventEmitter to an async generator", async () => {
5
+ const eventEmitter = new EventEmitter();
6
+ const generator = convertEventEmitterToAsyncGenerator(eventEmitter, "test");
7
+ {
8
+ const promise = generator.next();
9
+ eventEmitter.emit("test", "message");
10
+ expect(await promise).toMatchInlineSnapshot(`
11
+ {
12
+ "done": false,
13
+ "value": "message",
14
+ }
15
+ `);
16
+ const promise2 = generator.next();
17
+ eventEmitter.emit("test", "message2");
18
+ expect(await promise2).toMatchInlineSnapshot(`
19
+ {
20
+ "done": false,
21
+ "value": "message2",
22
+ }
23
+ `);
24
+ }
25
+ });
26
+ });
27
+ describe("when no listener is attached, messages are lost permanently", () => {
28
+ it("does not resend lost events after a subscriber attaches", async () => {
29
+ const eventEmitter = new EventEmitter();
30
+ eventEmitter.emit("test", "this message should be lost");
31
+ const generator = convertEventEmitterToAsyncGenerator(eventEmitter, "test");
32
+ const promise = generator.next();
33
+ eventEmitter.emit("test", "new message that will be received");
34
+ expect(await promise).toMatchInlineSnapshot(`
35
+ {
36
+ "done": false,
37
+ "value": "new message that will be received",
38
+ }
39
+ `);
40
+ });
41
+ });