diff --git a/package-lock.json b/package-lock.json index 0b1881e76..f3b961672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -116,6 +116,7 @@ "@types/apollo-upload-client": "^17.0.0", "@types/color-convert": "^2.0.0", "@types/fuzzaldrin": "^2.1.2", + "@types/is-ci": "^3.0.0", "@types/jscodeshift": "^0.11.3", "@types/lodash-es": "^4.17.3", "@types/pollyjs__adapter-node-http": "^2.0.1", @@ -9025,6 +9026,15 @@ "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==", "dev": true }, + "node_modules/@types/is-ci": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/is-ci/-/is-ci-3.0.0.tgz", + "integrity": "sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==", + "dev": true, + "dependencies": { + "ci-info": "^3.1.0" + } + }, "node_modules/@types/is-function": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/is-function/-/is-function-1.0.0.tgz", @@ -13584,10 +13594,16 @@ } }, "node_modules/ci-info": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz", - "integrity": "sha512-2CpRNYmImPx+RXKLq6jko/L07phmS9I02TyqkcNU20GCF/GgaWvc58hPtjxDX8lPpkdwc9sNh72V9k00S7ezog==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.1.tgz", + "integrity": "sha512-4jYS4MOAaCIStSRwiuxc4B8MYhIe676yO1sYGzARnjXkWpmzZMMYxY6zu8WYWDhSuth5zhrQ1rhNSibyyvv4/w==", "devOptional": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], "engines": { "node": ">=8" } @@ -46007,6 +46023,15 @@ "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==", "dev": true }, + "@types/is-ci": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/is-ci/-/is-ci-3.0.0.tgz", + "integrity": "sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==", + "dev": true, + "requires": { + "ci-info": "^3.1.0" + } + }, "@types/is-function": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/is-function/-/is-function-1.0.0.tgz", @@ -49815,9 +49840,9 @@ } }, "ci-info": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz", - "integrity": "sha512-2CpRNYmImPx+RXKLq6jko/L07phmS9I02TyqkcNU20GCF/GgaWvc58hPtjxDX8lPpkdwc9sNh72V9k00S7ezog==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.1.tgz", + "integrity": "sha512-4jYS4MOAaCIStSRwiuxc4B8MYhIe676yO1sYGzARnjXkWpmzZMMYxY6zu8WYWDhSuth5zhrQ1rhNSibyyvv4/w==", "devOptional": true }, "cipher-base": { diff --git a/package.json b/package.json index c8344152a..8742a8313 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "@types/apollo-upload-client": "^17.0.0", "@types/color-convert": "^2.0.0", "@types/fuzzaldrin": "^2.1.2", + "@types/is-ci": "^3.0.0", "@types/jscodeshift": "^0.11.3", "@types/lodash-es": "^4.17.3", "@types/pollyjs__adapter-node-http": "^2.0.1", diff --git a/recordings/User_3768991250/will-be-logged-in-if-has-valid-credentials_3587751314/recording.har b/recordings/User_3768991250/will-be-logged-in-if-has-valid-credentials_3587751314/recording.har index 4acaf1cce..763f052f9 100644 --- a/recordings/User_3768991250/will-be-logged-in-if-has-valid-credentials_3587751314/recording.har +++ b/recordings/User_3768991250/will-be-logged-in-if-has-valid-credentials_3587751314/recording.har @@ -8,7 +8,7 @@ }, "entries": [ { - "_id": "a1435ddf90b7742bd6534592ad110e86", + "_id": "916a39b70c19064326e4caf3e7a38f9d", "_order": 0, "cache": {}, "request": { diff --git a/recordings/User_3768991250/will-not-be-logged-in-if-doesn-t-have-valid-credentials_3719199657/recording.har b/recordings/User_3768991250/will-not-be-logged-in-if-doesn-t-have-valid-credentials_3719199657/recording.har index 849d9e61f..3bf44db4f 100644 --- a/recordings/User_3768991250/will-not-be-logged-in-if-doesn-t-have-valid-credentials_3719199657/recording.har +++ b/recordings/User_3768991250/will-not-be-logged-in-if-doesn-t-have-valid-credentials_3719199657/recording.har @@ -8,7 +8,7 @@ }, "entries": [ { - "_id": "414a8e773ab89cc536de866e780f5320", + "_id": "916a39b70c19064326e4caf3e7a38f9d", "_order": 0, "cache": {}, "request": { diff --git a/recordings/User_3768991250/will-not-be-logged-in-if-is-non-staff_2544500193/recording.har b/recordings/User_3768991250/will-not-be-logged-in-if-is-non-staff_2544500193/recording.har index 225d29103..97c26c8be 100644 --- a/recordings/User_3768991250/will-not-be-logged-in-if-is-non-staff_2544500193/recording.har +++ b/recordings/User_3768991250/will-not-be-logged-in-if-is-non-staff_2544500193/recording.har @@ -8,7 +8,7 @@ }, "entries": [ { - "_id": "81637bd419aedd21a86324a846d9d163", + "_id": "916a39b70c19064326e4caf3e7a38f9d", "_order": 0, "cache": {}, "request": { diff --git a/testUtils/api.ts b/testUtils/api.ts index f00178953..ac8487efc 100644 --- a/testUtils/api.ts +++ b/testUtils/api.ts @@ -1,30 +1,55 @@ import { ApolloClient, InMemoryCache } from "@apollo/client"; import { BatchHttpLink } from "@apollo/client/link/batch-http"; import { getApiUrl } from "@dashboard/config"; -import NodeHttpAdapter from "@pollyjs/adapter-node-http"; -import FSPersister from "@pollyjs/persister-fs"; import { createFetch } from "@saleor/sdk"; +import isCI from "is-ci"; import path from "path"; import { setupPolly } from "setup-polly-jest"; +const POLLY_MODES = ["replay", "record", "passthrough", "stopped"] as const; + +function getPollyMode() { + const env = process.env.POLLY_MODE as typeof POLLY_MODES[number]; + if (!env) { + return POLLY_MODES[0]; // replay + } + if (POLLY_MODES.includes(env)) { + return env; + } + console.warn(`Unrecognised POLLY_MODE env variable value: ${env}`); + return POLLY_MODES[0]; // replay +} + +function getPollyRecordIfMissing() { + const env = process.env.POLLY_RECORD_IF_MISSING; + if (!env) { + return !isCI; + } + return env === "true"; +} + function setupApi() { setupPolly({ - adapters: [NodeHttpAdapter], + adapters: [require("@pollyjs/adapter-node-http")], matchRequestsBy: { headers: false, url: { hash: false, - hostname: false, + hostname: true, password: false, - pathname: false, + pathname: true, port: false, protocol: false, query: false, username: false, }, + body: false, }, - persister: FSPersister, + mode: getPollyMode(), + recordIfMissing: getPollyRecordIfMissing(), + persister: require("@pollyjs/persister-fs"), persisterOptions: { + keepUnusedRequests: false, fs: { recordingsDir: path.resolve(__dirname, "../recordings"), },