Skip to content

Commit 0fd718b

Browse files
committed
migrate remaining e2e tests to Deno
1 parent 1038049 commit 0fd718b

19 files changed

Lines changed: 352 additions & 332 deletions

tests/bun/const.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
export const PRISME_URL = 'http://prisme.localhost'
2-
export const PRISME_ADMIN_URL = 'http://prisme.localhost:9090'
1+
export const PRISME_URL = "http://prisme.localhost";
2+
export const PRISME_ADMIN_URL = "http://prisme.localhost:9090";
33

4-
export const PRISME_API_URL = PRISME_URL + '/api/v1'
5-
export const PRISME_PAGEVIEWS_URL = PRISME_API_URL + '/events/pageviews'
6-
export const PRISME_NOSCRIPT_PAGEVIEWS_URL = PRISME_API_URL + '/noscript/events/pageviews'
7-
export const PRISME_CUSTOM_EVENTS_URL = PRISME_API_URL + '/events/custom'
8-
export const PRISME_NOSCRIPT_CUSTOM_EVENTS_URL = PRISME_API_URL + '/noscript/events/custom'
9-
export const PRISME_OUTBOUND_LINK_EVENTS_URL = PRISME_API_URL + '/events/outbound-links'
10-
export const PRISME_NOSCRIPT_OUTBOUND_LINK_EVENTS_URL = PRISME_API_URL + '/noscript/events/outbound-links'
11-
export const PRISME_FILE_DOWNLOAD_EVENTS_URL = PRISME_API_URL + '/events/file-downloads'
4+
export const PRISME_API_URL = PRISME_URL + "/api/v1";
5+
export const PRISME_PAGEVIEWS_URL = PRISME_API_URL + "/events/pageviews";
6+
export const PRISME_NOSCRIPT_PAGEVIEWS_URL = PRISME_API_URL +
7+
"/noscript/events/pageviews";
8+
export const PRISME_CUSTOM_EVENTS_URL = PRISME_API_URL + "/events/custom";
9+
export const PRISME_NOSCRIPT_CUSTOM_EVENTS_URL = PRISME_API_URL +
10+
"/noscript/events/custom";
11+
export const PRISME_OUTBOUND_LINK_EVENTS_URL = PRISME_API_URL +
12+
"/events/outbound-links";
13+
export const PRISME_NOSCRIPT_OUTBOUND_LINK_EVENTS_URL = PRISME_API_URL +
14+
"/noscript/events/outbound-links";
15+
export const PRISME_FILE_DOWNLOAD_EVENTS_URL = PRISME_API_URL +
16+
"/events/file-downloads";
1217

13-
export const PRISME_METRICS_URL = PRISME_ADMIN_URL + '/metrics'
18+
export const PRISME_METRICS_URL = PRISME_ADMIN_URL + "/metrics";
1419

15-
export const TIMESTAMP_REGEX = /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/
16-
export const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
17-
export const UUID_V7_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
18-
export const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/
19-
export const PRISME_VISITOR_ID_REGEX = /prisme_.+/
20+
export const TIMESTAMP_REGEX = /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/;
21+
export const UUID_V4_REGEX =
22+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
23+
export const UUID_V7_REGEX =
24+
/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
25+
export const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
26+
export const PRISME_VISITOR_ID_REGEX = /prisme_.+/;

tests/bun/deno.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"imports": {
33
"@std/expect": "jsr:@std/expect@1",
4-
"@faker-js/faker": "npm:@faker-js/faker@8",
5-
"@clickhouse/client-web": "npm:@clickhouse/client-web@1"
4+
"@faker-js/faker": "npm:@faker-js/faker@8",
5+
"@clickhouse/client-web": "npm:@clickhouse/client-web@1"
66
},
7-
"compilerOptions": {
8-
"lib": ["deno.ns", "dom"]
9-
}
7+
"compilerOptions": {
8+
"lib": ["deno.ns", "dom"]
9+
}
1010
}

tests/bun/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ services:
1515
default:
1616
aliases:
1717
- "clickhouse.localhost"
18-

tests/bun/trusted-proxy-custom-header/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test:
1818
-f ./docker-compose.test.yml \
1919
up \
2020
--abort-on-container-exit \
21-
--exit-code-from bun
21+
--exit-code-from deno
2222

2323
.PHONY: clean
2424
clean:

tests/bun/trusted-proxy-custom-header/docker-compose.test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
2-
bun:
3-
image: docker.io/oven/bun
4-
command: sh -c "bun install && cd ./trusted-proxy-custom-header && exec bun test"
5-
working_dir: /data
2+
deno:
3+
image: docker.io/denoland/deno:2.5.2
4+
command: deno test --allow-net
5+
working_dir: /data/trusted-proxy-custom-header
66
volumes:
77
- ..:/data
88
- prisme_logs:/prisme_logs:ro
Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
import { test, expect } from 'bun:test'
2-
import { PRISME_PAGEVIEWS_URL } from '../const'
3-
import { faker } from '@faker-js/faker'
1+
import { expect } from "@std/expect";
2+
import { faker } from "@faker-js/faker";
43

