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