ss_data.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. "use strict";
  10. const fs = require("fs");
  11. const jsyaml = require("js-yaml");
  12. const querystring = require("querystring");
  13. const queryKeys = [
  14. "tex", "pre", "post", "display", "noThrow", "errorColor", "styles",
  15. ];
  16. let dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
  17. dict = jsyaml.safeLoad(dict);
  18. for (const key in dict) {
  19. if (dict.hasOwnProperty(key)) {
  20. let itm = dict[key];
  21. if (typeof itm === "string") {
  22. itm = dict[key] = {tex: itm};
  23. }
  24. const query = {};
  25. queryKeys.forEach(function(key) {
  26. if (itm.hasOwnProperty(key)) {
  27. query[key] = itm[key];
  28. }
  29. });
  30. itm.query = querystring.stringify(query);
  31. if (itm.macros) {
  32. itm.query += "&" + querystring.stringify(itm.macros);
  33. }
  34. }
  35. }
  36. module.exports = dict;