5-
const seed = new Date().getTime()
6-
console.log('faker seed', seed)
7-
faker.seed(seed)
4+
import { PRISME_PAGEVIEWS_URL } from "../const.ts";
5+
import { sleep } from "../utils.ts";
86

9-
test('more than 60 requests per minute are rejected', async () => {
10-
const clientIp = faker.internet.ip()
7+
const seed = new Date().getTime();
8+
console.log("faker seed", seed);
9+
faker.seed(seed);
10+
11+
Deno.test("more than 60 requests per minute are rejected", async () => {
12+
const clientIp = faker.internet.ip();
1113

1214
for (let i = 0; i < 100; i++) {
1315
const response = await fetch(PRISME_PAGEVIEWS_URL, {
14-
method: 'POST',
16+
method: "POST",
1517
headers: {
16-
Origin: 'http://mywebsite.localhost',
17-
'X-Custom-Forwarded-For': clientIp,
18-
'X-Prisme-Referrer': 'http://mywebsite.localhost'
19-
}
20-
})
18+
Origin: "http://mywebsite.localhost",
19+
"X-Custom-Forwarded-For": clientIp,
20+
"X-Prisme-Referrer": "http://mywebsite.localhost",
21+
},
22+
});
2123
if (i < 60) {
22-
expect(response.status).toBe(200)
24+
expect(response.status).toBe(200);
2325
} else {
24-
expect(response.status).toBe(429)
26+
expect(response.status).toBe(429);
2527
}
2628
}
2729

2830
// Wait a minute.
29-
Bun.sleepSync(60 * 1000)
31+
await sleep(60 * 1000);
3032

3133
const response = await fetch(PRISME_PAGEVIEWS_URL, {
32-
method: 'POST',
34+
method: "POST",
3335
headers: {
34-
Origin: 'http://mywebsite.localhost',
35-
'X-Custom-Forwarded-For': clientIp,
36-
'X-Prisme-Referrer': 'http://mywebsite.localhost'
37-
}
38-
})
39-
expect(response.status).toBe(200)
40-
}, { timeout: 120 * 1000 })
36+
Origin: "http://mywebsite.localhost",
37+
"X-Custom-Forwarded-For": clientIp,
38+
"X-Prisme-Referrer": "http://mywebsite.localhost",
39+
},
40+
});
41+
expect(response.status).toBe(200);
42+
});
4143

42-
test('requests are rate limited based on X-Custom-Forwarded-For header', async () => {
44+
Deno.test("requests are rate limited based on X-Custom-Forwarded-For header", async () => {
4345
for (let i = 0; i < 100; i++) {
4446
const response = await fetch(PRISME_PAGEVIEWS_URL, {
45-
method: 'POST',
47+
method: "POST",
4648
headers: {
47-
Origin: 'http://mywebsite.localhost',
48-
'X-Custom-Forwarded-For': faker.internet.ip(),
49-
'X-Prisme-Referrer': 'http://mywebsite.localhost'
50-
}
51-
})
52-
expect(response.status).toBe(200)
49+
Origin: "http://mywebsite.localhost",
50+
"X-Custom-Forwarded-For": faker.internet.ip(),
51+
"X-Prisme-Referrer": "http://mywebsite.localhost",
52+
},
53+
});
54+
expect(response.status).toBe(200);
5355
}
54-
})
56+
});
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
import { test, expect } from 'bun:test'
2-
import { UUID_V4_REGEX } from '../const'
1+
import { expect } from "@std/expect";
2+
import { UUID_V4_REGEX } from "../const.ts";
33

4-
test('X-Request-Id is used when present', async () => {
5-
const requestId = 'foo'
4+
Deno.test("X-Request-Id is used when present", async () => {
5+
const requestId = "foo";
66

77
// Generate an access log.
8-
await fetch('http://prisme.localhost/', {
8+
await fetch("http://prisme.localhost/", {
99
headers: {
10-
'X-Custom-Request-Id': requestId
11-
}
12-
})
10+
"X-Custom-Request-Id": requestId,
11+
},
12+
});
1313

1414
// Read access log file.
15-
const file = Bun.file('/prisme_logs/access.log')
16-
const text = await file.text()
17-
const lines = text.split('\n').filter((l) => l !== '')
18-
const lastLogLine = lines[lines.length - 1]
19-
const lastLog = JSON.parse(lastLogLine)
15+
const text = await Deno.readTextFile("/prisme_logs/access.log");
16+
const lines = text.split("\n").filter((l) => l !== "");
17+
const lastLogLine = lines[lines.length - 1];
18+
const lastLog = JSON.parse(lastLogLine);
2019

21-
expect(lastLog.request_id).toBe(requestId)
22-
})
20+
expect(lastLog.request_id).toBe(requestId);
21+
});
2322

