single-file-cli 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.sh +1 -1
- package/deno.json +1 -1
- package/lib/cdp-client.js +29 -18
- package/lib/single-file-archive.js +4 -4
- package/lib/single-file-bundle.js +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/test/e2e/backend-fetch.test.js +92 -0
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.6.
|
|
1
|
+
export const version = "2.6.1";
|
package/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* global URL */
|
|
2
|
+
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { createServer } from "node:http";
|
|
6
|
+
import { execFile } from "node:child_process";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join, dirname } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
|
|
14
|
+
const execFileAsync = promisify(execFile);
|
|
15
|
+
const cliDirectory = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
16
|
+
|
|
17
|
+
test("the backend fetch presents the same user agent as the browser", { timeout: 120000 }, async () => {
|
|
18
|
+
const requests = [];
|
|
19
|
+
// no access-control-allow-origin, so the browser sends the request, refuses the
|
|
20
|
+
// response and the page falls back to the fetch made outside the browser
|
|
21
|
+
const resourceServer = createServer((request, response) => {
|
|
22
|
+
const { pathname } = new URL(request.url, "http://127.0.0.1");
|
|
23
|
+
requests.push({ headers: request.headers });
|
|
24
|
+
if (pathname === "/cors.css") {
|
|
25
|
+
response.writeHead(200, { "content-type": "text/css" }).end("h2 { color: rgb(11,22,33); }");
|
|
26
|
+
} else {
|
|
27
|
+
response.writeHead(404).end();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
await new Promise(resolve => resourceServer.listen(0, "127.0.0.1", resolve));
|
|
31
|
+
const styleUrl = "http://127.0.0.1:" + resourceServer.address().port + "/cors.css";
|
|
32
|
+
const server = createServer((request, response) => {
|
|
33
|
+
response.writeHead(200, { "content-type": "text/html" }).end(
|
|
34
|
+
"<html><head><link rel=\"stylesheet\" href=\"" + styleUrl + "\"></head><body><h2>styled</h2></body></html>");
|
|
35
|
+
});
|
|
36
|
+
await new Promise(resolve => server.listen(0, "localhost", resolve));
|
|
37
|
+
const directory = await mkdtemp(join(tmpdir(), "single-file-test-"));
|
|
38
|
+
try {
|
|
39
|
+
const outputPath = join(directory, "out.html");
|
|
40
|
+
const url = "http://localhost:" + server.address().port + "/top.html";
|
|
41
|
+
await execFileAsync(process.execPath, ["single-file-node.js", url, outputPath], { cwd: cliDirectory });
|
|
42
|
+
// the fetch made outside the browser sends no sec-fetch-dest; it does send
|
|
43
|
+
// sec-fetch-mode, which node sets on every request, so that one tells nothing
|
|
44
|
+
const browserRequest = requests.find(({ headers }) => headers["sec-fetch-dest"] !== undefined);
|
|
45
|
+
const backendRequest = requests.find(({ headers }) => headers["sec-fetch-dest"] === undefined);
|
|
46
|
+
assert.ok(browserRequest, "the resource was not fetched by the browser");
|
|
47
|
+
assert.ok(backendRequest, "the resource was not fetched outside the browser");
|
|
48
|
+
assert.equal(backendRequest.headers["user-agent"], browserRequest.headers["user-agent"],
|
|
49
|
+
"the backend fetch presented another user agent than the browser");
|
|
50
|
+
} finally {
|
|
51
|
+
await rm(directory, { recursive: true });
|
|
52
|
+
server.close();
|
|
53
|
+
resourceServer.close();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("the backend fetch presents the user agent given on the command line", { timeout: 120000 }, async () => {
|
|
58
|
+
const USER_AGENT = "SingleFileProbe/1.0";
|
|
59
|
+
const requests = [];
|
|
60
|
+
const resourceServer = createServer((request, response) => {
|
|
61
|
+
const { pathname } = new URL(request.url, "http://127.0.0.1");
|
|
62
|
+
requests.push({ headers: request.headers });
|
|
63
|
+
if (pathname === "/cors.css") {
|
|
64
|
+
response.writeHead(200, { "content-type": "text/css" }).end("h2 { color: rgb(11,22,33); }");
|
|
65
|
+
} else {
|
|
66
|
+
response.writeHead(404).end();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
await new Promise(resolve => resourceServer.listen(0, "127.0.0.1", resolve));
|
|
70
|
+
const styleUrl = "http://127.0.0.1:" + resourceServer.address().port + "/cors.css";
|
|
71
|
+
const server = createServer((request, response) => {
|
|
72
|
+
response.writeHead(200, { "content-type": "text/html" }).end(
|
|
73
|
+
"<html><head><link rel=\"stylesheet\" href=\"" + styleUrl + "\"></head><body><h2>styled</h2></body></html>");
|
|
74
|
+
});
|
|
75
|
+
await new Promise(resolve => server.listen(0, "localhost", resolve));
|
|
76
|
+
const directory = await mkdtemp(join(tmpdir(), "single-file-test-"));
|
|
77
|
+
try {
|
|
78
|
+
const outputPath = join(directory, "out.html");
|
|
79
|
+
const url = "http://localhost:" + server.address().port + "/top.html";
|
|
80
|
+
await execFileAsync(process.execPath, [
|
|
81
|
+
"single-file-node.js", url, outputPath,
|
|
82
|
+
"--user-agent", USER_AGENT
|
|
83
|
+
], { cwd: cliDirectory });
|
|
84
|
+
assert.ok(requests.length, "the resource was not fetched");
|
|
85
|
+
assert.ok(requests.every(({ headers }) => headers["user-agent"] === USER_AGENT),
|
|
86
|
+
"a request presented another user agent: " + JSON.stringify(requests.map(({ headers }) => headers["user-agent"])));
|
|
87
|
+
} finally {
|
|
88
|
+
await rm(directory, { recursive: true });
|
|
89
|
+
server.close();
|
|
90
|
+
resourceServer.close();
|
|
91
|
+
}
|
|
92
|
+
});
|