Js.hx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package runci.targets;
  2. import sys.FileSystem;
  3. import runci.System.*;
  4. import runci.Config.*;
  5. import haxe.io.Path;
  6. import sys.io.Process;
  7. using StringTools;
  8. class Js {
  9. static final miscJsDir = getMiscSubDir('js');
  10. static public function getJSDependencies() {
  11. switch [ci, systemName] {
  12. case [_, "Linux"]:
  13. if (commandSucceed("node", ["-v"])) {
  14. infoMsg('node has already been installed.');
  15. } else {
  16. Linux.requireAptPackages(["nodejs"]);
  17. }
  18. case _:
  19. //pass
  20. }
  21. runCommand("node", ["-v"]);
  22. }
  23. static function installNpmPackages(packages:Array<String>) {
  24. final required = if (isCi()) {
  25. packages;
  26. } else {
  27. final filtered = packages.filter( (lib) -> {
  28. final isInstalled = commandSucceed("npm", ["list", lib]);
  29. if (isInstalled)
  30. infoMsg('npm package `$lib` has already been installed.');
  31. return !isInstalled;
  32. });
  33. if (filtered.length == 0)
  34. return;
  35. filtered;
  36. };
  37. runNetworkCommand("npm", ["install"].concat(required));
  38. }
  39. static public function run(args:Array<String>) {
  40. getJSDependencies();
  41. final jsOutputs = [
  42. for (es_ver in [[], ["-D", "js-es=3"], ["-D", "js-es=6"]])
  43. for (unflatten in [[], ["-D", "js-unflatten"]])
  44. for (classic in [[], ["-D", "js-classic"]])
  45. for (enums_as_objects in [[], ["-D", "js-enums-as-arrays"]])
  46. {
  47. final extras = args.concat(es_ver).concat(unflatten).concat(classic).concat(enums_as_objects);
  48. runCommand("haxe", ["compile-js.hxml"].concat(extras));
  49. final output = if (extras.length > 0) {
  50. "bin/js/" + extras.join("") + "/unit.js";
  51. } else {
  52. "bin/js/default/unit.js";
  53. }
  54. final outputDir = Path.directory(output);
  55. if (!FileSystem.exists(outputDir))
  56. FileSystem.createDirectory(outputDir);
  57. FileSystem.rename("bin/unit.js", output);
  58. FileSystem.rename("bin/unit.js.map", output + ".map");
  59. runCommand("node", ["-e", "require('./" + output + "').unit.TestMain.main();"]);
  60. output;
  61. }
  62. ];
  63. infoMsg("Test ES6:");
  64. changeDirectory(getMiscSubDir("es6"));
  65. runCommand("haxe", ["run.hxml"]);
  66. haxelibInstallGit("HaxeFoundation", "hxnodejs");
  67. final env = Sys.environment();
  68. if (
  69. env.exists("SAUCE") &&
  70. env.exists("SAUCE_USERNAME") &&
  71. env.exists("SAUCE_ACCESS_KEY")
  72. ) {
  73. final sc = switch (ci) {
  74. // TODO: figure out SauceConnect for GitHub Actions
  75. // case AzurePipelines:
  76. // var scVersion = "sc-4.5.3-linux";
  77. // runCommand("wget", ["-q", 'https://saucelabs.com/downloads/${scVersion}.tar.gz'], true);
  78. // runCommand("tar", ["-xf", '${scVersion}.tar.gz']);
  79. // //start sauce-connect
  80. // var scReadyFile = "sauce-connect-ready-" + Std.random(100);
  81. // var p = new Process('${scVersion}/bin/sc', [
  82. // "-i", Sys.getEnv("SAUCE_TUNNEL_ID"),
  83. // "-f", scReadyFile
  84. // ]);
  85. // while(!FileSystem.exists(scReadyFile)) {
  86. // Sys.sleep(0.5);
  87. // }
  88. // p;
  89. case _:
  90. // sauce-connect should have been started
  91. null;
  92. }
  93. changeDirectory(unitDir);
  94. installNpmPackages(["wd", "q"]);
  95. runCommand("haxe", ["compile-saucelabs-runner.hxml"]);
  96. final server = new Process("nekotools", ["server"]);
  97. runCommand("node", ["bin/RunSauceLabs.js"].concat([for (js in jsOutputs) "unit-js.html?js=" + js.urlEncode()]));
  98. server.close();
  99. if (sc != null)
  100. sc.close();
  101. }
  102. infoMsg("Test optimization:");
  103. changeDirectory(optDir);
  104. runCommand("haxe", ["run.hxml"]);
  105. runci.targets.Jvm.getJavaDependencies(); // this is awkward
  106. haxelibInstallGit("Simn", "haxeserver");
  107. changeDirectory(serverDir);
  108. runCommand("haxe", ["build.hxml"]);
  109. runCommand("node", ["test.js"]);
  110. runCommand("haxe", ["build.hxml", "-D", "disable-hxb-optimizations"]);
  111. runCommand("node", ["test.js"]);
  112. runCommand("haxe", ["build.hxml", "-D", "disable-hxb-cache"]);
  113. runCommand("node", ["test.js"]);
  114. changeDirectory(sysDir);
  115. installNpmPackages(["deasync"]);
  116. runCommand("haxe", ["compile-js.hxml"].concat(args));
  117. runSysTest("node", ["bin/js/sys.js"]);
  118. changeDirectory(miscJsDir);
  119. runCommand("haxe", ["run.hxml"]);
  120. }
  121. }