bits-to-dead-trees 2.0.0 → 2.1.0
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/.changeset/config.json +4 -1
- package/.github/workflows/build-docker-image-of-release.yml +1 -1
- package/.tool-versions +1 -1
- package/CHANGELOG.md +15 -0
- package/Dockerfile +1 -1
- package/README.md +2 -2
- package/app.js +2 -2
- package/package.json +10 -9
- package/test/app.test.ts +24 -1
- package/test/smoke.test.js +36 -0
package/.changeset/config.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
|
|
3
|
-
"changelog":
|
|
3
|
+
"changelog": [
|
|
4
|
+
"@changesets/changelog-github",
|
|
5
|
+
{ "repo": "rmehner/bits-to-dead-trees" }
|
|
6
|
+
],
|
|
4
7
|
"commit": false,
|
|
5
8
|
"fixed": [],
|
|
6
9
|
"linked": [],
|
package/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
nodejs
|
|
1
|
+
nodejs 18.14.2
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# bits-to-dead-trees
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`567b753`](https://github.com/rmehner/bits-to-dead-trees/commit/567b753ca21c6788b246b69b62c484790bc0d478) Thanks [@rmehner](https://github.com/rmehner)! - Upgrade to Playwright 1.13 and Node 18
|
|
8
|
+
|
|
9
|
+
This includes new browser versions too!
|
|
10
|
+
|
|
11
|
+
## 2.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 57d032f: Don't close browser if it's currently creating a PDF. We've added smoke tests, so
|
|
16
|
+
this shouldn't happen again. Sorry!
|
|
17
|
+
|
|
3
18
|
## 2.0.0
|
|
4
19
|
|
|
5
20
|
### Major Changes
|
package/Dockerfile
CHANGED
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ of that. It's using [Playwright](https://playwright.dev) in the background for t
|
|
|
11
11
|
|
|
12
12
|
### Requirements
|
|
13
13
|
|
|
14
|
-
1. Node
|
|
14
|
+
1. Node 18+
|
|
15
15
|
2. npm
|
|
16
16
|
|
|
17
17
|
### Installation
|
|
@@ -57,7 +57,7 @@ If you want to use it internally with docker-compose, this should give you a goo
|
|
|
57
57
|
```yml
|
|
58
58
|
services:
|
|
59
59
|
pdf:
|
|
60
|
-
image: ghcr.io/rmehner/bits-to-dead-trees:
|
|
60
|
+
image: ghcr.io/rmehner/bits-to-dead-trees:v2.1.0
|
|
61
61
|
ports:
|
|
62
62
|
- 8000:8000
|
|
63
63
|
```
|
package/app.js
CHANGED
|
@@ -54,10 +54,10 @@ const createPDF = async (
|
|
|
54
54
|
|
|
55
55
|
const response = await page.goto(url, gotoOptions);
|
|
56
56
|
if (response?.ok()) {
|
|
57
|
-
return page.pdf(pdfOptions);
|
|
57
|
+
return await page.pdf(pdfOptions);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
return Promise.reject({
|
|
60
|
+
return await Promise.reject({
|
|
61
61
|
error: true,
|
|
62
62
|
message: await response?.text(),
|
|
63
63
|
status: response?.status(),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bits-to-dead-trees",
|
|
3
3
|
"author": "Robin Mehner <robin@coding-robin.de>",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Turn HTML into PDF files",
|
|
6
6
|
"repository": "github:rmehner/bits-to-dead-trees",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"playwright"
|
|
12
12
|
],
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">= 18"
|
|
15
15
|
},
|
|
16
16
|
"main": "server.js",
|
|
17
17
|
"type": "module",
|
|
@@ -30,19 +30,20 @@
|
|
|
30
30
|
"ts-check": "npx tsc --noEmit"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"fastify": "^4.
|
|
34
|
-
"playwright-core": "^1.
|
|
33
|
+
"fastify": "^4.13.0",
|
|
34
|
+
"playwright-core": "^1.31.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
+
"@changesets/changelog-github": "^0.4.8",
|
|
37
38
|
"@changesets/cli": "^2.26.0",
|
|
38
39
|
"@types/lodash": "^4.14.191",
|
|
39
|
-
"eslint": "^8.
|
|
40
|
+
"eslint": "^8.34.0",
|
|
40
41
|
"eslint-config-prettier": "^8.6.0",
|
|
41
42
|
"nodemon": "^2.0.20",
|
|
42
|
-
"pino-pretty": "^9.
|
|
43
|
-
"prettier": "^2.8.
|
|
44
|
-
"tslib": "^2.
|
|
43
|
+
"pino-pretty": "^9.3.0",
|
|
44
|
+
"prettier": "^2.8.4",
|
|
45
|
+
"tslib": "^2.5.0",
|
|
45
46
|
"typescript-json-schema": "^0.55.0",
|
|
46
|
-
"vitest": "^0.28.
|
|
47
|
+
"vitest": "^0.28.5"
|
|
47
48
|
}
|
|
48
49
|
}
|
package/test/app.test.ts
CHANGED
|
@@ -50,7 +50,6 @@ describe("POST /pdf", () => {
|
|
|
50
50
|
pdf = vi.fn().mockResolvedValue(Buffer.from("pdf"));
|
|
51
51
|
newPage = vi.fn().mockResolvedValue({ goto: gotoMethod, pdf });
|
|
52
52
|
newContext = vi.fn().mockResolvedValue({ newPage });
|
|
53
|
-
close = vi.fn();
|
|
54
53
|
|
|
55
54
|
(chromium.launch as Mock<any[], any>).mockResolvedValue({
|
|
56
55
|
newContext,
|
|
@@ -223,4 +222,28 @@ describe("POST /pdf", () => {
|
|
|
223
222
|
|
|
224
223
|
expect(close).toHaveBeenCalled();
|
|
225
224
|
});
|
|
225
|
+
|
|
226
|
+
it("generates the pdf before closing the browser", async () => {
|
|
227
|
+
let i = 0;
|
|
228
|
+
|
|
229
|
+
pdf.mockImplementation(async () => {
|
|
230
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
231
|
+
|
|
232
|
+
return i++;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
close.mockImplementation(() => {
|
|
236
|
+
return i++;
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
await app.inject({
|
|
240
|
+
method: "POST",
|
|
241
|
+
url: "/pdf",
|
|
242
|
+
payload: {
|
|
243
|
+
url: "https://google.com",
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(pdf.mock.results[0].value).toBeLessThan(close.mock.results[0].value);
|
|
248
|
+
});
|
|
226
249
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import build from "../app";
|
|
4
|
+
const app = build();
|
|
5
|
+
|
|
6
|
+
describe("Smoke tests", () => {
|
|
7
|
+
it("sends the PDF on the success case", async () => {
|
|
8
|
+
const response = await app.inject({
|
|
9
|
+
method: "POST",
|
|
10
|
+
url: "/pdf",
|
|
11
|
+
payload: { url: "https://coding-robin.de" },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(response.payload.startsWith("%PDF")).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns an error object when the page could not be loaded", async () => {
|
|
18
|
+
const response = await app.inject({
|
|
19
|
+
method: "POST",
|
|
20
|
+
url: "/pdf",
|
|
21
|
+
payload: {
|
|
22
|
+
url: "http://httpbin.org/status/404",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(response.statusCode).toEqual(404);
|
|
27
|
+
const error = JSON.parse(response.body);
|
|
28
|
+
|
|
29
|
+
expect(error).toMatchObject({
|
|
30
|
+
error: true,
|
|
31
|
+
status: 404,
|
|
32
|
+
statusText: "NOT FOUND",
|
|
33
|
+
message: "",
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|