Js.hx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 public function getJSDependencies() {
  10. switch [ci, systemName] {
  11. case [_, "Linux"]:
  12. if (commandSucceed("node", ["-v"])) {
  13. infoMsg('node has already been installed.');
  14. } else {
  15. Linux.requireAptPackages(["nodejs"]);
  16. }
  17. case [AzurePipelines, "Mac"]:
  18. runCommand("brew", ["install", "node"], true);
  19. // runCommand("brew", ["install", "node@10"], true);
  20. // runCommand("brew", ["link", "--overwrite", "--force", "node@10"]);
  21. case _:
  22. //pass
  23. }
  24. runCommand("node", ["-v"]);
  25. }
  26. static public function run(args:Array<String>) {
  27. getJSDependencies();
  28. var jsOutputs = [
  29. for (es_ver in [[], ["-D", "js-es=3"], ["-D", "js-es=6"]])
  30. for (unflatten in [[], ["-D", "js-unflatten"]])
  31. for (classic in [[], ["-D", "js-classic"]])
  32. for (enums_as_objects in [[], ["-D", "js-enums-as-arrays"]])
  33. {
  34. var extras = args.concat(es_ver).concat(unflatten).concat(classic).concat(enums_as_objects);
  35. runCommand("haxe", ["compile-js.hxml"].concat(extras));
  36. var output = if (extras.length > 0) {
  37. "bin/js/" + extras.join("") + "/unit.js";
  38. } else {
  39. "bin/js/default/unit.js";
  40. }
  41. var outputDir = Path.directory(output);
  42. if (!FileSystem.exists(outputDir)) {
  43. FileSystem.createDirectory(outputDir);
  44. }
  45. FileSystem.rename("bin/unit.js", output);
  46. FileSystem.rename("bin/unit.js.map", output + ".map");
  47. runCommand("node", ["-e", "require('./" + output + "').unit.TestMain.main();"]);
  48. output;
  49. }
  50. ];
  51. infoMsg("Test ES6:");
  52. changeDirectory(miscDir + "es6");
  53. runCommand("haxe", ["run.hxml"]);
  54. haxelibInstallGit("HaxeFoundation", "hxnodejs");
  55. var env = Sys.environment();
  56. if (
  57. env.exists("SAUCE") &&
  58. env.exists("SAUCE_USERNAME") &&
  59. env.exists("SAUCE_ACCESS_KEY")
  60. ) {
  61. var sc = switch (ci) {
  62. case AzurePipelines:
  63. var scVersion = "sc-4.5.3-linux";
  64. runCommand("wget", ["-q", 'https://saucelabs.com/downloads/${scVersion}.tar.gz'], true);
  65. runCommand("tar", ["-xf", '${scVersion}.tar.gz']);
  66. //start sauce-connect
  67. var scReadyFile = "sauce-connect-ready-" + Std.random(100);
  68. var p = new Process('${scVersion}/bin/sc', [
  69. "-i", Sys.getEnv("SAUCE_TUNNEL_ID"),
  70. "-f", scReadyFile
  71. ]);
  72. while(!FileSystem.exists(scReadyFile)) {
  73. Sys.sleep(0.5);
  74. }
  75. p;
  76. case _:
  77. // sauce-connect should have been started
  78. null;
  79. }
  80. changeDirectory(unitDir);
  81. runCommand("npm", ["install", "wd", "q"], true);
  82. runCommand("haxe", ["compile-saucelabs-runner.hxml"]);
  83. var server = new Process("nekotools", ["server"]);
  84. runCommand("node", ["bin/RunSauceLabs.js"].concat([for (js in jsOutputs) "unit-js.html?js=" + js.urlEncode()]));
  85. server.close();
  86. if (sc != null)
  87. sc.close();
  88. }
  89. infoMsg("Test optimization:");
  90. changeDirectory(optDir);
  91. runCommand("haxe", ["run.hxml"]);
  92. runci.targets.Java.getJavaDependencies(); // this is awkward
  93. haxelibInstallGit("Simn", "haxeserver");
  94. changeDirectory(serverDir);
  95. runCommand("haxe", ["build.hxml"]);
  96. runCommand("node", ["test.js"]);
  97. }
  98. }