|
| 1 | +import './__mocks__/resolveConfig.js' |
| 2 | + |
| 3 | +import fs from 'node:fs/promises' |
| 4 | +import path from 'node:path' |
| 5 | + |
| 6 | +import { jest } from '@jest/globals' |
| 7 | + |
| 8 | +import { withGitIntegration } from './__utils__/withGitIntegration.js' |
| 9 | +import { prettierListDifferent } from './__fixtures__/configs.js' |
| 10 | +import { prettyJS } from './__fixtures__/files.js' |
| 11 | + |
| 12 | +jest.setTimeout(20000) |
| 13 | +jest.retryTimes(2) |
| 14 | + |
| 15 | +describe('lint-staged', () => { |
| 16 | + test( |
| 17 | + 'supports symlinked git dir', |
| 18 | + withGitIntegration(async ({ cwd, execGit, gitCommit, readFile, writeFile }) => { |
| 19 | + // Rename `.git` to `git` and add symbolic link pointing to it |
| 20 | + await fs.rename(path.resolve(cwd, '.git'), path.resolve(cwd, 'git')) |
| 21 | + await fs.symlink(path.resolve(cwd, 'git'), path.resolve(cwd, '.git'), 'dir') |
| 22 | + |
| 23 | + await writeFile('.lintstagedrc.json', JSON.stringify(prettierListDifferent)) |
| 24 | + |
| 25 | + // Stage pretty file |
| 26 | + await writeFile('test file.js', prettyJS) |
| 27 | + await execGit(['add', 'test file.js']) |
| 28 | + |
| 29 | + // Run lint-staged with `prettier --list-different` and commit pretty file |
| 30 | + await gitCommit() |
| 31 | + |
| 32 | + // Nothing is wrong, so a new commit is created |
| 33 | + expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2') |
| 34 | + expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('test') |
| 35 | + expect(await readFile('test file.js')).toEqual(prettyJS) |
| 36 | + }) |
| 37 | + ) |
| 38 | +}) |
0 commit comments