jsontests.js 961 B

12345678910111213141516171819202122232425262728293031
  1. "use strict"
  2. const testSuitePaths = {
  3. draft6: "spec/JSON-Schema-Test-Suite/tests/draft6/",
  4. draft7: "spec/JSON-Schema-Test-Suite/tests/draft7/",
  5. draft2019: "spec/JSON-Schema-Test-Suite/tests/draft2019-09/",
  6. tests: "spec/tests/",
  7. security: "spec/security/",
  8. extras: "spec/extras/",
  9. async: "spec/async/",
  10. }
  11. const glob = require("glob")
  12. const fs = require("fs")
  13. for (const suite in testSuitePaths) {
  14. const p = testSuitePaths[suite]
  15. const files = glob.sync(`${p}{**/,}*.json`)
  16. if (files.length === 0) {
  17. console.error(`Missing folder ${p}\nTry: git submodule update --init\n`)
  18. process.exit(1)
  19. }
  20. const code = files
  21. .map((f) => {
  22. const name = f.replace(p, "").replace(/\.json$/, "")
  23. const testPath = f.replace(/^spec/, "..")
  24. return `\n {name: "${name}", test: require("${testPath}")},`
  25. })
  26. .reduce((list, f) => list + f)
  27. fs.writeFileSync(`./spec/_json/${suite}.js`, `module.exports = [${code}\n]\n`)
  28. }