|
| 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 fs from 'fs'; |
| 8 | +import * as os from 'os'; |
| 9 | +import * as path from 'path'; |
| 10 | +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; |
| 11 | +import { expect } from 'chai'; |
| 12 | +import { AuthStrategy } from '@salesforce/cli-plugins-testkit/lib/hubAuth'; |
| 13 | +import { SourceIgnoredResults } from '../../src/commands/force/source/ignored/list'; |
| 14 | + |
| 15 | +describe('force:source:ignored:list', () => { |
| 16 | + let session: TestSession; |
| 17 | + let forceIgnorePath: string; |
| 18 | + let originalForceIgnore; |
| 19 | + |
| 20 | + const pathToIgnoredFile1 = path.join('foo-bar', 'app', 'classes', 'FooBar.cls'); |
| 21 | + const pathToIgnoredFile2 = path.join('foo-bar', 'app', 'classes', 'FooBar.cls-meta.xml'); |
| 22 | + |
| 23 | + before(async () => { |
| 24 | + session = await TestSession.create({ |
| 25 | + project: { |
| 26 | + gitClone: 'https://github.com/salesforcecli/sample-project-multiple-packages', |
| 27 | + }, |
| 28 | + authStrategy: AuthStrategy.NONE, |
| 29 | + }); |
| 30 | + forceIgnorePath = path.join(session.project.dir, '.forceignore'); |
| 31 | + originalForceIgnore = await fs.promises.readFile(forceIgnorePath, 'utf8'); |
| 32 | + }); |
| 33 | + |
| 34 | + after(async () => { |
| 35 | + await session?.clean(); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('no forceignore', () => { |
| 39 | + before(async () => { |
| 40 | + await fs.promises.rm(forceIgnorePath); |
| 41 | + }); |
| 42 | + after(async () => { |
| 43 | + await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); |
| 44 | + }); |
| 45 | + it('default PkgDir', () => { |
| 46 | + const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput |
| 47 | + .result; |
| 48 | + expect(result.ignoredFiles).to.deep.equal([]); |
| 49 | + }); |
| 50 | + it('specified sourcePath', () => { |
| 51 | + const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { |
| 52 | + ensureExitCode: 0, |
| 53 | + }).jsonOutput.result; |
| 54 | + expect(result2.ignoredFiles).to.deep.equal([]); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('no files are ignored (empty forceignore)', () => { |
| 59 | + before(async () => { |
| 60 | + await fs.promises.writeFile(forceIgnorePath, ''); |
| 61 | + }); |
| 62 | + after(async () => { |
| 63 | + await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); |
| 64 | + }); |
| 65 | + it('default PkgDir', () => { |
| 66 | + const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput |
| 67 | + .result; |
| 68 | + expect(result.ignoredFiles).to.deep.equal([]); |
| 69 | + }); |
| 70 | + it('specified sourcePath', () => { |
| 71 | + const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { |
| 72 | + ensureExitCode: 0, |
| 73 | + }).jsonOutput.result; |
| 74 | + expect(result2.ignoredFiles).to.deep.equal([]); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe('returns an ignored class using specified path in forceignore', () => { |
| 79 | + before(async () => { |
| 80 | + // forceignore uses a library that wants ignore rules in posix format. |
| 81 | + await fs.promises.appendFile( |
| 82 | + forceIgnorePath, |
| 83 | + `${path.normalize(pathToIgnoredFile1).split(path.sep).join(path.posix.sep)}${os.EOL}` |
| 84 | + ); |
| 85 | + await fs.promises.appendFile( |
| 86 | + forceIgnorePath, |
| 87 | + `${path.normalize(pathToIgnoredFile2).split(path.sep).join(path.posix.sep)}${os.EOL}` |
| 88 | + ); |
| 89 | + }); |
| 90 | + after(async () => { |
| 91 | + await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); |
| 92 | + }); |
| 93 | + it('default PkgDir', () => { |
| 94 | + const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput |
| 95 | + .result; |
| 96 | + expect(result.ignoredFiles).to.include(pathToIgnoredFile1); |
| 97 | + expect(result.ignoredFiles).to.include(pathToIgnoredFile2); |
| 98 | + }); |
| 99 | + it('specified sourcePath', () => { |
| 100 | + const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { |
| 101 | + ensureExitCode: 0, |
| 102 | + }).jsonOutput.result; |
| 103 | + expect(result2.ignoredFiles).to.include(pathToIgnoredFile1); |
| 104 | + expect(result2.ignoredFiles).to.include(pathToIgnoredFile2); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('returns an ignored class using wildcards', () => { |
| 109 | + before(async () => { |
| 110 | + await fs.promises.appendFile(forceIgnorePath, '**/FooBar.*'); |
| 111 | + }); |
| 112 | + after(async () => { |
| 113 | + await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); |
| 114 | + }); |
| 115 | + |
| 116 | + it('default PkgDir', () => { |
| 117 | + const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput |
| 118 | + .result; |
| 119 | + expect(result.ignoredFiles).to.include(pathToIgnoredFile1); |
| 120 | + expect(result.ignoredFiles).to.include(pathToIgnoredFile2); |
| 121 | + }); |
| 122 | + it('specified sourcePath', () => { |
| 123 | + const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { |
| 124 | + ensureExitCode: 0, |
| 125 | + }).jsonOutput.result; |
| 126 | + expect(result2.ignoredFiles).to.include(pathToIgnoredFile1); |
| 127 | + expect(result2.ignoredFiles).to.include(pathToIgnoredFile2); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('returns an ignored non-metadata component', () => { |
| 132 | + const lwcDir = path.join('foo-bar', 'app', 'lwc'); |
| 133 | + const lwcConfigPath = path.join(lwcDir, 'jsconfig.json'); |
| 134 | + |
| 135 | + before(async () => { |
| 136 | + await fs.promises.mkdir(path.join(session.project.dir, lwcDir), { recursive: true }); |
| 137 | + await fs.promises.writeFile(path.join(session.project.dir, lwcConfigPath), '{}'); |
| 138 | + }); |
| 139 | + after(async () => { |
| 140 | + await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); |
| 141 | + }); |
| 142 | + |
| 143 | + it('default PkgDir', () => { |
| 144 | + const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput |
| 145 | + .result; |
| 146 | + expect(result.ignoredFiles).to.include(lwcConfigPath); |
| 147 | + }); |
| 148 | + it('specified sourcePath', () => { |
| 149 | + const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { |
| 150 | + ensureExitCode: 0, |
| 151 | + }).jsonOutput.result; |
| 152 | + expect(result2.ignoredFiles).to.include(lwcConfigPath); |
| 153 | + }); |
| 154 | + }); |
| 155 | +}); |
0 commit comments