web-runner.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* global document, location, addEventListener */
  2. // Open `index.html` in a browser to run this file
  3. import tests from "./tests-data.js";
  4. const table = document.createElement("table");
  5. tests.forEach(test => {
  6. const row = document.createElement("tr");
  7. const cellTest = document.createElement("td");
  8. const cellLink = document.createElement("td");
  9. const iframe = document.createElement("iframe");
  10. const link = document.createElement("a");
  11. link.textContent = test.title;
  12. link.target = test.script;
  13. row.dataset.script = test.script;
  14. link.href = iframe.src = (test.env || "all") + "/loader.html#" + encodeURIComponent(JSON.stringify({ script: test.script }));
  15. cellTest.appendChild(iframe);
  16. cellLink.appendChild(link);
  17. row.appendChild(cellLink);
  18. row.appendChild(cellTest);
  19. table.appendChild(row);
  20. });
  21. document.body.appendChild(table);
  22. if (!location.search.startsWith("?keepTests")) {
  23. addEventListener("message", event => {
  24. const result = JSON.parse(event.data);
  25. if (!result.error) {
  26. Array.from(document.querySelectorAll("tr")).find(row => row.dataset.script == result.script).remove();
  27. }
  28. if (!document.querySelectorAll("tr").length) {
  29. document.body.innerHTML = "ok";
  30. }
  31. }, false);
  32. }