-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replaces unzipper library with jszip (#1086)
* major: initial changes for swapping unzipper with jszip * feat: replace unzipper with jszip * chore: bump deps for xnuts * fix: create folders on load * fix: normalize zip file paths before comparison * fix: read directory with resolved path * fix: only posix paths added via createMockZip --------- Co-authored-by: mshanemc <[email protected]>
- Loading branch information
Showing
11 changed files
with
805 additions
and
844 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import { Messages } from '@salesforce/core'; | |
import { assert, expect } from 'chai'; | ||
import chai = require('chai'); | ||
import deepEqualInAnyOrder = require('deep-equal-in-any-order'); | ||
import * as unzipper from 'unzipper'; | ||
import { SinonStub } from 'sinon'; | ||
import { getString } from '@salesforce/ts-types'; | ||
import * as fs from 'graceful-fs'; | ||
|
@@ -441,20 +440,30 @@ describe('MetadataApiRetrieve', () => { | |
describe('post', () => { | ||
const output = join('mdapi', 'retrieve', 'dir'); | ||
const format = 'metadata'; | ||
const zipFile = 'abcd1234'; | ||
// This is what real zip file contents look like from the server | ||
const zipFile = `UEsDBBQACAgIACKPFlcAAAAAA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AAAAAAAAADSAAAAdW5wYWNrYWdlZC9jbGFzc2V | ||
zL1BhZ2VkUmVzdWx0LmNscy1tZXRhLnhtbFBLAQIUABQACAgIACKPFlcBhse1owAAAOcAAAAWAAAAAAAAAAAAAAAAALMBAAB1bnB | ||
hY2thZ2VkL3BhY2thZ2UueG1sUEsFBgAAAAADAAMA7QAAAJoCAAAAAA==`; | ||
const zipFileContents = Buffer.from(zipFile, 'base64'); | ||
const usernameOrConnection = '[email protected]'; | ||
const fakeResults = { status: RequestStatus.Succeeded, zipFile } as MetadataApiRetrieveStatus; | ||
let writeFileStub: SinonStub; | ||
let openBufferStub: SinonStub; | ||
let extractStub: SinonStub; | ||
let mkdirStub: SinonStub; | ||
const mdapiRetrieveExtractStub = $$.SANDBOX.stub().resolves({}); | ||
|
||
beforeEach(() => { | ||
writeFileStub = $$.SANDBOX.stub(fs, 'writeFileSync'); | ||
extractStub = $$.SANDBOX.stub().resolves(); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument | ||
openBufferStub = $$.SANDBOX.stub(unzipper.Open, 'buffer').resolves({ extract: extractStub } as any); | ||
mkdirStub = $$.SANDBOX.stub(fs, 'mkdirSync'); | ||
}); | ||
|
||
it('should write the retrieved zip when format=metadata', async () => { | ||
|
@@ -466,7 +475,7 @@ describe('MetadataApiRetrieve', () => { | |
expect(writeFileStub.calledOnce).to.be.true; | ||
expect(writeFileStub.firstCall.args[0]).to.equal(join(output, 'unpackaged.zip')); | ||
expect(writeFileStub.firstCall.args[1]).to.deep.equal(zipFileContents); | ||
expect(openBufferStub.called).to.be.false; | ||
expect(mkdirStub.called).to.be.false; | ||
expect(mdapiRetrieveExtractStub.called).to.be.false; | ||
}); | ||
|
||
|
@@ -476,11 +485,19 @@ describe('MetadataApiRetrieve', () => { | |
mdapiRetrieve.extract = mdapiRetrieveExtractStub; | ||
await mdapiRetrieve.post(fakeResults); | ||
|
||
expect(writeFileStub.calledOnce).to.be.true; | ||
const unpkg1Dir = join(output, 'unpackaged'); | ||
const unpkg2Dir = join(unpkg1Dir, 'unpackaged/'); | ||
const classesDir = join(unpkg2Dir, 'classes/'); | ||
|
||
expect(writeFileStub.called).to.be.true; | ||
expect(writeFileStub.firstCall.args[0]).to.equal(join(output, 'unpackaged.zip')); | ||
expect(writeFileStub.firstCall.args[1]).to.deep.equal(zipFileContents); | ||
expect(openBufferStub.called).to.be.true; | ||
expect(extractStub.called).to.be.true; | ||
expect(writeFileStub.secondCall.args[0]).to.equal(join(classesDir, 'PagedResult.cls')); | ||
expect(writeFileStub.thirdCall.args[0]).to.equal(join(classesDir, 'PagedResult.cls-meta.xml')); | ||
expect(mkdirStub.called).to.be.true; | ||
expect(mkdirStub.firstCall.args[0]).to.equal(unpkg1Dir); | ||
expect(mkdirStub.secondCall.args[0]).to.equal(unpkg2Dir); | ||
expect(mkdirStub.thirdCall.args[0]).to.equal(classesDir); | ||
expect(mdapiRetrieveExtractStub.called).to.be.false; | ||
}); | ||
|
||
|
@@ -494,7 +511,7 @@ describe('MetadataApiRetrieve', () => { | |
expect(writeFileStub.calledOnce).to.be.true; | ||
expect(writeFileStub.firstCall.args[0]).to.equal(join(output, zipFileName)); | ||
expect(writeFileStub.firstCall.args[1]).to.deep.equal(zipFileContents); | ||
expect(openBufferStub.called).to.be.false; | ||
expect(mkdirStub.called).to.be.false; | ||
expect(mdapiRetrieveExtractStub.called).to.be.false; | ||
}); | ||
}); | ||
|
Oops, something went wrong.