-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e test for linting difficult filename with ESLint + Prett…
…ier (#1413)
- Loading branch information
Showing
6 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
const THIS_FILE_DIR = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
/** @returns the path to the `lint-staged` repo root */ | ||
export const getRepoRootPath = () => path.join(THIS_FILE_DIR, '../../') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import path from 'node:path' | ||
|
||
import { withGitIntegration } from '../integration/__utils__/withGitIntegration.js' | ||
import * as fileFixtures from '../integration/__fixtures__/files.js' | ||
import { getRepoRootPath } from '../__utils__/getRepoRootPath.js' | ||
|
||
import { getLintStagedExecutor } from './__utils__/getLintStagedExecutor.js' | ||
|
||
describe('lint-staged', () => { | ||
const REPO_ESLINT_CONFIG = path.join(getRepoRootPath(), '.eslintrc.json') | ||
|
||
const BASIC_CONFIG = { | ||
'*.js': [`eslint --config ${REPO_ESLINT_CONFIG} --fix`, 'prettier --write'], | ||
} | ||
|
||
test.each([['$test.js'], ['[test].js'], ['(test).js']])( | ||
'supports linting "%s" with ESLint + Prettier', | ||
async (filename) => | ||
withGitIntegration(async ({ cwd, execGit, readFile, writeFile }) => { | ||
const lintStaged = getLintStagedExecutor(cwd) | ||
|
||
await writeFile('.lintstagedrc.json', JSON.stringify(BASIC_CONFIG)) | ||
|
||
await writeFile(filename, fileFixtures.uglyJS) | ||
await execGit(['add', filename]) | ||
|
||
const result = await lintStaged() | ||
|
||
expect(result.exitCode).toEqual(0) | ||
|
||
expect(await readFile(filename)).toEqual(fileFixtures.prettyJS) | ||
}) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters