Improve Polly.js config (#3040)
* Fix Polly.js configuration * Update test ids * Fix CR comments * Remove env var
This commit is contained in:
parent
84849f1eea
commit
2ddbb8bf9a
6 changed files with 66 additions and 15 deletions
37
package-lock.json
generated
37
package-lock.json
generated
|
@ -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": {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"entries": [
|
||||
{
|
||||
"_id": "a1435ddf90b7742bd6534592ad110e86",
|
||||
"_id": "916a39b70c19064326e4caf3e7a38f9d",
|
||||
"_order": 0,
|
||||
"cache": {},
|
||||
"request": {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"entries": [
|
||||
{
|
||||
"_id": "414a8e773ab89cc536de866e780f5320",
|
||||
"_id": "916a39b70c19064326e4caf3e7a38f9d",
|
||||
"_order": 0,
|
||||
"cache": {},
|
||||
"request": {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"entries": [
|
||||
{
|
||||
"_id": "81637bd419aedd21a86324a846d9d163",
|
||||
"_id": "916a39b70c19064326e4caf3e7a38f9d",
|
||||
"_order": 0,
|
||||
"cache": {},
|
||||
"request": {
|
||||
|
|
|
@ -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"),
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue