|
| 1 | +import fs from "node:fs/promises"; |
| 2 | +import { getFixturesPath, runCli } from "../utils"; |
| 3 | + |
| 4 | +// `.js` files are ignored in `.gitignore` |
| 5 | +const files = [ |
| 6 | + "ignore-path/ignore-path-test/ignored-by-customignore.js", |
| 7 | + "ignore-path/ignore-path-test/ignored-by-gitignore.js", |
| 8 | + "ignore-path/ignore-path-test/ignored-by-prettierignore.js", |
| 9 | +].map(getFixturesPath); |
| 10 | + |
| 11 | +const clean = () => |
| 12 | + Promise.all(files.map((file) => fs.rm(file, { force: true }))); |
| 13 | +const setup = () => |
| 14 | + Promise.all(files.map((file) => fs.writeFile(file, " a+ b"))); |
| 15 | + |
| 16 | +beforeAll(setup); |
| 17 | +afterAll(clean); |
| 18 | + |
| 19 | +const getUnformattedFiles = async (args) => { |
| 20 | + const { stdout } = await runCli("ignore-path/ignore-path-test/", [ |
| 21 | + "**/*.js", |
| 22 | + "-l", |
| 23 | + ...args, |
| 24 | + ]); |
| 25 | + return stdout ? stdout.split("\n").sort() : []; |
| 26 | +}; |
| 27 | + |
| 28 | +test("custom ignore path", async () => { |
| 29 | + expect(await getUnformattedFiles(["--ignore-path", ".customignore"])).toEqual( |
| 30 | + ["ignored-by-gitignore.js", "ignored-by-prettierignore.js"], |
| 31 | + ); |
| 32 | +}); |
| 33 | + |
| 34 | +test("ignore files by .prettierignore and .gitignore by default", async () => { |
| 35 | + expect( |
| 36 | + await getUnformattedFiles(["--ignore-path", ".non-exists-ignore-file"]), |
| 37 | + ).toEqual([ |
| 38 | + "ignored-by-customignore.js", |
| 39 | + "ignored-by-gitignore.js", |
| 40 | + "ignored-by-prettierignore.js", |
| 41 | + ]); |
| 42 | + expect(await getUnformattedFiles([])).toEqual([]); |
| 43 | +}); |
| 44 | + |
| 45 | +test("multiple `--ignore-path`", async () => { |
| 46 | + expect( |
| 47 | + await getUnformattedFiles([ |
| 48 | + "--ignore-path", |
| 49 | + ".customignore", |
| 50 | + "--ignore-path", |
| 51 | + ".prettierignore", |
| 52 | + "--ignore-path", |
| 53 | + ".non-exists-ignore-file", |
| 54 | + ]), |
| 55 | + ).toEqual(["ignored-by-gitignore.js"]); |
| 56 | +}); |
0 commit comments