Skip to content

Commit

Permalink
Ported test suite: patterns-glob
Browse files Browse the repository at this point in the history
  • Loading branch information
pralkarz authored and fabiospampinato committed Feb 23, 2025
1 parent 8ad8648 commit c373e50
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
Expand Down
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-1/!file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.
bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-1/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.
bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-1/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.
bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-2/!b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.
bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-2/!dir.js/1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.foo
{}
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-2/!dir.js/2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.foo
{}
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-2/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.
bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-3/dir/.svn/in-svn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-3/dir/inside.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-3/outside.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-4/0/1/2/level-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-4/0/1/level-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-4/0/level-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
2 changes: 2 additions & 0 deletions test/__fixtures__/patterns-glob/fixtures-4/level-0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
.bar()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log( "*");
93 changes: 93 additions & 0 deletions test/__tests__/__snapshots__/patterns-glob.js.snap
Original file line number Diff line number Diff line change
@@ -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`] = `[]`;
156 changes: 156 additions & 0 deletions test/__tests__/patterns-glob.js
Original file line number Diff line number Diff line change
@@ -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,
});
});

0 comments on commit c373e50

Please sign in to comment.