-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mjs
30 lines (27 loc) · 1.38 KB
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getBuildTargetFromUA } from "./dist/compat.js";
const testData = {
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.0.0 Safari/537.36": "es2021",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.0.0 Safari/537.36": "es2023",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36": "es2023",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36": "es2024",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15": "es2021",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.1": "es2023",
"HeadlessChrome/90": "es2021",
"HeadlessChrome/109": "es2023",
"ES/2020": "es2020",
"ES/2022": "es2022",
"Deno/1.33.1": "deno",
"Deno/1.33.2": "denonext",
"undici": "node",
"Node.js/20.0.0": "node",
"Node/20.0.0": "node",
"Bun/1.0.0": "node",
};
for (const [ua, expected] of Object.entries(testData)) {
const actual = getBuildTargetFromUA(ua);
if (actual !== expected) {
console.error(`UA ${ua} should have been ${expected} but was ${actual}`);
process.exit(1);
}
}
console.log("✅ All tests passed");