webring 1.6.1-dev.2752 → 1.6.1-dev.2804

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.
@@ -1,18 +1,36 @@
1
- import { expect, test } from "bun:test";
1
+ import { afterAll, expect, test } from "bun:test";
2
2
  import { run } from "./index.js";
3
3
  import { tmpdir } from "node:os";
4
4
  import { mkdtemp } from "node:fs/promises";
5
5
  import path from "node:path";
6
- import express from "express";
7
- const app = express();
8
- app.use(express.static("src/testdata"));
9
- const port = Math.floor(Math.random() * 10_000) + 3000;
10
- app.listen(port, () => {
11
- console.warn(`Test server listening at http://localhost:${port.toString()}`);
6
+ const testDataDir = path.join(import.meta.dir, "testdata");
7
+ function assignedPort(port) {
8
+ if (port === undefined) {
9
+ throw new Error("Bun did not assign a test server port");
10
+ }
11
+ return port;
12
+ }
13
+ const server = Bun.serve({
14
+ hostname: "127.0.0.1",
15
+ port: 0,
16
+ async fetch(request) {
17
+ const url = new URL(request.url);
18
+ const file = Bun.file(path.join(testDataDir, path.basename(url.pathname)));
19
+ if (!(await file.exists())) {
20
+ return new Response("Not found", { status: 404 });
21
+ }
22
+ return new Response(file, {
23
+ headers: { "Content-Type": "application/rss+xml" },
24
+ });
25
+ },
26
+ });
27
+ const port = assignedPort(server.port);
28
+ console.warn(`Test server listening at http://127.0.0.1:${port.toString()}`);
29
+ afterAll(async () => {
30
+ await server.stop(true);
12
31
  });
13
- await new Promise((resolve) => setTimeout(resolve, 500));
14
32
  function createUrl(urlPath) {
15
- return `http://localhost:${port.toString()}/${urlPath}`;
33
+ return `http://127.0.0.1:${port.toString()}/${urlPath}`;
16
34
  }
17
35
  function createSources(count) {
18
36
  return Array.from({ length: count }, (_, i) => ({
@@ -20,6 +38,11 @@ function createSources(count) {
20
38
  url: createUrl(`rss-${(i + 1).toString()}.xml`),
21
39
  }));
22
40
  }
41
+ function normalizeSnapshotPorts(value) {
42
+ return JSON.stringify(value)
43
+ .replaceAll("127.0.0.1", "localhost")
44
+ .replaceAll(port.toString(), "PORT");
45
+ }
23
46
  test("it should fetch an RSS feed without caching", async () => {
24
47
  const config = {
25
48
  sources: createSources(19),
@@ -27,9 +50,7 @@ test("it should fetch an RSS feed without caching", async () => {
27
50
  truncate: 300,
28
51
  };
29
52
  const result = await run(config);
30
- let string = JSON.stringify(result);
31
- // replace the port number with a fixed value
32
- string = string.replaceAll(port.toString(), "PORT");
53
+ const string = normalizeSnapshotPorts(result);
33
54
  expect(string).toMatchSnapshot();
34
55
  });
35
56
  test("it should fetch several RSS feeds", async () => {
@@ -39,9 +60,7 @@ test("it should fetch several RSS feeds", async () => {
39
60
  truncate: 300,
40
61
  };
41
62
  const result = await run(config);
42
- let string = JSON.stringify(result);
43
- // replace the port number with a fixed value
44
- string = string.replaceAll(port.toString(), "PORT");
63
+ const string = normalizeSnapshotPorts(result);
45
64
  expect(string).toMatchSnapshot();
46
65
  });
47
66
  test("it should fetch an RSS feed with caching", async () => {
@@ -55,9 +74,7 @@ test("it should fetch an RSS feed with caching", async () => {
55
74
  },
56
75
  };
57
76
  const result = await run(config);
58
- let string = JSON.stringify(result);
59
- // replace the port number with a fixed value
60
- string = string.replaceAll(port.toString(), "PORT");
77
+ const string = normalizeSnapshotPorts(result);
61
78
  expect(string).toMatchSnapshot();
62
79
  });
63
80
  // https://sdorra.dev/posts/2024-02-12-vitest-tmpdir
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,G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EAAE,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,oDAAoD;AACpD,KAAK,UAAU,aAAa;IAC1B,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC9C,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "url": "https://github.com/shepherdjerred/monorepo/issues"
18
18
  },
19
19
  "type": "module",
20
- "version": "1.6.1-dev.2752",
20
+ "version": "1.6.1-dev.2804",
21
21
  "scripts": {
22
22
  "lint": "eslint src --cache",
23
23
  "build": "tsc",
package/src/index.test.ts CHANGED
@@ -1,23 +1,42 @@
1
- import { expect, test } from "bun:test";
1
+ import { afterAll, expect, test } from "bun:test";
2
2
  import type { Configuration } from "./types.ts";
3
3
  import { run } from "./index.ts";
4
4
  import { tmpdir } from "node:os";
5
5
  import { mkdtemp } from "node:fs/promises";
6
6
  import path from "node:path";
7
- import express from "express";
8
7
 
9
- const app = express();
10
- app.use(express.static("src/testdata"));
8
+ const testDataDir = path.join(import.meta.dir, "testdata");
9
+ function assignedPort(port: number | undefined): number {
10
+ if (port === undefined) {
11
+ throw new Error("Bun did not assign a test server port");
12
+ }
13
+ return port;
14
+ }
11
15
 
12
- const port = Math.floor(Math.random() * 10_000) + 3000;
13
- app.listen(port, () => {
14
- console.warn(`Test server listening at http://localhost:${port.toString()}`);
16
+ const server = Bun.serve({
17
+ hostname: "127.0.0.1",
18
+ port: 0,
19
+ async fetch(request) {
20
+ const url = new URL(request.url);
21
+ const file = Bun.file(path.join(testDataDir, path.basename(url.pathname)));
22
+ if (!(await file.exists())) {
23
+ return new Response("Not found", { status: 404 });
24
+ }
25
+ return new Response(file, {
26
+ headers: { "Content-Type": "application/rss+xml" },
27
+ });
28
+ },
15
29
  });
30
+ const port = assignedPort(server.port);
31
+
32
+ console.warn(`Test server listening at http://127.0.0.1:${port.toString()}`);
16
33
 
17
- await new Promise((resolve) => setTimeout(resolve, 500));
34
+ afterAll(async () => {
35
+ await server.stop(true);
36
+ });
18
37
 
19
38
  function createUrl(urlPath: string): string {
20
- return `http://localhost:${port.toString()}/${urlPath}`;
39
+ return `http://127.0.0.1:${port.toString()}/${urlPath}`;
21
40
  }
22
41
 
23
42
  function createSources(count: number): Configuration["sources"] {
@@ -27,6 +46,12 @@ function createSources(count: number): Configuration["sources"] {
27
46
  }));
28
47
  }
29
48
 
49
+ function normalizeSnapshotPorts(value: unknown): string {
50
+ return JSON.stringify(value)
51
+ .replaceAll("127.0.0.1", "localhost")
52
+ .replaceAll(port.toString(), "PORT");
53
+ }
54
+
30
55
  test("it should fetch an RSS feed without caching", async () => {
31
56
  const config: Configuration = {
32
57
  sources: createSources(19),
@@ -35,9 +60,7 @@ test("it should fetch an RSS feed without caching", async () => {
35
60
  };
36
61
 
37
62
  const result = await run(config);
38
- let string = JSON.stringify(result);
39
- // replace the port number with a fixed value
40
- string = string.replaceAll(port.toString(), "PORT");
63
+ const string = normalizeSnapshotPorts(result);
41
64
  expect(string).toMatchSnapshot();
42
65
  });
43
66
 
@@ -49,9 +72,7 @@ test("it should fetch several RSS feeds", async () => {
49
72
  };
50
73
 
51
74
  const result = await run(config);
52
- let string = JSON.stringify(result);
53
- // replace the port number with a fixed value
54
- string = string.replaceAll(port.toString(), "PORT");
75
+ const string = normalizeSnapshotPorts(result);
55
76
  expect(string).toMatchSnapshot();
56
77
  });
57
78
 
@@ -67,9 +88,7 @@ test("it should fetch an RSS feed with caching", async () => {
67
88
  };
68
89
 
69
90
  const result = await run(config);
70
- let string = JSON.stringify(result);
71
- // replace the port number with a fixed value
72
- string = string.replaceAll(port.toString(), "PORT");
91
+ const string = normalizeSnapshotPorts(result);
73
92
  expect(string).toMatchSnapshot();
74
93
  });
75
94