From 594e9288a6aa365bddef0afe1867e28644d74290 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 28 Dec 2023 16:29:10 -0600 Subject: [PATCH 1/2] test: use structuredClone --- test/commands/retrieve/start.test.ts | 2 +- test/utils/deployResponses.ts | 43 +++++++++++++++++++--------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/test/commands/retrieve/start.test.ts b/test/commands/retrieve/start.test.ts index 279f67bf..cd655dc5 100644 --- a/test/commands/retrieve/start.test.ts +++ b/test/commands/retrieve/start.test.ts @@ -29,7 +29,7 @@ import { RetrieveResultJson } from '../../../src/utils/types.js'; import { exampleSourceComponent } from '../../utils/testConsts.js'; import RetrieveMetadata from '../../../src/commands/project/retrieve/start.js'; -Messages.importMessagesDirectoryFromMetaUrl(import.meta.url) +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'retrieve.start'); describe('project retrieve start', () => { diff --git a/test/utils/deployResponses.ts b/test/utils/deployResponses.ts index 445c915f..ca96c705 100644 --- a/test/utils/deployResponses.ts +++ b/test/utils/deployResponses.ts @@ -13,7 +13,7 @@ import { MetadataApiDeployStatus, RequestStatus, } from '@salesforce/source-deploy-retrieve'; -import { cloneJson, ensureArray } from '@salesforce/kit'; +import { ensureArray } from '@salesforce/kit'; const baseDeployResponse = { checkOnly: false, @@ -85,8 +85,7 @@ export const getDeployResponse = ( type: DeployResponseType, overrides?: Partial ): MetadataApiDeployStatus => { - // stringify --> parse to get a clone that doesn't affect the base deploy response - const response = JSON.parse(JSON.stringify({ ...baseDeployResponse, ...overrides })) as MetadataApiDeployStatus; + const response = structuredClone({ ...baseDeployResponse, ...overrides }) as MetadataApiDeployStatus; if (type === 'inProgress') { response.status = RequestStatus.InProgress; @@ -104,9 +103,11 @@ export const getDeployResponse = ( if (type === 'failed') { response.status = RequestStatus.Failed; response.success = false; - response.details.componentSuccesses = cloneJson(baseDeployResponse.details.componentSuccesses[0]) as DeployMessage; + response.details.componentSuccesses = structuredClone( + baseDeployResponse.details.componentSuccesses[0] + ) as DeployMessage; response.details.componentFailures = { - ...(cloneJson(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage), + ...(structuredClone(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage), success: false, problemType: 'Error', problem: 'This component has some problems', @@ -119,8 +120,12 @@ export const getDeployResponse = ( if (type === 'failedTest') { response.status = RequestStatus.Failed; response.success = false; - response.details.componentFailures = cloneJson(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage; - response.details.componentSuccesses = cloneJson(baseDeployResponse.details.componentSuccesses[0]) as DeployMessage; + response.details.componentFailures = structuredClone( + baseDeployResponse.details.componentSuccesses[1] + ) as DeployMessage; + response.details.componentSuccesses = structuredClone( + baseDeployResponse.details.componentSuccesses[0] + ) as DeployMessage; response.details.componentFailures.success = 'false'; delete response.details.componentFailures.id; response.details.componentFailures.problemType = 'Error'; @@ -163,8 +168,12 @@ export const getDeployResponse = ( if (type === 'passedTest') { response.status = RequestStatus.Failed; response.success = false; - response.details.componentFailures = cloneJson(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage; - response.details.componentSuccesses = cloneJson(baseDeployResponse.details.componentSuccesses[0]) as DeployMessage; + response.details.componentFailures = structuredClone( + baseDeployResponse.details.componentSuccesses[1] + ) as DeployMessage; + response.details.componentSuccesses = structuredClone( + baseDeployResponse.details.componentSuccesses[0] + ) as DeployMessage; response.details.componentFailures.success = 'false'; delete response.details.componentFailures.id; response.details.componentFailures.problemType = 'Error'; @@ -203,8 +212,12 @@ export const getDeployResponse = ( if (type === 'codeCoverageWarning') { response.status = RequestStatus.Failed; response.success = false; - response.details.componentFailures = cloneJson(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage; - response.details.componentSuccesses = cloneJson(baseDeployResponse.details.componentSuccesses[0]) as DeployMessage; + response.details.componentFailures = structuredClone( + baseDeployResponse.details.componentSuccesses[1] + ) as DeployMessage; + response.details.componentSuccesses = structuredClone( + baseDeployResponse.details.componentSuccesses[0] + ) as DeployMessage; response.details.componentFailures.success = 'false'; delete response.details.componentFailures.id; if (response.details.runTestResult) { @@ -249,8 +262,12 @@ export const getDeployResponse = ( if (type === 'passedAndFailedTest') { response.status = RequestStatus.Failed; response.success = false; - response.details.componentFailures = cloneJson(baseDeployResponse.details.componentSuccesses[1]) as DeployMessage; - response.details.componentSuccesses = cloneJson(baseDeployResponse.details.componentSuccesses[0]) as DeployMessage; + response.details.componentFailures = structuredClone( + baseDeployResponse.details.componentSuccesses[1] + ) as DeployMessage; + response.details.componentSuccesses = structuredClone( + baseDeployResponse.details.componentSuccesses[0] + ) as DeployMessage; response.details.componentFailures.success = 'false'; delete response.details.componentFailures.id; response.details.componentFailures.problemType = 'Error'; From d65e2e4e50c3f4c10ab4b1d85cc191f64f9447fc Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 28 Dec 2023 16:29:40 -0600 Subject: [PATCH 2/2] test: structuredClone