From 217074e13826b25c18a1398a5a468e064ea48c5f Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 21 Dec 2020 11:08:46 -0800 Subject: [PATCH] fix: throw error when glob returns no results (#207) --- package.json | 2 +- src/index.ts | 5 +++++ test/test.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3738016a..86436d53 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 912bda78..44d941d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; diff --git a/test/test.ts b/test/test.ts index af4337f4..185bafff 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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/ + ); + }); });