mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:50:18 +00:00
673b5245c5
## Description: Fixes the failing nationNameLength.test by usinbg the proper absolute path glob syntax Also switches to fast-glob because I don't see a reason to not use it. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: Lavodan
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import fs from "fs";
|
|
import { globSync } from "glob";
|
|
|
|
type Nation = {
|
|
name?: string;
|
|
};
|
|
|
|
type Manifest = {
|
|
nations?: Nation[];
|
|
};
|
|
|
|
describe("Map manifests: nation name length constraint", () => {
|
|
test("All nations' names must be ≤ 27 characters", () => {
|
|
const manifestPaths = globSync("resources/maps/**/manifest.json");
|
|
|
|
expect(manifestPaths.length).toBeGreaterThan(0);
|
|
|
|
const violations: string[] = [];
|
|
|
|
for (const manifestPath of manifestPaths) {
|
|
try {
|
|
const raw = fs.readFileSync(manifestPath, "utf8");
|
|
const manifest = JSON.parse(raw) as Manifest;
|
|
|
|
(manifest.nations ?? []).forEach((nation, idx) => {
|
|
const name = nation?.name;
|
|
if (typeof name !== "string") {
|
|
violations.push(
|
|
`${manifestPath} -> nations[${idx}].name is not a string`,
|
|
);
|
|
return;
|
|
}
|
|
if (name.length > 27) {
|
|
violations.push(
|
|
`${manifestPath} -> nations[${idx}].name "${name}" has length ${name.length} (> 27)`,
|
|
);
|
|
}
|
|
});
|
|
} catch (err) {
|
|
violations.push(
|
|
`Failed to parse ${manifestPath}: ${(err as Error).message}`,
|
|
);
|
|
}
|
|
}
|
|
|
|
if (violations.length > 0) {
|
|
throw new Error(
|
|
"Nation name length violations:\n" + violations.join("\n"),
|
|
);
|
|
}
|
|
});
|
|
});
|