Skip to content

Commit aa657ae

Browse files
committed
test: cover localhost no-cors cross-site requests
1 parent 4d3beb2 commit aa657ae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/e2e/cross-origin-request.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const webpack = require("webpack");
44
const Server = require("../../lib/Server");
55
const config = require("../fixtures/client-config/webpack.config");
66
const runBrowser = require("../helpers/run-browser");
7+
const { startServer } = require("../helpers/test-server");
78
const [port1, port2] = require("../ports-map")["cross-origin-request"];
89

910
describe("cross-origin requests", () => {
@@ -217,4 +218,25 @@ describe("cross-origin requests", () => {
217218
htmlServer.close();
218219
}
219220
});
221+
222+
it("should allow localhost for no-cors cross-site requests", async () => {
223+
const { page, server } = await startServer({
224+
allowedHosts: "auto",
225+
port: 0,
226+
});
227+
const { port } = server.options;
228+
await page.goto("about:blank");
229+
await page.evaluate((port) => {
230+
const iframe = document.createElement("iframe");
231+
const html = `
232+
<script src="http://localhost:${port}/main.js"></script>
233+
`;
234+
const blob = new Blob([html], { type: "text/html" });
235+
iframe.src = URL.createObjectURL(blob);
236+
document.body.append(iframe);
237+
}, port);
238+
await page.waitForTimeout(2000);
239+
const res = await page.goto(`http://localhost:${port}/main.js`);
240+
expect(res.status()).toBe(200);
241+
});
220242
});

0 commit comments

Comments
 (0)