jsapi.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. const [testfile, ...options] = WScript.Arguments;
  6. if (!testfile) {
  7. throw new Error("Missing testfile");
  8. }
  9. const verbose = options.indexOf("-verbose") !== -1;
  10. const self = this;
  11. const setTimeout = WScript.SetTimeout;
  12. const clearTimeout = WScript.ClearTimeout;
  13. WScript.Flag(`-wasmMaxTableSize:${(Math.pow(2,32)-1)|0}`);
  14. self.addEventListener = function() {};
  15. class ConsoleTestEnvironment {
  16. on_tests_ready() {
  17. runTests();
  18. this.all_loaded = true;
  19. }
  20. // Invoked after setup() has been called to notify the test environment
  21. // of changes to the test harness properties.
  22. on_new_harness_properties(properties) {}
  23. // Should return a new unique default test name.
  24. next_default_test_name() {
  25. return this.nextName = (this.nextName | 0) + 1;
  26. }
  27. // Should return the test harness timeout duration in milliseconds.
  28. test_timeout() {
  29. return null;
  30. }
  31. add_on_loaded_callback() {}
  32. // Should return the global scope object.
  33. global_scope() {
  34. return self;
  35. }
  36. }
  37. function chakra_create_test_environment() {
  38. return new ConsoleTestEnvironment();
  39. }
  40. WScript.LoadScriptFile("testsuite/harness/index.js");
  41. WScript.LoadScriptFile("testsuite/harness/wasm-constants.js");
  42. WScript.LoadScriptFile("testsuite/harness/wasm-module-builder.js");
  43. WScript.LoadScript(read("testsuite/harness/testharness.js")
  44. // Use our text environment
  45. .replace(" = create_test_environment", " = chakra_create_test_environment"));
  46. function reportResult(tests, harness_status) {
  47. const status_text_harness = {
  48. [harness_status.OK]: "OK",
  49. [harness_status.ERROR]: "Error",
  50. [harness_status.TIMEOUT]: "Timeout",
  51. };
  52. const firstTest = tests[0] || {};
  53. const status_text = {
  54. [firstTest.PASS]: "Pass",
  55. [firstTest.FAIL]: "Fail",
  56. [firstTest.TIMEOUT]: "Timeout",
  57. [firstTest.NOTRUN]: "Not Run",
  58. };
  59. const status_number = tests.reduce((all, test) => {
  60. var status = status_text[test.status];
  61. all[status] = (all[status]|0) + 1;
  62. return all;
  63. }, {});
  64. function get_assertion(test) {
  65. if (test.properties.hasOwnProperty("assert")) {
  66. if (Array.isArray(test.properties.assert)) {
  67. return test.properties.assert.join(" ");
  68. }
  69. return test.properties.assert;
  70. }
  71. return "";
  72. }
  73. const testsReport = tests.map(test => {
  74. const stack = verbose ? test.stack : "";
  75. return `${status_text[test.status]} ${test.name} ${get_assertion(test)} ${test.message || ""}${stack ? "\n" + stack : stack}`;
  76. });
  77. console.log(`Harness Status: ${status_text_harness[harness_status.status]}
  78. Found ${tests.length} tests: ${Object.keys(status_number).map(key => `${key} = ${status_number[key]}`).join(" ")}
  79. ${testsReport.join("\n")}`);
  80. }
  81. function runTests() {
  82. add_completion_callback((...args) => {
  83. try {
  84. reportResult(...args);
  85. } catch (e) {
  86. console.log(e);
  87. }
  88. });
  89. WScript.LoadScriptFile(testfile);
  90. }