From e33fd1e93a92cd95586d29d8fb0ff6cb6e038fbb Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Sat, 26 Feb 2022 17:20:38 -0700 Subject: [PATCH] fix: run mdapi NUTs in CI (#431) * fix: run mdapi NUTs in CI * fix: use latest testkit * fix: check for NaN in size comparison * fix: check for NaN in size comparison * fix: only compare file sizes not directories Co-authored-by: Shane McLaughlin --- .circleci/config.yml | 1 + package.json | 2 +- test/nuts/mdapi.nut.ts | 33 +++++++++++++++++++++------------ yarn.lock | 16 +++++++++++++++- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 639283218..9e12cd52d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,6 +81,7 @@ workflows: - 'yarn test:nuts:specialTypes' - 'yarn test:nuts:deploy:destructive' - 'yarn test:nuts:tracking' + - 'yarn test:nuts:mdapi' - release-management/release-package: sign: true github-release: true diff --git a/package.json b/package.json index 59b7e0ee1..c44e376f9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@oclif/dev-cli": "^1", "@oclif/plugin-command-snapshot": "^3.1.2", - "@salesforce/cli-plugins-testkit": "^1.5.3", + "@salesforce/cli-plugins-testkit": "^1.5.12", "@salesforce/dev-config": "^3.0.0", "@salesforce/dev-scripts": "^2.0.0", "@salesforce/plugin-command-reference": "^1.3.18", diff --git a/test/nuts/mdapi.nut.ts b/test/nuts/mdapi.nut.ts index e9feef068..01e97fe93 100644 --- a/test/nuts/mdapi.nut.ts +++ b/test/nuts/mdapi.nut.ts @@ -173,10 +173,16 @@ describe('mdapi NUTs', () => { expect(size1).to.equal(size2); } if (srcComp.content) { - const size1 = fs.statSync(srcComp.content).size; - const size2 = fs.statSync(srcComp2.content).size; - // Content files can differ slightly due to compression - expect(size1 / size2).to.be.within(0.98, 1.02); + const stat1 = fs.statSync(srcComp.content); + const stat2 = fs.statSync(srcComp2.content); + + if (stat1.isFile()) { + const size1 = stat1.size; + const size2 = stat2.size; + // Content files can differ slightly due to compression so compare + // with a tolerance. + expect(size1 / size2, `file1 size: ${size1} should ~ equal file2 size: ${size2}`).to.be.within(0.98, 1.02); + } } } }); @@ -184,12 +190,12 @@ describe('mdapi NUTs', () => { describe('mdapi:deploy:cancel', () => { it('will cancel an mdapi deploy via the stash.json', () => { - execCmd('force:source:convert --outputdir mdapi'); - const deploy = execCmd<{ id: string }>('force:mdapi:beta:deploy -d mdapi -w 0 --json', { + const convertDir = 'mdConvert1'; + execCmd(`force:source:convert --outputdir ${convertDir}`, { ensureExitCode: 0 }); + const deploy = execCmd<{ id: string }>(`force:mdapi:beta:deploy -d ${convertDir} -w 0 --json`, { ensureExitCode: 0, }).jsonOutput; - const result = execCmd('force:mdapi:deploy:cancel --json'); - expect(result.jsonOutput.status).to.equal(0); + const result = execCmd('force:mdapi:deploy:cancel --json', { ensureExitCode: 0 }); const json = result.jsonOutput.result; expect(json).to.have.property('canceledBy'); expect(json).to.have.property('status'); @@ -198,14 +204,17 @@ describe('mdapi NUTs', () => { }); it('will cancel an mdapi deploy via the specified deploy id', () => { - execCmd('force:source:convert --outputdir mdapi'); - const deploy = execCmd<{ id: string }>('force:mdapi:beta:deploy -d mdapi -w 0 --json', { + const convertDir = 'mdConvert2'; + execCmd(`force:source:convert --outputdir ${convertDir}`, { ensureExitCode: 0 }); + const deploy = execCmd<{ id: string }>(`force:mdapi:beta:deploy -d ${convertDir} -w 0 --json`, { ensureExitCode: 0, }).jsonOutput; expect(deploy.result).to.have.property('id'); - const result = execCmd(`force:mdapi:deploy:cancel --json --jobid ${deploy.result.id}`); - expect(result.jsonOutput.status).to.equal(0); + const result = execCmd( + `force:mdapi:deploy:cancel --json --jobid ${deploy.result.id}`, + { ensureExitCode: 0 } + ); const json = result.jsonOutput.result; expect(json).to.have.property('canceledBy'); expect(json).to.have.property('status'); diff --git a/yarn.lock b/yarn.lock index a3c87c822..47ec90c5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -694,7 +694,7 @@ mv "~2" safe-json-stringify "~1" -"@salesforce/cli-plugins-testkit@^1.2.0", "@salesforce/cli-plugins-testkit@^1.5.3": +"@salesforce/cli-plugins-testkit@^1.2.0": version "1.5.3" resolved "https://registry.yarnpkg.com/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-1.5.3.tgz#7a1f5e58708e5810de86f2c1a117d7e0c86e79b5" integrity sha512-watr4Dv6/pYaax+wLbAyZzmPhwkXwC62ERv370jG6064GUWXx/kdoJVEq1FFx8/cijszeWJaOyRGPpDRIss+hg== @@ -708,6 +708,20 @@ strip-ansi "6.0.1" ts-retry-promise "^0.6.0" +"@salesforce/cli-plugins-testkit@^1.5.12": + version "1.5.12" + resolved "https://registry.npmjs.org/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-1.5.12.tgz#e52631814a6cfba5ed08eeb065b214c36acd5597" + integrity sha512-GtEXgyUkF+begT49u4BsliEtDG/siGtE4ErTql7y36pptyGjsLAIWxX+0Iu1yVZzlxA4EmXMSCte/SD0iDDD4w== + dependencies: + "@salesforce/core" "^2.24.0" + "@salesforce/kit" "^1.5.13" + "@salesforce/ts-types" "^1.5.17" + archiver "^5.2.0" + debug "^4.3.1" + shelljs "^0.8.4" + strip-ansi "6.0.1" + ts-retry-promise "^0.6.0" + "@salesforce/command@^2.2.0": version "2.2.0" resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-2.2.0.tgz#316097f8defd300a93a3460dea3fe31e7d958254"