run.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <html>
  2. <head>
  3. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  4. <script src="../dist/puter.dev.js"></script>
  5. <script src="./kv.test.js"></script>
  6. <script src="./fs.test.js"></script>
  7. <style>
  8. #tests {
  9. margin-top: 20px;
  10. }
  11. #run-tests {
  12. margin-top: 20px;
  13. margin-bottom: 20px;
  14. background-color: #4c84af;
  15. border: none;
  16. color: white;
  17. padding: 10px 20px;
  18. text-align: center;
  19. text-decoration: none;
  20. display: inline-block;
  21. font-size: 16px;
  22. cursor: pointer;
  23. }
  24. #unselect-all {
  25. margin-left: 20px;
  26. cursor: pointer;
  27. }
  28. #select-all {
  29. margin-left: 20px;
  30. cursor: pointer;
  31. }
  32. .test-container{
  33. margin-bottom: 10px;
  34. padding: 10px;
  35. border-radius: 5px;
  36. }
  37. </style>
  38. <script>
  39. document.addEventListener("DOMContentLoaded", () => {
  40. window.pass = function(msg) {
  41. // $('#tests').append(`<p style="color:green;">${msg}</p>`);
  42. }
  43. window.fail = function(msg) {
  44. throw new Error(msg);
  45. }
  46. // print the test name with checkbox for each test
  47. $('#tests').append('<h2>File System Tests</h2>');
  48. for (let i = 0; i < fsTests.length; i++) {
  49. $('#tests').append(`<div class="test-container" id="fsTests-container-${i}">
  50. <input type="checkbox" class="test-checkbox" id="fsTests${i}" checked>
  51. <label for="fsTests${i}">${fsTests[i].name}</label><br>
  52. </div>`);
  53. }
  54. $('#tests').append('<h2>Key Value Tests</h2>');
  55. for (let i = 0; i < kvTests.length; i++) {
  56. $('#tests').append(`<div class="test-container" id="kvTests-container-${i}">
  57. <input type="checkbox" class="test-checkbox" id="kvTests${i}" checked>
  58. <label for="kvTests${i}">${kvTests[i].name}</label><br>
  59. </div>`);
  60. }
  61. window.assert = function(condition, message) {
  62. if (!condition) {
  63. throw new Error(message || "Assertion failed");
  64. }
  65. }
  66. async function runTests() {
  67. // go through fsTests and run each test
  68. for (let i = 0; i < fsTests.length; i++) {
  69. if (document.getElementById(`fsTests${i}`).checked) {
  70. try{
  71. await fsTests[i]();
  72. // make this test's container green
  73. $(`#fsTests-container-${i}`).css('background-color', '#85e085');
  74. } catch (e) {
  75. console.log(e);
  76. // make this test's container red
  77. $(`#fsTests-container-${i}`).css('background-color', '#ffbfbf');
  78. // message
  79. $(`#fsTests-container-${i}`).append(`<p style="color:#c00000;">${e}</p>`);
  80. }
  81. }
  82. }
  83. for (let i = 0; i < kvTests.length; i++) {
  84. if (document.getElementById(`kvTests${i}`).checked) {
  85. try{
  86. await kvTests[i]();
  87. // make this test's container green
  88. $(`#kvTests-container-${i}`).css('background-color', '#85e085');
  89. } catch (e) {
  90. // make this test's container red
  91. $(`#kvTests-container-${i}`).css('background-color', '#ff8484');
  92. // message
  93. $(`#kvTests-container-${i}`).append(`<p style="color:red;">${e}</p>`);
  94. }
  95. }
  96. }
  97. }
  98. $('#run-tests').click(() => {
  99. runTests();
  100. });
  101. $('#unselect-all').click(() => {
  102. for (let i = 0; i < fsTests.length; i++) {
  103. $('.test-checkbox').prop('checked', false);
  104. }
  105. });
  106. $('#select-all').click(() => {
  107. for (let i = 0; i < fsTests.length; i++) {
  108. $('.test-checkbox').prop('checked', true);
  109. }
  110. });
  111. });
  112. </script>
  113. </head>
  114. <body>
  115. <nav style="position: fixed; top: 0; width: 100%; background: #EEE; left: 0; padding-left: 10px;">
  116. <button id="run-tests">Run Tests</button>
  117. <span id="select-all">Select All</span>
  118. <span id="unselect-all">Unselect All</span>
  119. </nav>
  120. <div id="tests" style="margin-top:100px;"></div>
  121. </body>
  122. </html>