generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete bundle component and deploy 'new' bundle
* fix: delete bundle component and deploy 'new' bundle * chore: add NUT, UT commented due to stub issue for now * chore: add UTs, fix stubs * chore: can delete two helper files * chore: fix message tense * chore: async fs operations, remove plugin-data, another NUT * chore: hopefully fix NUTs * chore: clean up after dev work
- Loading branch information
1 parent
0827148
commit 6af9705
Showing
5 changed files
with
325 additions
and
46 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -18,10 +18,13 @@ import { ComponentSetBuilder, ComponentSetOptions } from '../../../src/component | |
import { Delete } from '../../../src/commands/force/source/delete'; | ||
import { exampleDeleteResponse, exampleSourceComponent } from './testConsts'; | ||
|
||
const fsPromises = fs.promises; | ||
|
||
describe('force:source:delete', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const username = '[email protected]'; | ||
const defaultPackagePath = 'defaultPackagePath'; | ||
let confirm = true; | ||
|
||
const oclifConfigStub = fromStub(stubInterface<IConfig>(sandbox)); | ||
|
||
|
@@ -30,6 +33,9 @@ describe('force:source:delete', () => { | |
let lifecycleEmitStub: sinon.SinonStub; | ||
let resolveProjectConfigStub: sinon.SinonStub; | ||
let fsUnlink: sinon.SinonStub; | ||
let moveToStashStub: sinon.SinonStub; | ||
let restoreFromStashStub: sinon.SinonStub; | ||
let deleteStashStub: sinon.SinonStub; | ||
|
||
class TestDelete extends Delete { | ||
public async runIt() { | ||
|
@@ -72,7 +78,11 @@ describe('force:source:delete', () => { | |
return exampleDeleteResponse; | ||
}, | ||
}); | ||
fsUnlink = stubMethod(sandbox, fs, 'unlinkSync').returns(true); | ||
stubMethod(sandbox, cmd, 'handlePrompt').returns(confirm); | ||
fsUnlink = stubMethod(sandbox, fsPromises, 'unlink').resolves(true); | ||
moveToStashStub = stubMethod(sandbox, cmd, 'moveFileToStash'); | ||
restoreFromStashStub = stubMethod(sandbox, cmd, 'restoreFileFromStash'); | ||
deleteStashStub = stubMethod(sandbox, cmd, 'deleteStash'); | ||
|
||
return cmd.runIt(); | ||
}; | ||
|
@@ -168,4 +178,69 @@ describe('force:source:delete', () => { | |
}); | ||
ensureHookArgs(); | ||
}); | ||
|
||
const stubLWC = (): string => { | ||
buildComponentSetStub.restore(); | ||
const comp = new SourceComponent({ | ||
name: 'mylwc', | ||
type: { | ||
id: 'lightningcomponentbundle', | ||
name: 'LightningComponentBundle', | ||
strategies: { | ||
adapter: 'bundle', | ||
}, | ||
}, | ||
}); | ||
stubMethod(sandbox, ComponentSetBuilder, 'build').resolves({ | ||
toArray: () => { | ||
return [comp]; | ||
}, | ||
}); | ||
const helperPath = join('dreamhouse-lwc', 'force-app', 'main', 'default', 'lwc', 'mylwc', 'helper.js'); | ||
|
||
stubMethod(sandbox, comp, 'walkContent').returns([ | ||
join('dreamhouse-lwc', 'force-app', 'main', 'default', 'lwc', 'mylwc', 'mylwc.js'), | ||
helperPath, | ||
]); | ||
|
||
stubMethod(sandbox, fs, 'lstatSync').returns({ isDirectory: () => false }); | ||
return helperPath; | ||
}; | ||
|
||
it('will use stash and delete stash upon successful delete', async () => { | ||
const sourcepath = stubLWC(); | ||
const result = await runDeleteCmd(['--sourcepath', sourcepath, '--json', '-r']); | ||
// successful delete will move files to the stash, delete the stash, and won't restore from it | ||
expect(moveToStashStub.calledOnce).to.be.true; | ||
expect(deleteStashStub.calledOnce).to.be.true; | ||
expect(restoreFromStashStub.called).to.be.false; | ||
expect(result.deletedSource).to.deep.equal([ | ||
{ | ||
filePath: sourcepath, | ||
fullName: join('mylwc', 'helper.js'), | ||
state: 'Deleted', | ||
type: 'LightningComponentBundle', | ||
}, | ||
]); | ||
}); | ||
|
||
it('restores from stash during aborted delete', async () => { | ||
const sourcepath = stubLWC(); | ||
|
||
confirm = false; | ||
const result = await runDeleteCmd(['--sourcepath', sourcepath, '--json', '-r']); | ||
// aborted delete will move files to the stash, and restore from it | ||
expect(moveToStashStub.calledOnce).to.be.true; | ||
expect(deleteStashStub.called).to.be.false; | ||
expect(restoreFromStashStub.calledOnce).to.be.true; | ||
// ensure JSON output from aborted delete | ||
expect(result).to.deep.equal({ | ||
result: { | ||
deletedSource: [], | ||
deletes: [{}], | ||
outboundFiles: [], | ||
}, | ||
status: 0, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.