Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.7 KB
Raw Blame
import fs from "fs";
import path from "path";
import { describe, expect, test } from "vitest";
import {
  I18N_PROJECTS,
  REPO_ROOT,
  findMissingKeys,
} from "@editor/i18n/translationAudit";

// One suite per frontend app (editor + portal). The scan logic lives in
// @editor/i18n/translationAudit so both apps share one implementation.
describe.each(I18N_PROJECTS)(
  "Missing translation coverage — $name",
  (project) => {
    test(
      "fails if any key used in source is missing from the English locales",
      // Scans/parses the whole source tree: generous headroom for a loaded CPU.
      { timeout: 60_000 },
      () => {
        expect(fs.existsSync(project.localeFile)).toBe(true);

        const { missing, usedCount } = findMissingKeys(project);
        expect(usedCount).toBeGreaterThan(project.minUsedKeys ?? 1); // scan sanity

        const annotations = missing.map(
          ({ key, fallback, file, line, column }) => ({
            key,
            fallback,
            file: path.relative(REPO_ROOT, file).replace(/\\/g, "/"),
            line,
            column,
          }),
        );

        // GitHub Annotations format so misses show up tagged on the code in CI.
        for (const { key, fallback, file, line, column } of annotations) {
          process.stderr.write(
            `::error file=${file},line=${line},col=${column}::Missing English translation for ${key} (${fallback})\n`,
          );
        }

        const located = annotations.map(
          ({ key, fallback, file, line, column }) => ({
            key,
            fallback,
            location: `${file}:${line}:${column}`,
          }),
        );

        expect(located).toEqual([]);
      },
    );
  },
);