Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"specialist": "^1.4.5",
"tiny-editorconfig": "^1.0.0",
"tiny-jsonc": "^1.0.1",
"tiny-readdir-glob": "^1.22.24",
"tiny-readdir-glob": "^1.23.0",
"tiny-spinner": "^2.0.4",
"worktank": "^2.7.3",
"zeptomatch": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions,

if (!totalMatched && !totalIgnored) {
if (options.errorOnUnmatchedPattern) {
stderr.prefixed.error(`No files matching the given patterns were found`);
stderr.prefixed.error(`No files matching the given patterns were found.`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async function normalizeOptions(options: unknown, targets: unknown[]): Promise<O

const stdin = await getStdin();

if (!isString(stdin) && !globs.length) exit("Expected at least one target file/dir/glob");
if (!isString(stdin) && !globs.length) exit("Expected at least one target file/dir/glob.");

const check = "check" in options && !!options.check;
const list = "listDifferent" in options && !!options.listDifferent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
foo(


)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
foo(


)
1 change: 1 addition & 0 deletions test/__fixtures__/patterns/directory/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
Empty file.
1 change: 1 addition & 0 deletions test/__fixtures__/patterns/node_modules/node-module.js

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

1 change: 1 addition & 0 deletions test/__fixtures__/patterns/other-directory/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
1 change: 1 addition & 0 deletions test/__fixtures__/patterns/other-regular-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
1 change: 1 addition & 0 deletions test/__fixtures__/patterns/regular-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
82 changes: 82 additions & 0 deletions test/__tests__/__snapshots__/patterns.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`exits with an informative message when there are no patterns provided (stderr) 1`] = `
"
Expected at least one target file/dir/glob.
"
`;

exports[`exits with an informative message when there are no patterns provided (stdout) 1`] = `""`;

exports[`exits with an informative message when there are no patterns provided (write) 1`] = `[]`;

exports[`multiple patterns (stderr) 1`] = `""`;

exports[`multiple patterns (stdout) 1`] = `
"directory/file.js
directory/nested-directory/nested-directory-file.js
other-directory/file.js
other-directory/nested-directory/nested-directory-file.js"
`;

exports[`multiple patterns (write) 1`] = `[]`;

exports[`multiple patterns with a negated pattern (stderr) 1`] = `""`;

exports[`multiple patterns with a negated pattern (stdout) 1`] = `
"directory/file.js
other-directory/file.js
other-regular-modules.js
regular-module.js"
`;

exports[`multiple patterns with a negated pattern (write) 1`] = `[]`;

exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (stderr) 1`] = `""`;

exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (stdout) 1`] = `
"other-directory/file.js
other-directory/nested-directory/nested-directory-file.js
other-regular-modules.js
regular-module.js"
`;

exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (write) 1`] = `[]`;

exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (stderr) 1`] = `""`;

exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (stdout) 1`] = `
"node_modules/node-module.js
other-directory/file.js
other-directory/nested-directory/nested-directory-file.js
other-regular-modules.js
regular-module.js"
`;

exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (write) 1`] = `[]`;

exports[`multiple patterns with a negated pattern, ignores node_modules by default (stderr) 1`] = `""`;

exports[`multiple patterns with a negated pattern, ignores node_modules by default (stdout) 1`] = `
"other-directory/file.js
other-directory/nested-directory/nested-directory-file.js
other-regular-modules.js
regular-module.js"
`;

exports[`multiple patterns with a negated pattern, ignores node_modules by default (write) 1`] = `[]`;

exports[`multiple patterns with an extra non-existent pattern (stderr) 1`] = `""`;

exports[`multiple patterns with an extra non-existent pattern (stdout) 1`] = `
"directory/file.js
directory/nested-directory/nested-directory-file.js"
`;

exports[`multiple patterns with an extra non-existent pattern (write) 1`] = `[]`;

exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (stderr) 1`] = `"[error] No files matching the given patterns were found."`;

exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (stdout) 1`] = `""`;

exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (write) 1`] = `[]`;
65 changes: 65 additions & 0 deletions test/__tests__/patterns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { runCli } from "../utils";

describe("multiple patterns", () => {
runCli("patterns", ["directory/**/*.js", "other-directory/**/*.js", "-l"]).test({
status: 1,
});
});

describe("multiple patterns with an extra non-existent pattern", () => {
runCli("patterns", ["directory/**/*.js", "non-existent.js", "-l"]).test({
status: 1,
});
});

describe("multiple patterns with a negated pattern", () => {
runCli("patterns", ["**/*.js", "!**/nested-directory/**", "-l"]).test({
status: 1,
});
});

describe("multiple patterns with a negated pattern, ignores node_modules by default", () => {
runCli("patterns", ["**/*.js", "!directory/**", "-l"]).test({
status: 1,
});
});

// TODO: Handle leading `./` and `../` in patterns.
describe.skip("multiple patterns with a negated pattern and leading `./`, ignores node_modules by default", () => {
runCli("patterns", ["./**/*.js", "!./directory/**", "-l"]).test({
status: 1,
});
});

describe("multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag", () => {
runCli("patterns", ["**/*.js", "!directory/**", "-l", "--with-node-modules"]).test({
status: 1,
});
});

describe("exits with an informative message when there are no patterns provided", () => {
runCli("patterns").test({
status: 1,
});
});

describe("multiple patterns, throws an error and exits with a non-zero code when there are no matches", () => {
runCli("patterns", ["non-existent.js", "other-non-existent.js", "-l"]).test({
status: 1,
});
});

describe("file names with special characters", () => {
runCli("patterns-special-characters/square-brackets/", ["[with-square-brackets].js", "-l"]).test({
status: 1,
write: [],
stderr: "",
stdout: "[with-square-brackets].js",
});
runCli("patterns-special-characters/dots/", ["[...with-square-brackets-and-dots].js", "-l"]).test({
status: 1,
write: [],
stderr: "",
stdout: "[...with-square-brackets-and-dots].js",
});
});
Loading