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