Files
openidea/scripts/check-webkit.test.ts
T
Bbu Gulli Annandctro15547 ccf87e2476 fix(macos): support macOS 12 again (#3576)
Lowers the minimum macOS version to 12.0 and the WebKit floor to Safari 15.4: Vite targets safari15.4, check-webkit enforces the 15.4 floor and rejects Array toSorted/toReversed/toSpliced, showPicker and Intl.supportedValuesOf in startup chunks, the boot outdated check tests structuredClone, the Database view drops toReversed, and the install docs list macOS 12. Container-query layouts degrade on macOS 12.

Fixes #3413

Co-authored-by: ctro15547 <16602442+ctro15547@users.noreply.github.com>
2026-11-16 00:58:42 +08:00

48 lines
1.9 KiB
TypeScript

// @vitest-environment node
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it } from "vitest";
import { checkBuild, checkSource } from "./check-webkit.ts";
it.each([
"Promise.withResolvers()",
"Object.groupBy(items, key)",
"Array.fromAsync(items)",
"text.toWellFormed()",
"input.showPicker()",
'Intl.supportedValuesOf("collator")',
"items.toSorted(compare)",
"path.toReversed()",
'new RegExp("[a-z]", "v")',
'RegExp("(?<=a)b")',
"/[a-z]/v",
"/(?<!a)b/",
'import data from "./data.json" with { type: "json" }',
])("rejects %s in the Safari 15.4 startup graph", (source) => {
expect(checkSource(source, true).length).toBeGreaterThan(0);
});
it("does not mistake regex detection strings or named groups for newer syntax", () => {
expect(checkSource('const message = "(?<=a)"; const regex = /(?<name>a)/u;', true)).toEqual([]);
expect(checkSource("const regex = /(\\(\\?<=)|(\\(\\?<!)/;", true)).toEqual([]);
});
it("checks the entry's static imports and all lazy chunks for syntax", () => {
const dir = mkdtempSync(join(tmpdir(), "openidea-webkit-"));
try {
mkdirSync(join(dir, "assets"));
writeFileSync(join(dir, "index.html"), '<script type="module" src="/assets/entry.js"></script>');
writeFileSync(join(dir, "boot.js"), "");
writeFileSync(join(dir, "assets/entry.js"), 'import "./dependency.js"; import("./lazy.js");');
writeFileSync(join(dir, "assets/dependency.js"), "Promise.withResolvers();");
writeFileSync(join(dir, "assets/lazy.js"), "Object.groupBy(items, key); const re = /[a-z]/v;");
expect(checkBuild(dir)).toEqual([
"assets/dependency.js: Promise.withResolvers requires newer WebKit",
"assets/lazy.js: RegExp v flag requires Safari 17",
]);
} finally {
rmSync(dir, { recursive: true });
}
});