module-bugfixes.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });