|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
| 9 | +/* eslint-disable no-console */ |
| 10 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 11 | +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
| 12 | + |
| 13 | +import * as path from 'path'; |
| 14 | +import { promises as fs } from 'fs'; |
| 15 | +import { expect } from 'chai'; |
| 16 | +import * as shell from 'shelljs'; |
| 17 | + |
| 18 | +import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit'; |
| 19 | +import { Connection, AuthInfo } from '@salesforce/core'; |
| 20 | +import { PushPullResponse } from '../../../src/shared/types'; |
| 21 | +import { StatusResult } from '../../../src/commands/force/source/status'; |
| 22 | + |
| 23 | +let session: TestSession; |
| 24 | +const classdir = 'force-app/main/default/classes'; |
| 25 | +let originalForceIgnore: string; |
| 26 | +let conn: Connection; |
| 27 | + |
8 | 28 | describe('forceignore changes', () => {
|
9 |
| - before(() => { |
10 |
| - // source status to init tracking |
| 29 | + before(async () => { |
| 30 | + session = await TestSession.create({ |
| 31 | + project: { |
| 32 | + name: 'IgnoreProject', |
| 33 | + }, |
| 34 | + setupCommands: [ |
| 35 | + `sfdx force:org:create -d 1 -s -f ${path.join('config', 'project-scratch-def.json')}`, |
| 36 | + `sfdx force:apex:class:create -n IgnoreTest --outputdir ${classdir}`, |
| 37 | + ], |
| 38 | + }); |
| 39 | + originalForceIgnore = await fs.readFile(path.join(session.project.dir, '.forceignore'), 'utf8'); |
| 40 | + conn = await Connection.create({ |
| 41 | + authInfo: await AuthInfo.create({ |
| 42 | + username: (session.setup[0] as { result: { username: string } }).result?.username, |
| 43 | + }), |
| 44 | + }); |
11 | 45 | });
|
12 | 46 |
|
13 |
| - it.skip('will not push a file that was created, then ignored', () => { |
14 |
| - // add a file in the local source |
15 |
| - // setup a forceIgnore with some file |
16 |
| - // push |
17 |
| - // verify not in results |
| 47 | + after(async () => { |
| 48 | + await session?.zip(undefined, 'artifacts'); |
| 49 | + await session?.clean(); |
18 | 50 | });
|
19 | 51 |
|
20 |
| - it.skip('will not push a file that was created, then un-ignored', () => { |
21 |
| - // setup a forceIgnore with some file |
22 |
| - // add a file in the local source |
23 |
| - // unignore the file |
24 |
| - // push |
25 |
| - // verify file pushed in results |
| 52 | + describe('local', () => { |
| 53 | + it('will not push a file that was created, then ignored', async () => { |
| 54 | + // setup a forceIgnore with some file |
| 55 | + const newForceIgnore = originalForceIgnore + '\n' + `${classdir}/IgnoreTest.cls`; |
| 56 | + await fs.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore); |
| 57 | + // nothing should push |
| 58 | + const output = execCmd<PushPullResponse[]>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput.result; |
| 59 | + expect(output).to.deep.equal([]); |
| 60 | + }); |
| 61 | + |
| 62 | + it('will ignore a class in the ignore file before it was created', async () => { |
| 63 | + // setup a forceIgnore with some file |
| 64 | + const newForceIgnore = |
| 65 | + originalForceIgnore + '\n' + `${classdir}/UnIgnoreTest.cls` + '\n' + `${classdir}/IgnoreTest.cls`; |
| 66 | + await fs.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore); |
| 67 | + |
| 68 | + // add a file in the local source |
| 69 | + shell.exec(`sfdx force:apex:class:create -n UnIgnoreTest --outputdir ${classdir}`, { |
| 70 | + cwd: session.project.dir, |
| 71 | + silent: true, |
| 72 | + }); |
| 73 | + // pushes with no results |
| 74 | + const ignoredOutput = execCmd<PushPullResponse[]>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput |
| 75 | + .result; |
| 76 | + // nothing should have been pushed |
| 77 | + expect(ignoredOutput).to.deep.equal([]); |
| 78 | + }); |
| 79 | + |
| 80 | + it('will push files that are now un-ignored', async () => { |
| 81 | + // un-ignore the file |
| 82 | + await fs.writeFile(path.join(session.project.dir, '.forceignore'), originalForceIgnore); |
| 83 | + |
| 84 | + // verify file pushed in results |
| 85 | + const unIgnoredOutput = execCmd<PushPullResponse[]>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput |
| 86 | + .result; |
| 87 | + |
| 88 | + // all 4 files should have been pushed |
| 89 | + expect(unIgnoredOutput).to.have.length(4); |
| 90 | + unIgnoredOutput.map((result) => expect(result.type === 'ApexClass')); |
| 91 | + }); |
26 | 92 | });
|
27 | 93 |
|
28 |
| - it.skip('will not pull a remote file added to the ignore AFTER it is being tracked', () => { |
29 |
| - // make a remote change |
30 |
| - // add that type to the forceignore |
31 |
| - // pull doesn't retrieve that change |
| 94 | + describe('remote', () => { |
| 95 | + it('adds on the server', async () => { |
| 96 | + const createResult = await conn.tooling.create('ApexClass', { |
| 97 | + Name: 'CreatedClass', |
| 98 | + Body: 'public class CreatedClass {}', |
| 99 | + Status: 'Active', |
| 100 | + }); |
| 101 | + if (!Array.isArray(createResult) && createResult.success) { |
| 102 | + expect(createResult.id).to.be.a('string'); |
| 103 | + } |
| 104 | + }); |
| 105 | + |
| 106 | + it('will not pull a remote file added to the ignore AFTER it is being tracked', async () => { |
| 107 | + // add that type to the forceignore |
| 108 | + await fs.writeFile(path.join(session.project.dir, '.forceignore'), originalForceIgnore + '\n' + classdir); |
| 109 | + |
| 110 | + // gets file into source tracking |
| 111 | + const statusOutput = execCmd<StatusResult[]>('force:source:status --json --remote', { ensureExitCode: 0 }) |
| 112 | + .jsonOutput.result; |
| 113 | + expect(statusOutput.some((result) => result.fullName === 'CreatedClass')).to.equal(true); |
| 114 | + |
| 115 | + // pull doesn't retrieve that change |
| 116 | + const pullOutput = execCmd<PushPullResponse[]>('force:source:pull --json', { ensureExitCode: 0 }).jsonOutput |
| 117 | + .result; |
| 118 | + expect(pullOutput.some((result) => result.fullName === 'CreatedClass')).to.equal(false); |
| 119 | + }); |
32 | 120 | });
|
33 | 121 | });
|
0 commit comments