From 2bc7ea7abfc89f20d16e91db451a671b32580211 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 2 Jan 2024 14:02:43 -0300 Subject: [PATCH 1/3] fix: don't cast opts to boolean --- src/utils/deploy.ts | 6 ++---- test/nuts/deploy/metadata.nut.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils/deploy.ts b/src/utils/deploy.ts index ac4a5ee2..bedc5cea 100644 --- a/src/utils/deploy.ts +++ b/src/utils/deploy.ts @@ -5,8 +5,6 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ - - import { ConfigAggregator, Messages, Org, SfError, SfProject } from '@salesforce/core'; import { Duration } from '@salesforce/kit'; import { Nullable } from '@salesforce/ts-types'; @@ -26,7 +24,7 @@ import { DEPLOY_STATUS_CODES } from './errorCodes.js'; import { DeployCache } from './deployCache.js'; import { writeManifest } from './manifestCache.js'; -Messages.importMessagesDirectoryFromMetaUrl(import.meta.url) +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); export const cacheMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'cache'); const deployMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata'); @@ -156,7 +154,7 @@ export async function executeDeploy( }); componentSet = await buildComponentSet(opts, stl); if (componentSet.size === 0) { - if (Boolean(opts['source-dir']) ?? Boolean(opts.manifest) ?? Boolean(opts.metadata) ?? throwOnEmpty) { + if (opts['source-dir'] ?? opts.manifest ?? opts.metadata ?? throwOnEmpty) { // the user specified something to deploy, but there isn't anything throw new SfError( deployMessages.getMessage('error.nothingToDeploy'), diff --git a/test/nuts/deploy/metadata.nut.ts b/test/nuts/deploy/metadata.nut.ts index dfa818f8..fad0cd24 100644 --- a/test/nuts/deploy/metadata.nut.ts +++ b/test/nuts/deploy/metadata.nut.ts @@ -5,13 +5,24 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { join } from 'node:path'; +import * as fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { expect } from 'chai'; import { SourceTestkit } from '@salesforce/source-testkit'; +import { SfError } from '@salesforce/core'; import { DeployResultJson } from '../../../src/utils/types.js'; +const packageXml = ` + + 59.0 + +`; + describe('deploy metadata NUTs', () => { let testkit: SourceTestkit; + const packageFile = 'package.xml'; + let xmlPath: string | undefined; before(async () => { testkit = await SourceTestkit.create({ @@ -19,12 +30,21 @@ describe('deploy metadata NUTs', () => { nut: fileURLToPath(import.meta.url), }); await testkit.deploy({ args: '--source-dir force-app', exitCode: 0 }); + xmlPath = join(testkit.projectDir, packageFile); + await fs.promises.writeFile(xmlPath, packageXml); }); after(async () => { await testkit?.clean(); }); + it('should throw if component set is empty', async () => { + const response = await testkit.deploy({ args: '' }); + expect(response?.status).to.equal(1); + const result = response?.result as unknown as SfError; + expect(result.name).to.equal('NothingToDeploy'); + }); + it('should deploy ApexClasses from wildcard match (single character)', async () => { const response = await testkit.deploy({ args: '--metadata "ApexClass:P*"' }); expect(response?.status).to.equal(0); From f52af4667de42993496ddaad6072beae4158ac0a Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 2 Jan 2024 16:05:11 -0300 Subject: [PATCH 2/3] test(nut): deploy empty manifest --- test/nuts/deploy/metadata.nut.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nuts/deploy/metadata.nut.ts b/test/nuts/deploy/metadata.nut.ts index fad0cd24..dbf6daf2 100644 --- a/test/nuts/deploy/metadata.nut.ts +++ b/test/nuts/deploy/metadata.nut.ts @@ -39,7 +39,7 @@ describe('deploy metadata NUTs', () => { }); it('should throw if component set is empty', async () => { - const response = await testkit.deploy({ args: '' }); + const response = await testkit.deploy({ args: '--manifest package.xml --dry-run' }); expect(response?.status).to.equal(1); const result = response?.result as unknown as SfError; expect(result.name).to.equal('NothingToDeploy'); From bafed0289db0feee2d3eba1e9eb62177a981882c Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 2 Jan 2024 16:36:15 -0300 Subject: [PATCH 3/3] test: fix deploy nut --- test/nuts/deploy/metadata.nut.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/nuts/deploy/metadata.nut.ts b/test/nuts/deploy/metadata.nut.ts index dbf6daf2..bba4bd67 100644 --- a/test/nuts/deploy/metadata.nut.ts +++ b/test/nuts/deploy/metadata.nut.ts @@ -10,7 +10,6 @@ import * as fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { expect } from 'chai'; import { SourceTestkit } from '@salesforce/source-testkit'; -import { SfError } from '@salesforce/core'; import { DeployResultJson } from '../../../src/utils/types.js'; const packageXml = ` @@ -39,10 +38,12 @@ describe('deploy metadata NUTs', () => { }); it('should throw if component set is empty', async () => { - const response = await testkit.deploy({ args: '--manifest package.xml --dry-run' }); - expect(response?.status).to.equal(1); - const result = response?.result as unknown as SfError; - expect(result.name).to.equal('NothingToDeploy'); + try { + await testkit.deploy({ args: '--manifest package.xml --dry-run', json: true, exitCode: 1 }); + } catch (e) { + const err = e as Error; + expect(err.name).to.equal('NothingToDeploy'); + } }); it('should deploy ApexClasses from wildcard match (single character)', async () => {