Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/puppeteer_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions tests/examples/other/exclude-url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html lang="en">

<head>
<meta charset="utf-8">
</head>

<body>
<a href="/foo.html">Foo</a>
<a href="/bar.html">Bar</a>
<a href="/baz.html">Baz</a>
</body>

</html>
21 changes: 21 additions & 0 deletions tests/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {});
Expand Down