From c373e50a6c07630a07e0184db815e4ba2346a1d6 Mon Sep 17 00:00:00 2001 From: pralkarz <31964869+pralkarz@users.noreply.github.com> Date: Sun, 23 Feb 2025 16:44:47 +0100 Subject: [PATCH] Ported test suite: patterns-glob --- .vscode/settings.json | 2 +- .../patterns-glob/fixtures-1/!file.js | 2 + .../patterns-glob/fixtures-1/a.js | 2 + .../patterns-glob/fixtures-1/b.js | 2 + .../patterns-glob/fixtures-2/!b.js | 2 + .../patterns-glob/fixtures-2/!dir.js/1.css | 2 + .../patterns-glob/fixtures-2/!dir.js/2.css | 2 + .../patterns-glob/fixtures-2/a.js | 2 + .../fixtures-3/dir/.svn/in-svn.js | 2 + .../patterns-glob/fixtures-3/dir/inside.js | 2 + .../dir/node_modules/in-node_modules.js | 2 + .../patterns-glob/fixtures-3/outside.js | 2 + .../patterns-glob/fixtures-4/0/1/2/level-3.js | 2 + .../patterns-glob/fixtures-4/0/1/level-2.js | 2 + .../patterns-glob/fixtures-4/0/level-1.js | 2 + .../patterns-glob/fixtures-4/level-0.js | 2 + .../constructor/should-be-formatted.js | 1 + .../__snapshots__/patterns-glob.js.snap | 93 +++++++++++ test/__tests__/patterns-glob.js | 156 ++++++++++++++++++ 19 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 test/__fixtures__/patterns-glob/fixtures-1/!file.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-1/a.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-1/b.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-2/!b.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-2/!dir.js/1.css create mode 100644 test/__fixtures__/patterns-glob/fixtures-2/!dir.js/2.css create mode 100644 test/__fixtures__/patterns-glob/fixtures-2/a.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-3/dir/.svn/in-svn.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-3/dir/inside.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-3/dir/node_modules/in-node_modules.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-3/outside.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-4/0/1/2/level-3.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-4/0/1/level-2.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-4/0/level-1.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-4/level-0.js create mode 100644 test/__fixtures__/patterns-glob/fixtures-5/constructor/should-be-formatted.js create mode 100644 test/__tests__/__snapshots__/patterns-glob.js.snap create mode 100644 test/__tests__/patterns-glob.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 796b669..e4ca126 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - } + }, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" } diff --git a/test/__fixtures__/patterns-glob/fixtures-1/!file.js b/test/__fixtures__/patterns-glob/fixtures-1/!file.js new file mode 100644 index 0000000..0b118ad --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-1/!file.js @@ -0,0 +1,2 @@ +foo. +bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-1/a.js b/test/__fixtures__/patterns-glob/fixtures-1/a.js new file mode 100644 index 0000000..0b118ad --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-1/a.js @@ -0,0 +1,2 @@ +foo. +bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-1/b.js b/test/__fixtures__/patterns-glob/fixtures-1/b.js new file mode 100644 index 0000000..0b118ad --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-1/b.js @@ -0,0 +1,2 @@ +foo. +bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-2/!b.js b/test/__fixtures__/patterns-glob/fixtures-2/!b.js new file mode 100644 index 0000000..0b118ad --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-2/!b.js @@ -0,0 +1,2 @@ +foo. +bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/1.css b/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/1.css new file mode 100644 index 0000000..687c7f1 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/1.css @@ -0,0 +1,2 @@ +.foo +{} diff --git a/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/2.css b/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/2.css new file mode 100644 index 0000000..687c7f1 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-2/!dir.js/2.css @@ -0,0 +1,2 @@ +.foo +{} diff --git a/test/__fixtures__/patterns-glob/fixtures-2/a.js b/test/__fixtures__/patterns-glob/fixtures-2/a.js new file mode 100644 index 0000000..0b118ad --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-2/a.js @@ -0,0 +1,2 @@ +foo. +bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-3/dir/.svn/in-svn.js b/test/__fixtures__/patterns-glob/fixtures-3/dir/.svn/in-svn.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-3/dir/.svn/in-svn.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-3/dir/inside.js b/test/__fixtures__/patterns-glob/fixtures-3/dir/inside.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-3/dir/inside.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-3/dir/node_modules/in-node_modules.js b/test/__fixtures__/patterns-glob/fixtures-3/dir/node_modules/in-node_modules.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-3/dir/node_modules/in-node_modules.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-3/outside.js b/test/__fixtures__/patterns-glob/fixtures-3/outside.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-3/outside.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-4/0/1/2/level-3.js b/test/__fixtures__/patterns-glob/fixtures-4/0/1/2/level-3.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-4/0/1/2/level-3.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-4/0/1/level-2.js b/test/__fixtures__/patterns-glob/fixtures-4/0/1/level-2.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-4/0/1/level-2.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-4/0/level-1.js b/test/__fixtures__/patterns-glob/fixtures-4/0/level-1.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-4/0/level-1.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-4/level-0.js b/test/__fixtures__/patterns-glob/fixtures-4/level-0.js new file mode 100644 index 0000000..11d7772 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-4/level-0.js @@ -0,0 +1,2 @@ +foo +.bar() diff --git a/test/__fixtures__/patterns-glob/fixtures-5/constructor/should-be-formatted.js b/test/__fixtures__/patterns-glob/fixtures-5/constructor/should-be-formatted.js new file mode 100644 index 0000000..9c26669 --- /dev/null +++ b/test/__fixtures__/patterns-glob/fixtures-5/constructor/should-be-formatted.js @@ -0,0 +1 @@ +console.log( "*"); diff --git a/test/__tests__/__snapshots__/patterns-glob.js.snap b/test/__tests__/__snapshots__/patterns-glob.js.snap new file mode 100644 index 0000000..1a6c7d9 --- /dev/null +++ b/test/__tests__/__snapshots__/patterns-glob.js.snap @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`fixtures-1: Should match all files (stderr) 1`] = `""`; + +exports[`fixtures-1: Should match all files (stdout) 1`] = ` +"!file.js +a.js +b.js" +`; + +exports[`fixtures-1: Should match all files (write) 1`] = `[]`; + +exports[`fixtures-1: Should match files except \`a.js\` (stderr) 1`] = `""`; + +exports[`fixtures-1: Should match files except \`a.js\` (stdout) 1`] = ` +"!file.js +b.js" +`; + +exports[`fixtures-1: Should match files except \`a.js\` (write) 1`] = `[]`; + +exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (stderr) 1`] = `""`; + +exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (stdout) 1`] = ` +"!b.js +a.js" +`; + +exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (write) 1`] = `[]`; + +exports[`fixtures-2: Should only match \`!b.js\` (stderr) 1`] = `""`; + +exports[`fixtures-2: Should only match \`!b.js\` (stdout) 1`] = `"!b.js"`; + +exports[`fixtures-2: Should only match \`!b.js\` (write) 1`] = `[]`; + +exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (stderr) 1`] = `""`; + +exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (stdout) 1`] = ` +"dir/inside.js +dir/node_modules/in-node_modules.js +outside.js" +`; + +exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (write) 1`] = `[]`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (stderr) 1`] = `""`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (stdout) 1`] = ` +"dir/.svn/in-svn.js +outside.js" +`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (write) 1`] = `[]`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (stderr) 1`] = `""`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (stdout) 1`] = `"outside.js"`; + +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (write) 1`] = `[]`; + +exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (stderr) 1`] = `""`; + +exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (stdout) 1`] = ` +"dir/inside.js +outside.js" +`; + +exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (write) 1`] = `[]`; + +exports[`fixtures-4: Should match \`level-1.js\` #2 (stderr) 1`] = `""`; + +exports[`fixtures-4: Should match \`level-1.js\` #2 (stdout) 1`] = `"0/level-1.js"`; + +exports[`fixtures-4: Should match \`level-1.js\` #2 (write) 1`] = `[]`; + +exports[`fixtures-4: Should match \`level-1.js\` #3 (stderr) 1`] = `""`; + +exports[`fixtures-4: Should match \`level-1.js\` #3 (stdout) 1`] = `"0/level-1.js"`; + +exports[`fixtures-4: Should match \`level-1.js\` #3 (write) 1`] = `[]`; + +exports[`fixtures-4: Should match \`level-1.js\` (stderr) 1`] = `""`; + +exports[`fixtures-4: Should match \`level-1.js\` (stdout) 1`] = `"0/level-1.js"`; + +exports[`fixtures-4: Should match \`level-1.js\` (write) 1`] = `[]`; + +exports[`should not ignore file paths contains object prototype keys (stderr) 1`] = `""`; + +exports[`should not ignore file paths contains object prototype keys (stdout) 1`] = `"constructor/should-be-formatted.js"`; + +exports[`should not ignore file paths contains object prototype keys (write) 1`] = `[]`; diff --git a/test/__tests__/patterns-glob.js b/test/__tests__/patterns-glob.js new file mode 100644 index 0000000..6e88d35 --- /dev/null +++ b/test/__tests__/patterns-glob.js @@ -0,0 +1,156 @@ +import { runCli } from "../utils"; + +/* +fixtures-1/ +├─ !file.js +├─ a.js +└─ b.js +*/ + +describe("fixtures-1: Should match all files", () => { + runCli("patterns-glob/fixtures-1", [ + "*.js", + "!file.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("fixtures-1: Should match files except `a.js`", () => { + runCli("patterns-glob/fixtures-1", [ + "*.js", + "!a.js", + "-l", + ]).test({ + status: 1, + }); +}); + +/* + fixtures-2/ + ├─ a.js + ├─ !b.js + └─ !dir.js/ + ├─ 1.css + └─ 2.css +*/ + +describe("fixtures-2: Should match `a.js` and `!b.js`", () => { + runCli("patterns-glob/fixtures-2", [ + "*.js", + "!b.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("fixtures-2: Should only match `!b.js`", () => { + runCli("patterns-glob/fixtures-2", [ + "*.js", + "!a.js", + "-l", + ]).test({ + status: 1, + }); +}); + +/* + fixtures-3/ + ├─ outside.js + └─ dir + ├─ inside.js + ├─ node_modules/ + │ └─in-node_modules.js + └─ .svn/ + └─in-svn.js +*/ + +describe("fixtures-3: Should match `outside.js`, `dir/inside.js` and `dir/node_modules/in-node_modules.js`", () => { + runCli("patterns-glob/fixtures-3", [ + "**/*.js", + "-l", + "--with-node-modules" + ]).test({ + status: 1, + }); +}); + +describe("fixtures-3: Should only match `outside.js` and `dir/inside.js`", () => { + runCli("patterns-glob/fixtures-3", [ + "**/*.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("fixtures-3: Should not exclude `.svn` when specified explicitly", () => { + describe("(existing)", () => { + runCli("patterns-glob/fixtures-3", [ + "*.js", + "dir/.svn/in-svn.js", + "-l", + ]).test({ + status: 1, + }); + }); + + describe("(nonexisting)", () => { + runCli("patterns-glob/fixtures-3", [ + "*.js", + ".svn/in-svn.js", + "-l", + ]).test({ + status: 1, + }); + }); +}); + +/* + fixtures-4/ + ├─ level-0.js + └─ 0 + ├─ level-1.js + └─ 1/ + ├─ level-2.js + └─ 2/ + └─ level-3.js +*/ + +describe("fixtures-4: Should match `level-1.js`", () => { + runCli("patterns-glob/fixtures-4", [ + "./0/./level-1.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("fixtures-4: Should match `level-1.js` #2", () => { + runCli("patterns-glob/fixtures-4", [ + "./0/1/2/../../level-1.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("fixtures-4: Should match `level-1.js` #3", () => { + runCli("patterns-glob/fixtures-4", [ + "./0/non-exists-dir/2/../../level-1.js", + "-l", + ]).test({ + status: 1, + }); +}); + +describe("should not ignore file paths contains object prototype keys", () => { + runCli("patterns-glob/fixtures-5", [ + "./constructor/should-be-formatted.js", + "-l" + ]).test({ + status: 1, + }); +});