Skip to content

Commit 217074e

Browse files
authoredDec 21, 2020
fix: throw error when glob returns no results (#207)
1 parent 0c8cd4b commit 217074e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@types/chai": "^4.2.7",
39-
"@types/cheerio": "^0.22.10",
39+
"@types/cheerio": "0.22.22",
4040
"@types/finalhandler": "^1.1.0",
4141
"@types/glob": "^7.1.3",
4242
"@types/marked": "^1.2.0",

‎src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ export class LinkChecker extends EventEmitter {
173173
const paths: string[] = [];
174174
for (const path of options.path) {
175175
const expandedPaths = await glob(path);
176+
if (expandedPaths.length === 0) {
177+
throw new Error(
178+
`The provided glob "${path}" returned 0 results. The current working directory is "${process.cwd()}".`
179+
);
180+
}
176181
paths.push(...expandedPaths);
177182
}
178183
options.path = paths;

‎test/test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,13 @@ describe('linkinator', () => {
407407
assert.ok(results.passed);
408408
assert.strictEqual(results.links.length, 3);
409409
});
410+
411+
it('should throw if a glob provides no paths to scan', async () => {
412+
await assert.rejects(
413+
check({
414+
path: 'test/fixtures/basic/*.md',
415+
}),
416+
/returned 0 results/
417+
);
418+
});
410419
});

0 commit comments

Comments
 (0)
Please sign in to comment.