|
| 1 | +import '../integration/__mocks__/resolveConfig.js' |
| 2 | + |
| 3 | +import { jest } from '@jest/globals' |
| 4 | + |
| 5 | +import { withGitIntegration } from '../integration/__utils__/withGitIntegration.js' |
| 6 | +import * as fileFixtures from '../integration/__fixtures__/files.js' |
| 7 | +import * as configFixtures from '../integration/__fixtures__/configs.js' |
| 8 | + |
| 9 | +import { getLintStagedExecutor } from './__utils__/getLintStagedExecutor.js' |
| 10 | + |
| 11 | +jest.setTimeout(20000) |
| 12 | +jest.retryTimes(2) |
| 13 | + |
| 14 | +describe('lint-staged', () => { |
| 15 | + test( |
| 16 | + '--diff implies --no-stash', |
| 17 | + withGitIntegration(async ({ execGit, writeFile, cwd }) => { |
| 18 | + const lintStaged = getLintStagedExecutor(cwd) |
| 19 | + |
| 20 | + await execGit(['checkout', '-b', 'my-branch']) |
| 21 | + await writeFile('.lintstagedrc.json', JSON.stringify(configFixtures.prettierListDifferent)) |
| 22 | + await writeFile('test.js', fileFixtures.prettyJS) |
| 23 | + await execGit(['add', '.lintstagedrc.json']) |
| 24 | + await execGit(['add', 'test.js']) |
| 25 | + await execGit(['commit', '-m', 'test']) |
| 26 | + |
| 27 | + let res = await lintStaged() |
| 28 | + expect(res.stdout).toMatch('No staged files found.') |
| 29 | + |
| 30 | + res = await lintStaged('--stash') |
| 31 | + expect(res.stdout).toMatch('No staged files found.') |
| 32 | + |
| 33 | + res = await lintStaged('--no-stash') |
| 34 | + expect(res.stdout).toMatch('No staged files found.') |
| 35 | + expect(res.stderr).toMatch('Skipping backup because `--no-stash` was used.') |
| 36 | + |
| 37 | + res = await lintStaged('--diff=master...my-branch') |
| 38 | + expect(res.stderr).toMatch('Skipping backup because `--diff` was used.') |
| 39 | + |
| 40 | + try { |
| 41 | + await lintStaged('--diff=master...my-branch --stash') |
| 42 | + } catch (err) { |
| 43 | + expect(err.stderr).toMatch('lint-staged failed due to a git error.') |
| 44 | + } |
| 45 | + |
| 46 | + res = await lintStaged('--diff=master...my-branch --no-stash') |
| 47 | + expect(res.stderr).toMatch('Skipping backup because `--diff` was used.') |
| 48 | + }) |
| 49 | + ) |
| 50 | +}) |
0 commit comments