import test from "ava";

const fs = require("fs");
const path = require("path");

const localesPath = path.join(__dirname, "..", "locales");
const filenameRegex = /^[a-z][a-z](_[A-Z]+)*\.json$/;

test("locale files are valid", t => {
  const filenames = fs.readdirSync(localesPath);
  filenames.forEach(filename => {
    /* test filename */
    if (!filenameRegex.test(filename)) t.fail(`locale filename "${filename}" is invalid`);

    /* test file json */
    const content = fs.readFileSync(path.join(localesPath, filename), { encoding: "utf8" });
    let valid = false;
    try {
      JSON.parse(content);
      valid = true;
    } catch (e) {}
    if (!valid) t.fail(`locale file "${filename}" is invalid`);
  });

  t.pass(); // if nothing has failed so far
});

@@ -556,21 +556,12 @@
 let 
-valid = false
+json
 ;%0A  
@@ -573,16 +573,23 @@
  %7B%0A     
+ json =
  JSON.pa
@@ -606,28 +606,8 @@
 t);%0A
-      valid = true;%0A
     
@@ -623,70 +623,251 @@
 e) %7B
-%7D
 %0A
+  
     
-if (!valid) t.fail(%60locale file %22$%7Bfilename%7D%22 is invalid
+t.fail(%60locale file %22$%7Bfilename%7D%22 contains invalid JSON%60);%0A    %7D%0A%0A    /* test file contents */%0A    t.truthy(json%5B%22__redirect__%22%5D %7C%7C json%5B%22__locale_name__%22%5D, %60locale file %22$%7Bfilename%7D%22 is missing both %22__locale_name__%22 and %22__redirect__%22
 %60);%0A

Add test for certain required locale keys