8000 test: add failing test for staged deleted files not passed directly t… · lint-staged/lint-staged@48a6e95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48a6e95

Browse files
ItsNickBarryiiroj
authored andcommitted
test: add failing test for staged deleted files not passed directly to tasks with diff filter D
1 parent b56b29e commit 48a6e95

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/integration/diff-options.test.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('lint-staged', () => {
7070
)
7171

7272
test(
73-
'supports staged deleted files',
73+
'supports staged deleted files processed by linter',
7474
withGitIntegration(async ({ appendFile, cwd, execGit }) => {
7575
const globalConsoleTemp = console
7676
console = makeConsoleMock()
@@ -91,6 +91,42 @@ describe('lint-staged', () => {
9191
})
9292

9393
expect(passed).toEqual(true)
94+
expect(console.printHistory()).not.toMatch('No files matching the pattern were found:')
95+
96+
console = globalConsoleTemp
97+
})
98+
)
99+
100+
test(
101+
'supports staged deleted files not processed by linter',
102+
withGitIntegration(async ({ appendFile, cwd, execGit }) => {
103+
const globalConsoleTemp = console
104+
console = makeConsoleMock()
105+
106+
// Stage and commit file
107+
await appendFile('test.txt', 'text contents')
108+
await execGit(['add', 'test.txt'])
109+
await execGit(['commit', '-m', 'test'])
110+
111+
// Staged deleted file not subject to linter processing
112+
await execGit(['rm', 'test.txt'])
113+
114+
// Run lint-staged with `--diff-filter=D` to include only deleted files.
115+
const passed = await lintStaged({
116+
config: {
117+
'*.js': 'prettier --list-different',
118+
'*': () => [
119+
/* despite empty array, this triggers processing of all files */
120+
],
121+
},
122+
cwd,
123+
diffFilter: 'D',
124+
})
125+
126+
expect(passed).toEqual(true)
127+
expect(console.printHistory()).toMatch('Running tasks for staged files...')
128+
expect(console.printHistory()).not.toMatch('fatal: pathspec')
129+
expect(console.printHistory()).not.toMatch('did not match any files')
94130

95131
console = globalConsoleTemp
96132
})

0 commit comments

Comments
 (0)
0