test(android): scan values resource aliases

This commit is contained in:
Vincent Koc
2026-07-12 08:02:17 +02:00
committed by Vincent Koc
parent 06b2be86c3
commit d91ae52040
2 changed files with 7 additions and 9 deletions

View File

@@ -7,9 +7,9 @@ import { NATIVE_I18N_LOCALES } from "./native-app-i18n.ts";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(HERE, "..");
const ANDROID_ROOT = path.join(ROOT, "apps", "android", "app", "src", "main");
const RESOURCE_ROOT = path.join(ANDROID_ROOT, "res");
const SOURCE_ROOT = path.join(ANDROID_ROOT, "java");
const ANDROID_MAIN_ROOT = path.join(ROOT, "apps", "android", "app", "src", "main");
const RESOURCE_ROOT = path.join(ANDROID_MAIN_ROOT, "res");
const SOURCE_ROOT = path.join(ANDROID_MAIN_ROOT, "java");
const INVENTORY_PATH = path.join(ROOT, "apps", ".i18n", "native-source.json");
const ARTIFACT_ROOT = path.join(ROOT, "apps", ".i18n", "native");
const TOOL_DISPLAY_PATH = path.join(
@@ -205,15 +205,13 @@ async function readAndroidSource(
return sources;
}
async function readAndroidResourceReferences(root = ANDROID_ROOT): Promise<string> {
async function readAndroidResourceReferences(root = ANDROID_MAIN_ROOT): Promise<string> {
const entries = await readdir(root, { withFileTypes: true });
const sources: string[] = [];
for (const entry of entries) {
const fullPath = path.join(root, entry.name);
if (entry.isDirectory()) {
if (fullPath.startsWith(`${RESOURCE_ROOT}${path.sep}values`)) {
continue;
}
// This walk is confined to app/src/main, so Gradle build output is never eligible.
sources.push(await readAndroidResourceReferences(fullPath));
continue;
}

View File

@@ -26,8 +26,8 @@ describe("Android app i18n resources", () => {
it("counts Kotlin and XML resource references", () => {
expect(
findUnusedAndroidResourceKeys(
["kotlin_only", "manifest_only", "unused"],
'R.string.kotlin_only android:label="@string/manifest_only"',
["kotlin_only", "manifest_only", "values_only", "unused"],
'R.string.kotlin_only android:label="@string/manifest_only" <string name="alias">@string/values_only</string>',
),
).toEqual(["unused"]);
});