@tui-sandbox/library 5.1.2 → 6.0.1

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [6.0.1](https://github.com/mikavilpas/tui-sandbox/compare/library-v6.0.0...library-v6.0.1) (2024-11-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * disable verbose cypress logging related to kbd&mouse input ([#141](https://github.com/mikavilpas/tui-sandbox/issues/141)) ([c170da2](https://github.com/mikavilpas/tui-sandbox/commit/c170da27053a292288cd915b02069e48b556caf1))
9
+
10
+ ## [6.0.0](https://github.com/mikavilpas/tui-sandbox/compare/library-v5.1.2...library-v6.0.0) (2024-11-17)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * this changes the way that cypress support bindings are generated. Previously, you had to manually create a file in your cypress/support directory. Now, the file is automatically generated for you when you run `tui start`.
16
+
17
+ ### Features
18
+
19
+ * automatically generate cypress support bindings on startup ([48cc416](https://github.com/mikavilpas/tui-sandbox/commit/48cc416dff628edbc850be4f31e7317c8a686217))
20
+
3
21
  ## [5.1.2](https://github.com/mikavilpas/tui-sandbox/compare/library-v5.1.1...library-v5.1.2) (2024-11-15)
4
22
 
5
23
 
@@ -1,6 +1,7 @@
1
1
  import { stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { startTestServer } from "../server/index.js";
3
+ import { createCypressSupportFile } from "../server/cypress-support/createCypressSupportFile.js";
4
+ import { startTestServer, updateTestdirectorySchemaFile } from "../server/index.js";
4
5
  //
5
6
  // This is the main entrypoint to tui-sandbox
6
7
  //
@@ -9,16 +10,23 @@ const args = process.argv.slice(2);
9
10
  if (args[0] !== "start") {
10
11
  throw new Error(`Usage: tui start`);
11
12
  }
13
+ const outputFileName = "MyTestDirectory.ts";
12
14
  /** The cwd in the user's directory when they are running this script. Not the
13
15
  * cwd of the script itself. */
14
16
  const cwd = process.cwd();
15
- console.log(`🚀 Starting test server in ${cwd}`);
16
- await stat(path.join(cwd, "MyTestDirectory.ts"));
17
+ console.log(`🚀 Starting test server in ${cwd} - this should be the root of your integration-tests directory 🤞🏻`);
18
+ await stat(path.join(cwd, outputFileName));
17
19
  try {
18
- await startTestServer({
20
+ const config = {
19
21
  testEnvironmentPath: path.join(cwd, "test-environment/"),
20
- outputFilePath: path.join(cwd, "MyTestDirectory.ts"),
22
+ outputFilePath: path.join(cwd, outputFileName),
23
+ };
24
+ await createCypressSupportFile({
25
+ cypressSupportDirectoryPath: path.join(cwd, "cypress", "support"),
26
+ supportFileName: "tui-sandbox.ts",
21
27
  });
28
+ await updateTestdirectorySchemaFile(config);
29
+ await startTestServer(config);
22
30
  }
23
31
  catch (e) {
24
32
  console.error(e);
@@ -1,10 +1,9 @@
1
1
  import type { AnyTRPCRouter } from "@trpc/server";
2
- import type { TestServerConfig } from "./updateTestdirectorySchemaFile.js";
3
2
  export type TestServerSettings = {
4
3
  port: number;
5
4
  };
6
5
  export declare class TestServer {
7
6
  private readonly settings;
8
7
  constructor(settings: TestServerSettings);
9
- startAndRun(appRouter: AnyTRPCRouter, config: TestServerConfig): Promise<void>;
8
+ startAndRun(appRouter: AnyTRPCRouter): Promise<void>;
10
9
  }
@@ -5,7 +5,6 @@ import express from "express";
5
5
  import { accessSync } from "fs";
6
6
  import path from "path";
7
7
  import { fileURLToPath } from "url";
8
- import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js";
9
8
  const __filename = fileURLToPath(import.meta.url);
10
9
  const __dirname = path.dirname(__filename);
11
10
  export class TestServer {
@@ -13,9 +12,8 @@ export class TestServer {
13
12
  constructor(settings) {
14
13
  this.settings = settings;
15
14
  }
16
- async startAndRun(appRouter, config) {
15
+ async startAndRun(appRouter) {
17
16
  console.log("🚀 Server starting");
18
- await updateTestdirectorySchemaFile(config);
19
17
  const app = express();
20
18
  app.use("/trpc", trpcExpress.createExpressMiddleware({
21
19
  router: appRouter,
@@ -0,0 +1 @@
1
+ export declare function createCypressSupportFileContents(): Promise<string>;
@@ -0,0 +1,67 @@
1
+ import { format, resolveConfig } from "prettier";
2
+ import { fileURLToPath } from "url";
3
+ const __filename = fileURLToPath(import.meta.url);
4
+ export async function createCypressSupportFileContents() {
5
+ // this is the interface of tui-sandbox as far as cypress in the user's
6
+ // application is concerned
7
+ let text = `
8
+ /// <reference types="cypress" />
9
+ //
10
+ // This file is autogenerated by tui-sandbox. Do not edit it directly.
11
+ //
12
+ import type { OverrideProperties } from "type-fest"
13
+ import type { StartNeovimGenericArguments } from "@tui-sandbox/library/dist/src/server/types"
14
+ import type { MyTestDirectory, MyTestDirectoryFile } from "../../MyTestDirectory"
15
+
16
+ export type NeovimContext = {
17
+ contents: MyTestDirectory
18
+ rootPathAbsolute: string
19
+ }
20
+
21
+ declare global {
22
+ interface Window {
23
+ startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
24
+ }
25
+ }
26
+
27
+ type MyStartNeovimServerArguments = OverrideProperties<
28
+ StartNeovimGenericArguments,
29
+ {
30
+ filename?: MyTestDirectoryFile | { openInVerticalSplits: MyTestDirectoryFile[] }
31
+ // NOTE: right now you need to make sure the config-modifications directory exists in your test directory
32
+ startupScriptModifications?: Array<keyof MyTestDirectory["config-modifications"]["contents"]>
33
+ }
34
+ >
35
+
36
+ Cypress.Commands.add("startNeovim", (startArguments?: MyStartNeovimServerArguments) => {
37
+ cy.window().then(async win => {
38
+ return await win.startNeovim(startArguments)
39
+ })
40
+ })
41
+
42
+ Cypress.Commands.add("typeIntoTerminal", (text: string, options?: Partial<Cypress.TypeOptions>) => {
43
+ // the syntax for keys is described here:
44
+ // https://docs.cypress.io/api/commands/type
45
+ cy.get("textarea").focus().type(text, options)
46
+ })
47
+
48
+ before(function () {
49
+ // disable Cypress's default behavior of logging all XMLHttpRequests and
50
+ // fetches to the Command Log
51
+ // https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399?permalink_comment_id=4615046#gistcomment-4615046
52
+ cy.intercept({ resourceType: /xhr|fetch/ }, { log: false })
53
+ })
54
+
55
+ declare global {
56
+ namespace Cypress {
57
+ interface Chainable {
58
+ startNeovim(args?: MyStartNeovimServerArguments): Chainable<NeovimContext>
59
+ typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): Chainable<void>
60
+ }
61
+ }
62
+ }
63
+ `;
64
+ const options = await resolveConfig(__filename);
65
+ text = await format(text, { ...options, parser: "typescript" });
66
+ return text;
67
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { createCypressSupportFileContents } from "./contents.js";
2
+ it("should return the expected contents", async () => {
3
+ // this test is to help track breaking changes with releases
4
+ expect(await createCypressSupportFileContents()).toMatchInlineSnapshot(`
5
+ "/// <reference types="cypress" />
6
+ //
7
+ // This file is autogenerated by tui-sandbox. Do not edit it directly.
8
+ //
9
+ import type { StartNeovimGenericArguments } from "@tui-sandbox/library/dist/src/server/types"
10
+ import type { OverrideProperties } from "type-fest"
11
+ import type { MyTestDirectory, MyTestDirectoryFile } from "../../MyTestDirectory"
12
+
13
+ export type NeovimContext = {
14
+ contents: MyTestDirectory
15
+ rootPathAbsolute: string
16
+ }
17
+
18
+ declare global {
19
+ interface Window {
20
+ startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
21
+ }
22
+ }
23
+
24
+ type MyStartNeovimServerArguments = OverrideProperties<
25
+ StartNeovimGenericArguments,
26
+ {
27
+ filename?: MyTestDirectoryFile | { openInVerticalSplits: MyTestDirectoryFile[] }
28
+ // NOTE: right now you need to make sure the config-modifications directory exists in your test directory
29
+ startupScriptModifications?: Array<keyof MyTestDirectory["config-modifications"]["contents"]>
30
+ }
31
+ >
32
+
33
+ Cypress.Commands.add("startNeovim", (startArguments?: MyStartNeovimServerArguments) => {
34
+ cy.window().then(async win => {
35
+ return await win.startNeovim(startArguments)
36
+ })
37
+ })
38
+
39
+ Cypress.Commands.add("typeIntoTerminal", (text: string, options?: Partial<Cypress.TypeOptions>) => {
40
+ // the syntax for keys is described here:
41
+ // https://docs.cypress.io/api/commands/type
42
+ cy.get("textarea").focus().type(text, options)
43
+ })
44
+
45
+ before(function () {
46
+ // disable Cypress's default behavior of logging all XMLHttpRequests and
47
+ // fetches to the Command Log
48
+ // https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399?permalink_comment_id=4615046#gistcomment-4615046
49
+ cy.intercept({ resourceType: /xhr|fetch/ }, { log: false })
50
+ })
51
+
52
+ declare global {
53
+ namespace Cypress {
54
+ interface Chainable {
55
+ startNeovim(args?: MyStartNeovimServerArguments): Chainable<NeovimContext>
56
+ typeIntoTerminal(text: string, options?: Partial<Cypress.TypeOptions>): Chainable<void>
57
+ }
58
+ }
59
+ }
60
+ "
61
+ `);
62
+ });
@@ -0,0 +1,11 @@
1
+ export type CreateCypressSupportFileArgs = {
2
+ cypressSupportDirectoryPath: string;
3
+ supportFileName: string;
4
+ };
5
+ export type CreateCypressSupportFileResult = "updated" | "did-nothing";
6
+ /**
7
+ * This is the interface of tui-sandbox as far as cypress in the user's
8
+ * application is concerned. It needs to be checked for changes once per
9
+ * tui-sandbox version.
10
+ */
11
+ export declare function createCypressSupportFile({ cypressSupportDirectoryPath, supportFileName, }: CreateCypressSupportFileArgs): Promise<CreateCypressSupportFileResult>;
@@ -0,0 +1,29 @@
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ import path from "path";
3
+ import { createCypressSupportFileContents } from "./contents.js";
4
+ /**
5
+ * This is the interface of tui-sandbox as far as cypress in the user's
6
+ * application is concerned. It needs to be checked for changes once per
7
+ * tui-sandbox version.
8
+ */
9
+ export async function createCypressSupportFile({ cypressSupportDirectoryPath, supportFileName, }) {
10
+ const text = await createCypressSupportFileContents();
11
+ let oldSchema = "";
12
+ const outputFilePath = path.join(cypressSupportDirectoryPath, supportFileName);
13
+ try {
14
+ oldSchema = readFileSync(outputFilePath, "utf-8");
15
+ }
16
+ catch (error) {
17
+ console.log(`No existing cypress support file found at ${outputFilePath}, creating a new one`);
18
+ }
19
+ if (oldSchema !== text) {
20
+ // it's important to not write the file if the schema hasn't changed
21
+ // because file watchers will trigger on file changes and we don't want to
22
+ // trigger a build if the schema hasn't changed
23
+ writeFileSync(outputFilePath, text);
24
+ return "updated";
25
+ }
26
+ else {
27
+ return "did-nothing";
28
+ }
29
+ }
@@ -0,0 +1,35 @@
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ import { createCypressSupportFileContents } from "./contents.js";
3
+ import { createCypressSupportFile } from "./createCypressSupportFile.js";
4
+ vi.mock("fs");
5
+ vi.mock("./contents.ts");
6
+ const mocked = {
7
+ readFileSync: vi.mocked(readFileSync),
8
+ writeFileSync: vi.mocked(writeFileSync),
9
+ createCypressSupportFileContents: vi.mocked(createCypressSupportFileContents),
10
+ };
11
+ describe("createCypressSupportFileContents", () => {
12
+ it("should update the file if the schema has changed", async () => {
13
+ mocked.readFileSync.mockImplementationOnce(() => "");
14
+ mocked.writeFileSync.mockImplementationOnce(() => {
15
+ //
16
+ });
17
+ const result = await createCypressSupportFile({
18
+ cypressSupportDirectoryPath: "cypress/support",
19
+ supportFileName: "tui-sandbox.ts",
20
+ });
21
+ expect(result).toBe("updated");
22
+ });
23
+ it("should not update the file if the schema has not changed", async () => {
24
+ mocked.readFileSync.mockImplementationOnce(() => "contents");
25
+ mocked.writeFileSync.mockImplementationOnce(() => {
26
+ //
27
+ });
28
+ mocked.createCypressSupportFileContents.mockImplementationOnce(async () => "contents");
29
+ const result = await createCypressSupportFile({
30
+ cypressSupportDirectoryPath: "cypress/support",
31
+ supportFileName: "tui-sandbox.ts",
32
+ });
33
+ expect(result).toBe("did-nothing");
34
+ });
35
+ });
@@ -44,7 +44,7 @@ export declare function createAppRouter(config: TestServerConfig): Promise<impor
44
44
  tabId: string;
45
45
  };
46
46
  };
47
- output: AsyncGenerator<string, void, unknown>;
47
+ output: AsyncIterable<string, void, unknown>;
48
48
  }>;
49
49
  sendStdin: import("@trpc/server").TRPCMutationProcedure<{
50
50
  input: {
@@ -102,7 +102,7 @@ export async function startTestServer(config) {
102
102
  port: 3000,
103
103
  });
104
104
  const appRouter = await createAppRouter(config);
105
- await testServer.startAndRun(appRouter, config);
105
+ await testServer.startAndRun(appRouter);
106
106
  return testServer;
107
107
  }
108
108
  var autocleanup;