From 1aefcba962edb3aa9b3e930e4bf36a685d41ee1e Mon Sep 17 00:00:00 2001 From: Will Mann Date: Tue, 24 Oct 2023 16:11:44 +0100 Subject: [PATCH 1/2] feat: changed cuids in MSW to dynamic faker strings to prevent file changes on each generation --- packages/msw/src/constants.ts | 2 ++ packages/msw/src/getters/object.ts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/msw/src/constants.ts b/packages/msw/src/constants.ts index 904d0787d..c7b859163 100644 --- a/packages/msw/src/constants.ts +++ b/packages/msw/src/constants.ts @@ -26,3 +26,5 @@ export const DEFAULT_FORMAT_MOCK: Record< uuid: 'faker.string.uuid()', zipCode: 'faker.location.zipCode()', }; + +export const DEFAULT_OBJECT_KEY_MOCK = 'faker.string.alphanumeric(5)'; diff --git a/packages/msw/src/getters/object.ts b/packages/msw/src/getters/object.ts index a1ee9815a..bf8548338 100644 --- a/packages/msw/src/getters/object.ts +++ b/packages/msw/src/getters/object.ts @@ -12,6 +12,7 @@ import { ReferenceObject, SchemaObject } from 'openapi3-ts'; import { resolveMockValue } from '../resolvers/value'; import { MockDefinition, MockSchemaObject } from '../types'; import { combineSchemasMock } from './combine'; +import { DEFAULT_OBJECT_KEY_MOCK } from '../constants'; export const getMockObject = ({ item, @@ -148,7 +149,7 @@ export const getMockObject = ({ return { ...resolvedValue, value: `{ - '${cuid()}': ${resolvedValue.value} + '[${DEFAULT_OBJECT_KEY_MOCK}]': ${resolvedValue.value} }`, }; } From 019b9e9d442448eb6184fec2722ef681d54237a6 Mon Sep 17 00:00:00 2001 From: Melloware Date: Thu, 26 Oct 2023 08:00:35 -0400 Subject: [PATCH 2/2] Update constants.ts --- packages/msw/src/constants.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/msw/src/constants.ts b/packages/msw/src/constants.ts index c7b859163..b8e61f1a4 100644 --- a/packages/msw/src/constants.ts +++ b/packages/msw/src/constants.ts @@ -27,4 +27,5 @@ export const DEFAULT_FORMAT_MOCK: Record< zipCode: 'faker.location.zipCode()', }; +// #980 replace CUID so tests are consistent export const DEFAULT_OBJECT_KEY_MOCK = 'faker.string.alphanumeric(5)';