www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ss_data.js (1060B)


      1 /**
      2  * Parse and polish the screenshotter data in ss_data.yaml.
      3  *
      4  * This module is responsible for reading the file ss_data.yaml,
      5  * unify syntactic variations (like string vs. dict as test case body)
      6  * and provide common functionality (like a query string encoded version).
      7  * The export of this module is simply a dictionary of test cases.
      8  */
      9 
     10 var fs = require("fs");
     11 var jsyaml = require("js-yaml");
     12 var querystring = require("querystring");
     13 
     14 var queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"];
     15 var dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
     16 dict = jsyaml.safeLoad(dict);
     17 for (var key in dict) {
     18     var itm = dict[key];
     19     if (typeof itm === "string") {
     20         itm = dict[key] = { tex: itm };
     21     }
     22     var query = {};
     23     queryKeys.forEach(function(key) {
     24         if (itm.hasOwnProperty(key)) {
     25             query[key] = itm[key];
     26         }
     27     });
     28     itm.query = querystring.stringify(query);
     29     if (itm.macros) {
     30         itm.query += "&" + querystring.stringify(itm.macros);
     31     }
     32 }
     33 module.exports = dict;