diff --git a/test/__fixtures__/ignore-in-subdirectories/.prettierignore b/test/__fixtures__/ignore-in-subdirectories/.prettierignore new file mode 100644 index 0000000..eea9c1c --- /dev/null +++ b/test/__fixtures__/ignore-in-subdirectories/.prettierignore @@ -0,0 +1 @@ +web1/ignore-me diff --git a/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/should-ignore.js b/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/should-ignore.js new file mode 100644 index 0000000..3bef913 --- /dev/null +++ b/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/should-ignore.js @@ -0,0 +1 @@ +var x = 'this should not be formatted'; diff --git a/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/subdirectory/should-ignore.js b/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/subdirectory/should-ignore.js new file mode 100644 index 0000000..3bef913 --- /dev/null +++ b/test/__fixtures__/ignore-in-subdirectories/web1/ignore-me/subdirectory/should-ignore.js @@ -0,0 +1 @@ +var x = 'this should not be formatted'; diff --git a/test/__fixtures__/ignore-in-subdirectories/web1/should-not-ignore.js b/test/__fixtures__/ignore-in-subdirectories/web1/should-not-ignore.js new file mode 100644 index 0000000..0bcbead --- /dev/null +++ b/test/__fixtures__/ignore-in-subdirectories/web1/should-not-ignore.js @@ -0,0 +1 @@ +var x = 'this should be formatted'; diff --git a/test/__fixtures__/ignore-in-subdirectories/web2/should-not-ignore.js b/test/__fixtures__/ignore-in-subdirectories/web2/should-not-ignore.js new file mode 100644 index 0000000..0bcbead --- /dev/null +++ b/test/__fixtures__/ignore-in-subdirectories/web2/should-not-ignore.js @@ -0,0 +1 @@ +var x = 'this should be formatted'; diff --git a/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap b/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap new file mode 100644 index 0000000..49a61e6 --- /dev/null +++ b/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`formats files when executing in a subdirectory (stderr) 1`] = `""`; + +exports[`formats files when executing in a subdirectory (stderr) 2`] = `""`; + +exports[`formats files when executing in a subdirectory (stdout) 1`] = `"should-not-ignore.js"`; + +exports[`formats files when executing in a subdirectory (stdout) 2`] = `"should-not-ignore.js"`; + +exports[`formats files when executing in a subdirectory (write) 1`] = `[]`; + +exports[`formats files when executing in a subdirectory (write) 2`] = `[]`; + +exports[`formats files when executing in a subdirectory and using stdin (stderr) 1`] = `""`; + +exports[`formats files when executing in a subdirectory and using stdin (write) 1`] = `[]`; + +exports[`ignore files when executing in a subdirectory and using stdin (stderr) 1`] = `""`; + +exports[`ignore files when executing in a subdirectory and using stdin (write) 1`] = `[]`; + +exports[`ignores files when executing in a subdirectory (stderr) 1`] = `""`; + +exports[`ignores files when executing in a subdirectory (stderr) 2`] = `""`; + +exports[`ignores files when executing in a subdirectory (stdout) 1`] = `""`; + +exports[`ignores files when executing in a subdirectory (stdout) 2`] = `""`; + +exports[`ignores files when executing in a subdirectory (write) 1`] = `[]`; + +exports[`ignores files when executing in a subdirectory (write) 2`] = `[]`; diff --git a/test/__tests__/ignore-in-subdirectories.js b/test/__tests__/ignore-in-subdirectories.js new file mode 100644 index 0000000..6f49003 --- /dev/null +++ b/test/__tests__/ignore-in-subdirectories.js @@ -0,0 +1,72 @@ +import { runCli } from "../utils"; + +describe("ignores files when executing in a subdirectory", () => { + runCli("ignore-in-subdirectories/web1", [ + "ignore-me/should-ignore.js", + "--ignore-path", + "../.prettierignore", + "-l", + ]).test({ + status: 0, + }); + + runCli("ignore-in-subdirectories/web1", [ + "ignore-me/subdirectory/should-ignore.js", + "--ignore-path", + "../.prettierignore", + "-l", + ]).test({ + status: 0, + }); +}); + +describe("formats files when executing in a subdirectory", () => { + runCli("ignore-in-subdirectories/web1", [ + "should-not-ignore.js", + "--ignore-path", + "../.prettierignore", + "-l", + ]).test({ + status: 1, + }); + + runCli("ignore-in-subdirectories/web2", [ + "should-not-ignore.js", + "--ignore-path", + "../.prettierignore", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("ignore files when executing in a subdirectory and using stdin", () => { + runCli( + "ignore-in-subdirectories/web1", + [ + "--ignore-path", + "../.prettierignore", + "--stdin-filepath", + "ignore-me/example.js", + ], + { + input: "hello_world( );", + }, + ).test({ + stdout: "hello_world();", + status: 0, + }); +}); + +describe("formats files when executing in a subdirectory and using stdin", () => { + runCli( + "ignore-in-subdirectories/web1", + ["--ignore-path", "../.prettierignore", "--stdin-filepath", "example.js"], + { + input: "hello_world( );", + }, + ).test({ + stdout: "hello_world();", + status: 0, + }); +});