diff --git a/src/puppeteer_utils.js b/src/puppeteer_utils.js index 820cded0..bc387187 100644 --- a/src/puppeteer_utils.js +++ b/src/puppeteer_utils.js @@ -184,7 +184,10 @@ const crawl = async opt => { // Port can be null, therefore we need the null check const isOnAppPort = port && port.toString() === options.port.toString(); - if (hostname === "localhost" && isOnAppPort && !uniqueUrls.has(newUrl) && !streamClosed) { + // Do not add excluded urls to the queue + const isExcluded = options.exclude && options.exclude.includes(newUrl) + + if (hostname === "localhost" && isOnAppPort && !uniqueUrls.has(newUrl) && !streamClosed && !isExcluded) { uniqueUrls.add(newUrl); enqued++; queue.write(newUrl); diff --git a/tests/examples/other/exclude-url.html b/tests/examples/other/exclude-url.html new file mode 100644 index 00000000..58495720 --- /dev/null +++ b/tests/examples/other/exclude-url.html @@ -0,0 +1,13 @@ + + + + + + + + Foo + Bar + Baz + + + \ No newline at end of file diff --git a/tests/run.test.js b/tests/run.test.js index a39a63ae..32170c8b 100644 --- a/tests/run.test.js +++ b/tests/run.test.js @@ -589,6 +589,27 @@ describe("history.pushState two redirects to the same file", () => { }); }); +describe("excludes urls in options.exclude array", () => { + const source = "tests/examples/other"; + const include = ["/exclude-url.html"]; + + const exclude = ["http://localhost:45671/bar.html", "http://localhost:45671/baz.html"] + + const { fs, filesCreated, names } = mockFs(); + + beforeAll(() => snapRun(fs, { source, include, exclude, port: 45671 })); + test("should not crawl urls in exclude", () => { + expect(filesCreated()).toEqual(3); + expect(names()).toEqual( + expect.arrayContaining([ + `/${source}/exclude-url.html`, + `/${source}/foo.html`, + `/${source}/404.html`, + ]) + ); + }); +}); + describe.skip("publicPath", () => {}); describe.skip("skipThirdPartyRequests", () => {});