24-
test('Random UUID v4 is used when X-Custom-Request-Id is missing', async () => {
23+
Deno.test("Random UUID v4 is used when X-Custom-Request-Id is missing", async () => {
2524
// Generate an access log.
26-
await fetch('http://prisme.localhost/')
25+
await fetch("http://prisme.localhost/");
2726

2827
// Read access log file.
29-
const file = Bun.file('/prisme_logs/access.log')
30-
const text = await file.text()
31-
const lines = text.split('\n').filter((l) => l !== '')
32-
const lastLogLine = lines[lines.length - 1]
33-
const lastLog = JSON.parse(lastLogLine)
28+
const text = await Deno.readTextFile("/prisme_logs/access.log");
29+
const lines = text.split("\n").filter((l) => l !== "");
30+
const lastLogLine = lines[lines.length - 1];
31+
const lastLog = JSON.parse(lastLogLine);
3432

35-
expect(lastLog.request_id).toMatch(UUID_V4_REGEX)
36-
})
33+
expect(lastLog.request_id).toMatch(UUID_V4_REGEX);
34+
});
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
import { test, expect } from 'bun:test'
1+
import { expect } from "@std/expect";
22

3-
test('X-Custom-Forwarded-For is used when present', async () => {
4-
const sourceIp = '10.127.42.1'
3+
Deno.test("X-Custom-Forwarded-For is used when present", async () => {
4+
const sourceIp = "10.127.42.1";
55

66
// Generate an access log.
7-
await fetch('http://prisme.localhost/', {
7+
await fetch("http://prisme.localhost/", {
88
headers: {
9-
'X-Custom-Forwarded-For': sourceIp
10-
}
11-
})
9+
"X-Custom-Forwarded-For": sourceIp,
10+
},
11+
});
1212

1313
// Read access log file.
14-
const file = Bun.file('/prisme_logs/access.log')
15-
const text = await file.text()
16-
const lines = text.split('\n').filter((l) => l !== '')
17-
const lastLogLine = lines[lines.length - 1]
18-
const lastLog = JSON.parse(lastLogLine)
14+
const text = await Deno.readTextFile("/prisme_logs/access.log");
15+
const lines = text.split("\n").filter((l) => l !== "");
16+
const lastLogLine = lines[lines.length - 1];
17+
const lastLog = JSON.parse(lastLogLine);
1918

20-
expect(lastLog.source_ip).toBe(sourceIp)
21-
})
19+
expect(lastLog.source_ip).toBe(sourceIp);
20+
});
2221

23-
test('Real IP is used when X-Custom-Forwarded-For is missing', async () => {
22+
Deno.test("Real IP is used when X-Custom-Forwarded-For is missing", async () => {
2423
// Generate an access log.
25-
await fetch('http://prisme.localhost/')
24+
await fetch("http://prisme.localhost/");
2625

2726
// Read access log file.
28-
const file = Bun.file('/prisme_logs/access.log')
29-
const text = await file.text()
30-
const lines = text.split('\n').filter((l) => l !== '')
31-
const lastLogLine = lines[lines.length - 1]
32-
const lastLog = JSON.parse(lastLogLine)
27+
const text = await Deno.readTextFile("/prisme_logs/access.log");
28+
const lines = text.split("\n").filter((l) => l !== "");
29+
const lastLogLine = lines[lines.length - 1];
30+
const lastLog = JSON.parse(lastLogLine);
3331

34-
expect(lastLog.source_ip).toBe('')
35-
})
32+
expect(lastLog.source_ip).toBe("");
33+
});

tests/bun/trusted-proxy/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test:
1818
-f ./docker-compose.test.yml \
1919
up \
2020
--abort-on-container-exit \
21-
--exit-code-from bun
21+
--exit-code-from deno
2222

2323
.PHONY: clean
2424
clean:

tests/bun/trusted-proxy/docker-compose.test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
2-
bun:
3-
image: docker.io/oven/bun
4-
command: sh -c "bun install && cd ./trusted-proxy && exec bun test"
5-
working_dir: /data
2+
deno:
3+
image: docker.io/denoland/deno:2.5.2
4+
command: deno test --allow-net
5+
working_dir: /data/trusted-proxy
66
volumes:
77
- ..:/data
88
- prisme_logs:/prisme_logs:ro

0 commit comments

Comments
 (0)