Skip to content

Commit

Permalink
fix: throw error when glob returns no results (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 21, 2020
1 parent 0c8cd4b commit 217074e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/cheerio": "^0.22.10",
"@types/cheerio": "0.22.22",
"@types/finalhandler": "^1.1.0",
"@types/glob": "^7.1.3",
"@types/marked": "^1.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export class LinkChecker extends EventEmitter {
const paths: string[] = [];
for (const path of options.path) {
const expandedPaths = await glob(path);
if (expandedPaths.length === 0) {
throw new Error(
`The provided glob "${path}" returned 0 results. The current working directory is "${process.cwd()}".`
);
}
paths.push(...expandedPaths);
}
options.path = paths;
Expand Down
9 changes: 9 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,13 @@ describe('linkinator', () => {
assert.ok(results.passed);
assert.strictEqual(results.links.length, 3);
});

it('should throw if a glob provides no paths to scan', async () => {
await assert.rejects(
check({
path: 'test/fixtures/basic/*.md',
}),
/returned 0 results/
);
});
});

0 comments on commit 217074e

Please sign in to comment.