From de50ae86c635effeb346c88ac488c2aedae65cd2 Mon Sep 17 00:00:00 2001 From: Bob Qiu Date: Wed, 28 Oct 2026 17:28:32 +0800 Subject: [PATCH] Add tests and YAML configurations for environment variable sourcing and response handling - Introduced new YAML files for global environments, project environment sources, and environment cascade collections. - Implemented tests for variable source levels, modal editing, tooltip behavior, and response downloads. - Enhanced pre-request scripts to handle client certificates and proxy updates. - Verified caching behavior for prompt tags and response tag trigger behaviors. --- .../environment-pickers-and-creation.spec.ts | 9 ++++--- ...environment-overrides-sub-and-base.spec.ts | 23 +++++++++-------- .../variable-source-levels.spec.ts | 23 +++++++++-------- .../variable-source-modal-editing.spec.ts | 16 ++++++------ .../variable-source-tooltip-behavior.spec.ts | 13 +++++----- .../variable-source-tooltip-open.spec.ts | 17 +++++++------ ...t-script-client-certificate-update.spec.ts | 23 +++++++++-------- .../pre-request-script-proxy-update.spec.ts | 17 +++++++------ .../http-request/response-downloads.spec.ts | 13 +++++----- ...mpt-tag-caches-value-until-cleared.spec.ts | 25 ++++++++++--------- .../response-tag-trigger-behaviors.spec.ts | 25 ++++++++++--------- 11 files changed, 106 insertions(+), 98 deletions(-) diff --git a/packages/insomnia-test/tests/environment/environment-pickers-and-creation.spec.ts b/packages/insomnia-test/tests/environment/environment-pickers-and-creation.spec.ts index 34d4b4ec73..02d87f6c76 100644 --- a/packages/insomnia-test/tests/environment/environment-pickers-and-creation.spec.ts +++ b/packages/insomnia-test/tests/environment/environment-pickers-and-creation.spec.ts @@ -1,10 +1,11 @@ import { faker } from "@faker-js/faker"; -import { ProjectType } from "@package/enums/project-types"; -import { test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { ProjectType } from "../../enums/project-types"; +import { test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + test("Verify the project and collection environment pickers open and close independently", async ({ user, }) => { diff --git a/packages/insomnia-test/tests/environment/folder-environment-overrides-sub-and-base.spec.ts b/packages/insomnia-test/tests/environment/folder-environment-overrides-sub-and-base.spec.ts index 6627f1e2b9..0dc992b9f5 100644 --- a/packages/insomnia-test/tests/environment/folder-environment-overrides-sub-and-base.spec.ts +++ b/packages/insomnia-test/tests/environment/folder-environment-overrides-sub-and-base.spec.ts @@ -1,13 +1,14 @@ import { faker } from "@faker-js/faker"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { HTTP_SERVER, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { EnvironmentKvPairDataType } from "@package/models/environment"; -import { Folder } from "@package/models/folder"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { HTTP_SERVER, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { EnvironmentKvPairDataType } from "../../models/environment"; +import { Folder } from "../../models/folder"; +import { Project } from "../../models/project"; + const sharedVariable = faker.string.alpha(8); const subOnlyVariable = faker.string.alpha(9); @@ -64,12 +65,12 @@ test("Verify a folder environment overrides sub and base environments for its re const responseInFolder = await httpRequestFlow.send(requestInFolder); const responseOutsideFolder = await httpRequestFlow.send(requestOutsideFolder); - expect(responseInFolder.statusBar.code).toBe(200); - expect(responseInFolder.preview).toMatchObject({ + expect(responseInFolder.statusCode).toBe(200); + expect(responseInFolder.body).toMatchObject({ args: { shared: folderShared, subOnly: subSubOnly }, }); - expect(responseOutsideFolder.statusBar.code).toBe(200); - expect(responseOutsideFolder.preview).toMatchObject({ + expect(responseOutsideFolder.statusCode).toBe(200); + expect(responseOutsideFolder.body).toMatchObject({ args: { shared: subShared, subOnly: subSubOnly }, }); }); diff --git a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-levels.spec.ts b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-levels.spec.ts index 8e10f612c2..804ca1e703 100644 --- a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-levels.spec.ts +++ b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-levels.spec.ts @@ -1,17 +1,18 @@ import path from "node:path"; import { faker } from "@faker-js/faker"; -import { ProjectType } from "@package/enums/project-types"; -import type { FlowManager } from "@package/flows/flow-manager"; -import type { VariableSourceLanding } from "@package/flows/variable-source.flow"; -import { test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; -const cascadeFixture = path.join(import.meta.dirname, "environment-cascade-collection.yaml"); -const globalCollectionFixture = path.join(import.meta.dirname, "collection-for-global-environments.yaml"); -const globalEnvironmentFixture = path.join(import.meta.dirname, "global-environment.yaml"); +import { ProjectType } from "../../../enums/project-types"; +import { test } from "../../../misc/fixtures"; +import { Collection } from "../../../models/collection"; +import { Project } from "../../../models/project"; +import type { FlowManager } from "../../../flows/flow-manager"; +import type { VariableSourceLanding } from "../../../flows/variable-source.flow"; + +const cascadeFixture = path.join(__dirname, "environment-cascade-collection.yaml"); +const globalCollectionFixture = path.join(__dirname, "collection-for-global-environments.yaml"); +const globalEnvironmentFixture = path.join(__dirname, "global-environment.yaml"); interface Scenario { id: string; @@ -145,9 +146,9 @@ for (const scenario of scenarios) { scenario.landingRow, ); - expect(response.statusBar.code).toBe(200); + expect(response.statusCode).toBe(200); expect( - JSON.parse((response.preview as { data: string }).data)[scenario.field], + JSON.parse((response.body as { data: string }).data)[scenario.field], ).toBe(scenario.value); expect(modal.source).toContain(scenario.source); expect(modal.preview).toBe(scenario.value); diff --git a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-modal-editing.spec.ts b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-modal-editing.spec.ts index 6c34b1d414..aa5a5b15f6 100644 --- a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-modal-editing.spec.ts +++ b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-modal-editing.spec.ts @@ -1,12 +1,13 @@ import path from "node:path"; import { faker } from "@faker-js/faker"; -import { ProjectType } from "@package/enums/project-types"; -import { test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { ProjectType } from "../../../enums/project-types"; +import { test } from "../../../misc/fixtures"; +import { Collection } from "../../../models/collection"; +import { Project } from "../../../models/project"; + test("Verify the tag modal's source follows the edited template and hides for non-variable content", async ({ user, }) => { @@ -18,7 +19,7 @@ test("Verify the tag modal's source follows the edited template and hides for no ); await importFlow.importFile( project, - path.join(import.meta.dirname, "environment-cascade-collection.yaml"), + path.join(__dirname, "environment-cascade-collection.yaml"), ); const collection = new Collection("Environment Cascade"); await environmentFlow.activate(collection, "Base Environment"); @@ -29,10 +30,7 @@ test("Verify the tag modal's source follows the edited template and hides for no "{{ _.subOnlyVar }}", "subOnly_base", ); - await variableSourceFlow.selectModalVariable( - { label: "-- Custom --" }, - "Failed to render environment variables: 'my custom template logic'", - ); + await variableSourceFlow.selectModalVariable({ label: "-- Custom --" }); const plainText = await variableSourceFlow.setModalTemplate("plain text", "plain text"); const inheritedKey = await variableSourceFlow.setModalTemplate("{{ constructor }}"); const padded = await variableSourceFlow.setModalTemplate("{{ _.subOnlyVar }}", "subOnly_base"); diff --git a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-behavior.spec.ts b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-behavior.spec.ts index 8ead0d488f..93cc0bb78f 100644 --- a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-behavior.spec.ts +++ b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-behavior.spec.ts @@ -1,12 +1,13 @@ import path from "node:path"; import { faker } from "@faker-js/faker"; -import { ProjectType } from "@package/enums/project-types"; -import { test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { ProjectType } from "../../../enums/project-types"; +import { test } from "../../../misc/fixtures"; +import { Collection } from "../../../models/collection"; +import { Project } from "../../../models/project"; + test("Verify hovering an undefined variable swaps the tooltip to the render error instead of vanishing", async ({ user, }) => { @@ -18,7 +19,7 @@ test("Verify hovering an undefined variable swaps the tooltip to the render erro ); await importFlow.importFile( project, - path.join(import.meta.dirname, "collection-for-global-environments.yaml"), + path.join(__dirname, "collection-for-global-environments.yaml"), ); const collection = new Collection("collection-for-global-environments"); await environmentFlow.activate(collection, "ExampleA"); @@ -44,7 +45,7 @@ test("Verify hovering the tooltip's own content keeps it visible", async ({ user ); await importFlow.importFile( project, - path.join(import.meta.dirname, "environment-cascade-collection.yaml"), + path.join(__dirname, "environment-cascade-collection.yaml"), ); const collection = new Collection("Environment Cascade"); await environmentFlow.activate(collection, "Base Environment"); diff --git a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-open.spec.ts b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-open.spec.ts index fb57ca4154..4df8d8502b 100644 --- a/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-open.spec.ts +++ b/packages/insomnia-test/tests/environment/variable-source-live-preview/variable-source-tooltip-open.spec.ts @@ -1,16 +1,17 @@ import path from "node:path"; import { faker } from "@faker-js/faker"; -import { ProjectType } from "@package/enums/project-types"; -import { test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; -const cascadeFixture = path.join(import.meta.dirname, "environment-cascade-collection.yaml"); -const globalCollectionFixture = path.join(import.meta.dirname, "collection-for-global-environments.yaml"); -const globalEnvironmentFixture = path.join(import.meta.dirname, "global-environment.yaml"); -const projectEnvironmentSourceFixture = path.join(import.meta.dirname, "project-environment-source.yaml"); +import { ProjectType } from "../../../enums/project-types"; +import { test } from "../../../misc/fixtures"; +import { Collection } from "../../../models/collection"; +import { Project } from "../../../models/project"; + +const cascadeFixture = path.join(__dirname, "environment-cascade-collection.yaml"); +const globalCollectionFixture = path.join(__dirname, "collection-for-global-environments.yaml"); +const globalEnvironmentFixture = path.join(__dirname, "global-environment.yaml"); +const projectEnvironmentSourceFixture = path.join(__dirname, "project-environment-source.yaml"); test("Verify the tooltip's Open inside the Manage Environments modal selects the source environment, and works again after selecting another", async ({ user, diff --git a/packages/insomnia-test/tests/http-request/pre-request-script-client-certificate-update.spec.ts b/packages/insomnia-test/tests/http-request/pre-request-script-client-certificate-update.spec.ts index 6bd2c0d0c8..5186319b0d 100644 --- a/packages/insomnia-test/tests/http-request/pre-request-script-client-certificate-update.spec.ts +++ b/packages/insomnia-test/tests/http-request/pre-request-script-client-certificate-update.spec.ts @@ -1,14 +1,15 @@ import path from "node:path"; import { faker } from "@faker-js/faker"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { certPath } from "@package/misc/certs"; -import { DEFAULT_TIMEOUT, HTTP_SERVER_MTLS, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { certPath } from "../../misc/certs"; +import { DEFAULT_TIMEOUT, HTTP_SERVER_MTLS, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + const url = `${HTTP_SERVER_MTLS}/post`; test("Verify pre-request script reads and replaces the client certificate via insomnia.request.certificate", async ({ @@ -19,7 +20,7 @@ test("Verify pre-request script reads and replaces the client certificate via in await preferencesFlow.set({ validateSSL: false, - dataFolders: [path.join(import.meta.dirname, "../../misc/fixtures")], + dataFolders: [path.join(__dirname, "../../misc/fixtures")], }); const project = await workspaceFlow.createProject( @@ -53,14 +54,14 @@ test("Verify pre-request script reads and replaces the client certificate via in }); const responseView = await httpRequestFlow.send(request); - expect(responseView.statusBar.code).toBe(200); + expect(responseView.statusCode).toBe(200); await expect - .poll(() => responseView.console(), { timeout: DEFAULT_TIMEOUT }) + .poll(() => responseView.console?.(), { timeout: DEFAULT_TIMEOUT }) .toContain("Adding SSL PEM certificate"); await expect - .poll(() => responseView.console(), { timeout: DEFAULT_TIMEOUT }) + .poll(() => responseView.console?.(), { timeout: DEFAULT_TIMEOUT }) .toContain("Adding SSL KEY certificate"); await expect - .poll(() => responseView.console(), { timeout: DEFAULT_TIMEOUT }) + .poll(() => responseView.console?.(), { timeout: DEFAULT_TIMEOUT }) .toContain("original cert:"); }); diff --git a/packages/insomnia-test/tests/http-request/pre-request-script-proxy-update.spec.ts b/packages/insomnia-test/tests/http-request/pre-request-script-proxy-update.spec.ts index 7faab81c18..a4c3183321 100644 --- a/packages/insomnia-test/tests/http-request/pre-request-script-proxy-update.spec.ts +++ b/packages/insomnia-test/tests/http-request/pre-request-script-proxy-update.spec.ts @@ -1,11 +1,12 @@ import { faker } from "@faker-js/faker"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { DEFAULT_TIMEOUT, HTTP_SERVER, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { DEFAULT_TIMEOUT, HTTP_SERVER, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + const url = `${HTTP_SERVER}/post`; test("Verify pre-request script reads the configured proxy and overrides it via insomnia.request.proxy", async ({ @@ -48,11 +49,11 @@ test("Verify pre-request script reads the configured proxy and overrides it via }); const responseView = await httpRequestFlow.send(request); - expect(responseView.statusBar.code).toBeUndefined(); + expect(responseView.statusCode).toBeUndefined(); await expect - .poll(() => responseView.console(), { timeout: DEFAULT_TIMEOUT }) + .poll(() => responseView.console?.(), { timeout: DEFAULT_TIMEOUT }) .toContain("localhost:1111"); await expect - .poll(() => responseView.console(), { timeout: DEFAULT_TIMEOUT }) + .poll(() => responseView.console?.(), { timeout: DEFAULT_TIMEOUT }) .toContain("Trying 127.0.0.1:8888"); }); diff --git a/packages/insomnia-test/tests/http-request/response-downloads.spec.ts b/packages/insomnia-test/tests/http-request/response-downloads.spec.ts index 3c9c74ba9f..5a90cb3d4f 100644 --- a/packages/insomnia-test/tests/http-request/response-downloads.spec.ts +++ b/packages/insomnia-test/tests/http-request/response-downloads.spec.ts @@ -3,14 +3,15 @@ import os from "node:os"; import path from "node:path"; import { faker } from "@faker-js/faker"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { ResponseExportOption } from "@package/enums/response-export-option"; -import { DEFAULT_TIMEOUT, HTTP_SERVER, LONG_TIMEOUT, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { ResponseExportOption } from "../../enums/response-export-option"; +import { DEFAULT_TIMEOUT, HTTP_SERVER, LONG_TIMEOUT, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + const LARGE_RESPONSE_BYTES = 5 * 1024 * 1024; test("Verify exporting a small JSON response as raw, prettified and HTTP debug files", async ({ diff --git a/packages/insomnia-test/tests/template-tag/prompt-tag-caches-value-until-cleared.spec.ts b/packages/insomnia-test/tests/template-tag/prompt-tag-caches-value-until-cleared.spec.ts index eeb8283f14..b845c5215a 100644 --- a/packages/insomnia-test/tests/template-tag/prompt-tag-caches-value-until-cleared.spec.ts +++ b/packages/insomnia-test/tests/template-tag/prompt-tag-caches-value-until-cleared.spec.ts @@ -1,12 +1,13 @@ import { faker } from "@faker-js/faker"; -import { ContentType } from "@package/enums/content-type"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { HTTP_SERVER, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { ContentType } from "../../enums/content-type"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { HTTP_SERVER, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + test("Verify a prompt Tag Caches its Value Under the Storage Key Until it is Cleared", async ({ user, }) => { @@ -48,10 +49,10 @@ test("Verify a prompt Tag Caches its Value Under the Storage Key Until it is Cle expect(previewBeforeSend.functionName).toBe("prompt"); expect(first.promptInputType).toBe("password"); - expect(first.response.statusBar.code).toBe(200); - expect(first.response.preview).toMatchObject({ data: firstValue }); - expect(cached.statusBar.code).toBe(200); - expect(cached.preview).toMatchObject({ data: firstValue }); - expect(second.response.statusBar.code).toBe(200); - expect(second.response.preview).toMatchObject({ data: secondValue }); + expect(first.response.statusCode).toBe(200); + expect(first.response.body).toMatchObject({ data: firstValue }); + expect(cached.statusCode).toBe(200); + expect(cached.body).toMatchObject({ data: firstValue }); + expect(second.response.statusCode).toBe(200); + expect(second.response.body).toMatchObject({ data: secondValue }); }); diff --git a/packages/insomnia-test/tests/template-tag/response-tag-trigger-behaviors.spec.ts b/packages/insomnia-test/tests/template-tag/response-tag-trigger-behaviors.spec.ts index adb82c6ed5..d37cb504ac 100644 --- a/packages/insomnia-test/tests/template-tag/response-tag-trigger-behaviors.spec.ts +++ b/packages/insomnia-test/tests/template-tag/response-tag-trigger-behaviors.spec.ts @@ -1,12 +1,13 @@ import { faker } from "@faker-js/faker"; -import { ContentType } from "@package/enums/content-type"; -import { HttpMethod } from "@package/enums/http-method"; -import { ProjectType } from "@package/enums/project-types"; -import { HTTP_SERVER, test } from "@package/misc/fixtures"; -import { Collection } from "@package/models/collection"; -import { Project } from "@package/models/project"; import { expect } from "@playwright/test"; +import { ContentType } from "../../enums/content-type"; +import { HttpMethod } from "../../enums/http-method"; +import { ProjectType } from "../../enums/project-types"; +import { HTTP_SERVER, test } from "../../misc/fixtures"; +import { Collection } from "../../models/collection"; +import { Project } from "../../models/project"; + test("Verify the response Tag's Trigger Behavior Controls When its Dependency Request is Resent", async ({ user, }) => { @@ -53,10 +54,10 @@ test("Verify the response Tag's Trigger Behavior Controls When its Dependency Re const always = await httpRequestFlow.send(alwaysRequest); await expect(neverFailure).rejects.toThrow(/No responses for request/); - expect(noHistory.statusBar.code).toBe(200); - expect(noHistory.preview).toMatchObject({ data: marker }); - expect(whenExpired.statusBar.code).toBe(200); - expect(whenExpired.preview).toMatchObject({ data: marker }); - expect(always.statusBar.code).toBe(200); - expect(always.preview).toMatchObject({ data: marker }); + expect(noHistory.statusCode).toBe(200); + expect(noHistory.body).toMatchObject({ data: marker }); + expect(whenExpired.statusCode).toBe(200); + expect(whenExpired.body).toMatchObject({ data: marker }); + expect(always.statusCode).toBe(200); + expect(always.body).toMatchObject({ data: marker }); });