module-bugfixes.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // ES6 Module tests for bugfixes
  6. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. function testModuleScript(source, message, shouldFail = false) {
  8. let testfunc = () => testRunner.LoadModule(source, 'samethread', shouldFail);
  9. if (shouldFail) {
  10. let caught = false;
  11. // We can't use assert.throws here because the SyntaxError used to construct the thrown error
  12. // is from a different context so it won't be strictly equal to our SyntaxError.
  13. try {
  14. testfunc();
  15. } catch(e) {
  16. caught = true;
  17. // Compare toString output of SyntaxError and other context SyntaxError constructor.
  18. assert.areEqual(e.constructor.toString(), SyntaxError.toString(), message);
  19. }
  20. assert.isTrue(caught, `Expected error not thrown: ${message}`);
  21. } else {
  22. assert.doesNotThrow(testfunc, message);
  23. }
  24. }
  25. var tests = [
  26. {
  27. name: "OS12113549: Assertion on module export in ProcessCapturedSym",
  28. body: function() {
  29. let functionBody =
  30. `
  31. import { module1_exportbinding_0 as module2_localbinding_0 } from 'bug_OS12113549_module1.js';
  32. assert.areEqual({"BugID": "OS12113549"}, module2_localbinding_0);
  33. `
  34. testRunner.LoadModule(functionBody, 'samethread');
  35. }
  36. },
  37. {
  38. name: "Memory leak test on syntax error",
  39. body: function() {
  40. try {
  41. WScript.LoadModule('');
  42. WScript.LoadModule('1');
  43. WScript.LoadModule('const a = () -> {};');
  44. } catch(e) {
  45. // no-op
  46. }
  47. }
  48. },
  49. {
  50. name: "Issue 4482: Indirect circular module dependencies",
  51. body: function() {
  52. let functionBody = "import 'module_4482_dep1.js';"
  53. testRunner.LoadModule(functionBody);
  54. }
  55. },
  56. {
  57. name: "Issue 4570: Module that appears multiple times in dependency tree",
  58. body: function() {
  59. let functionBody = "import 'module_4570_dep1.js';"
  60. testRunner.LoadModule(functionBody);
  61. }
  62. },
  63. {
  64. name: "Issue 5171: Incorrect module load order",
  65. body: function() {
  66. WScript.RegisterModuleSource("obj.js", `export const obj = {a:false, b: false, c: false};`);
  67. WScript.RegisterModuleSource("a.js",`
  68. import {obj} from "obj.js";
  69. assert.isTrue(obj.b);
  70. assert.isFalse(obj.c);
  71. assert.isFalse(obj.a);
  72. obj.a = true;`);
  73. WScript.RegisterModuleSource("b.js",`
  74. import {obj} from "obj.js";
  75. assert.isFalse(obj.b);
  76. assert.isFalse(obj.c);
  77. assert.isFalse(obj.a);
  78. obj.b = true;`);
  79. WScript.RegisterModuleSource("c.js",`
  80. import {obj} from "obj.js";
  81. assert.isTrue(obj.b);
  82. assert.isFalse(obj.c);
  83. assert.isTrue(obj.a);
  84. obj.c = true;`);
  85. const start = 'import "b.js"; import "a.js"; import "c.js";';
  86. testRunner.LoadModule(start);
  87. }
  88. }
  89. ];
  90. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });