|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * Licensed under the BSD 3-Clause license. |
| 5 | + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | +import * as path from 'path'; |
| 8 | +import * as fs from 'fs'; |
| 9 | +import { TestSession } from '@salesforce/cli-plugins-testkit'; |
| 10 | +import { expect } from 'chai'; |
| 11 | +import * as sinon from 'sinon'; |
| 12 | +import { getComponentSets } from '../../../src/shared/localComponentSetArray'; |
| 13 | + |
| 14 | +describe('Bundle-like types delete', () => { |
| 15 | + let session: TestSession; |
| 16 | + |
| 17 | + before(async () => { |
| 18 | + session = await TestSession.create({ |
| 19 | + project: { |
| 20 | + sourceDir: path.join('test', 'nuts', 'repros', 'partialBundleDelete'), |
| 21 | + }, |
| 22 | + authStrategy: 'NONE', |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + // We need a sinon sandbox to stub the file system to make it look like we |
| 27 | + // deleted some files. |
| 28 | + const sandbox = sinon.createSandbox(); |
| 29 | + |
| 30 | + after(async () => { |
| 31 | + await session?.clean(); |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(() => { |
| 35 | + sandbox.restore(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('returns components for deploy with partial LWC delete', () => { |
| 39 | + const lwcTestCompDir = path.join(session.project.dir, 'force-app', 'lwc', 'testComp'); |
| 40 | + const lwcHtmlFile = path.join(lwcTestCompDir, 'myComp.html'); |
| 41 | + const lwcJsFile = path.join(lwcTestCompDir, 'myComp.js'); |
| 42 | + const lwcMetaFile = path.join(lwcTestCompDir, 'myComp.js-meta.xml'); |
| 43 | + |
| 44 | + const compSets = getComponentSets([ |
| 45 | + { |
| 46 | + path: path.join(session.project.dir, 'force-app', 'lwc'), |
| 47 | + nonDeletes: [lwcJsFile, lwcMetaFile], |
| 48 | + deletes: [lwcHtmlFile], |
| 49 | + }, |
| 50 | + ]); |
| 51 | + |
| 52 | + expect(compSets.length).to.equal(1); |
| 53 | + compSets.forEach((cs) => { |
| 54 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal([]); |
| 55 | + const comps = cs.getSourceComponents().toArray(); |
| 56 | + expect(comps[0].isMarkedForDelete()).to.equal(false); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it('returns components for delete for full LWC delete', () => { |
| 61 | + // We stub this so it appears that we deleted all the LWC files |
| 62 | + sandbox.stub(fs, 'existsSync').returns(false); |
| 63 | + const lwcTestCompDir = path.join(session.project.dir, 'force-app', 'lwc', 'testComp'); |
| 64 | + const lwcHtmlFile = path.join(lwcTestCompDir, 'myComp.html'); |
| 65 | + const lwcJsFile = path.join(lwcTestCompDir, 'myComp.js'); |
| 66 | + const lwcMetaFile = path.join(lwcTestCompDir, 'myComp.js-meta.xml'); |
| 67 | + |
| 68 | + const compSets = getComponentSets([ |
| 69 | + { |
| 70 | + path: path.join(session.project.dir, 'force-app', 'lwc'), |
| 71 | + nonDeletes: [], |
| 72 | + deletes: [lwcHtmlFile, lwcJsFile, lwcMetaFile], |
| 73 | + }, |
| 74 | + ]); |
| 75 | + |
| 76 | + expect(compSets.length).to.equal(1); |
| 77 | + compSets.forEach((cs) => { |
| 78 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal(['post']); |
| 79 | + const comps = cs.getSourceComponents().toArray(); |
| 80 | + expect(comps[0].isMarkedForDelete()).to.equal(true); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + it('returns components for deploy with partial StaticResource delete', () => { |
| 85 | + const srDir = path.join(session.project.dir, 'force-app', 'staticresources'); |
| 86 | + const srFile1 = path.join(srDir, 'ZippedResource', 'file1.json'); |
| 87 | + const srFile2 = path.join(srDir, 'ZippedResource', 'file2.json'); |
| 88 | + const srMetaFile = path.join(srDir, 'ZippedResource.resource-meta.xml'); |
| 89 | + |
| 90 | + const compSets = getComponentSets([ |
| 91 | + { |
| 92 | + path: srDir, |
| 93 | + nonDeletes: [srMetaFile, srFile2], |
| 94 | + deletes: [srFile1], |
| 95 | + }, |
| 96 | + ]); |
| 97 | + |
| 98 | + expect(compSets.length).to.equal(1); |
| 99 | + compSets.forEach((cs) => { |
| 100 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal([]); |
| 101 | + const comps = cs.getSourceComponents().toArray(); |
| 102 | + expect(comps[0].isMarkedForDelete()).to.equal(false); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + it('returns components for delete for full StaticResource delete', () => { |
| 107 | + // We stub this so it appears that we deleted all the ZippedResource static resource files |
| 108 | + sandbox.stub(fs, 'existsSync').returns(false); |
| 109 | + const srDir = path.join(session.project.dir, 'force-app', 'staticresources'); |
| 110 | + const srFile1 = path.join(srDir, 'ZippedResource', 'file1.json'); |
| 111 | + const srFile2 = path.join(srDir, 'ZippedResource', 'file2.json'); |
| 112 | + const srMetaFile = path.join(srDir, 'ZippedResource.resource-meta.xml'); |
| 113 | + |
| 114 | + const compSets = getComponentSets([ |
| 115 | + { |
| 116 | + path: srDir, |
| 117 | + nonDeletes: [], |
| 118 | + deletes: [srFile1, srFile2, srMetaFile], |
| 119 | + }, |
| 120 | + ]); |
| 121 | + |
| 122 | + expect(compSets.length).to.equal(1); |
| 123 | + compSets.forEach((cs) => { |
| 124 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal(['post']); |
| 125 | + const comps = cs.getSourceComponents().toArray(); |
| 126 | + expect(comps[0].isMarkedForDelete()).to.equal(true); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + it('returns components for deploy with partial DigitalExperienceBundle delete', () => { |
| 131 | + const debDir = path.join(session.project.dir, 'force-app', 'digitalExperiences', 'site', 'Xcel_Energy1'); |
| 132 | + const deFile1 = path.join(debDir, 'sfdc_cms__view', 'home', 'content.json'); |
| 133 | + |
| 134 | + const compSets = getComponentSets([ |
| 135 | + { |
| 136 | + path: debDir, |
| 137 | + nonDeletes: [], |
| 138 | + deletes: [deFile1], |
| 139 | + }, |
| 140 | + ]); |
| 141 | + |
| 142 | + expect(compSets.length).to.equal(1); |
| 143 | + compSets.forEach((cs) => { |
| 144 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal([]); |
| 145 | + const comps = cs.getSourceComponents().toArray(); |
| 146 | + expect(comps[0].isMarkedForDelete()).to.equal(false); |
| 147 | + }); |
| 148 | + }); |
| 149 | + |
| 150 | + it('returns components for deploy with partial ExperienceBundle delete', () => { |
| 151 | + const ebDir = path.join(session.project.dir, 'force-app', 'experiences', 'fooEB'); |
| 152 | + const eFile1 = path.join(ebDir, 'views', 'login.json'); |
| 153 | + const eFile2 = path.join(ebDir, 'routes', 'login.json'); |
| 154 | + |
| 155 | + const compSets = getComponentSets([ |
| 156 | + { |
| 157 | + path: ebDir, |
| 158 | + nonDeletes: [eFile2], |
| 159 | + deletes: [eFile1], |
| 160 | + }, |
| 161 | + ]); |
| 162 | + |
| 163 | + expect(compSets.length).to.equal(1); |
| 164 | + compSets.forEach((cs) => { |
| 165 | + expect(cs.getTypesOfDestructiveChanges()).to.deep.equal([]); |
| 166 | + const comps = cs.getSourceComponents().toArray(); |
| 167 | + expect(comps[0].isMarkedForDelete()).to.equal(false); |
| 168 | + }); |
| 169 | + }); |
| 170 | +}); |
0 commit comments