|
1 | 1 | load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") |
| 2 | +load("@npm//:@babel/cli/package_json.bzl", babel_bin = "bin") |
2 | 3 | load("//js:defs.bzl", "js_test") |
3 | 4 |
|
4 | 5 | TESTS = [ |
5 | 6 | "escape.js", |
6 | | - "lstat.js", |
7 | | - "opendir.js", |
8 | | - "readdir.js", |
9 | | - "readlink.js", |
10 | | - "realpath.js", |
| 7 | + "lstat.mjs", |
| 8 | + "opendir.mjs", |
| 9 | + "readdir.mjs", |
| 10 | + "readlink.mjs", |
| 11 | + "realpath.mjs", |
| 12 | +] |
| 13 | + |
| 14 | +CJS_TESTS = [ |
| 15 | + t.replace(".mjs", ".cjs") |
| 16 | + for t in TESTS |
11 | 17 | ] |
12 | 18 |
|
13 | 19 | # Multiple node toolchains for testing across versions |
@@ -39,26 +45,65 @@ TOOLCHAINS_VERSIONS = [ |
39 | 45 | for t in TESTS |
40 | 46 | ] |
41 | 47 |
|
| 48 | +babel_bin.babel( |
| 49 | + name = "babel_mjs2js", |
| 50 | + srcs = [t for t in TESTS if t.endswith(".mjs")] + [ |
| 51 | + "babel.config.js", |
| 52 | + "//:node_modules/@babel/plugin-transform-modules-commonjs", |
| 53 | + ], |
| 54 | + outs = [t.replace(".mjs", ".cjs") for t in TESTS if t.endswith(".mjs")], |
| 55 | + args = [ |
| 56 | + "--extensions", |
| 57 | + ".mjs", |
| 58 | + "--out-file-extension", |
| 59 | + ".cjs", |
| 60 | + "--out-dir", |
| 61 | + ".", |
| 62 | + ] + [t for t in TESTS if t.endswith(".mjs")], |
| 63 | + chdir = package_name(), # to automatically pickup babel.config.js |
| 64 | +) |
| 65 | + |
42 | 66 | # Basic tests |
43 | 67 | [ |
44 | 68 | [ |
45 | | - js_test( |
46 | | - name = "{}_{}_test".format( |
47 | | - t.replace(".js", ""), |
48 | | - toolchain_name, |
49 | | - ), |
50 | | - data = [ |
51 | | - "//:node_modules/inline-fixtures", |
52 | | - "//js/private/node-patches/src:compile", |
53 | | - ], |
54 | | - entry_point = "copy_entry_{}".format(t), |
55 | | - node_toolchain = toolchain, |
56 | | - patch_node_fs = False, |
57 | | - # Without node patches on for these tests, the program is going to escape the sandbox if it |
58 | | - # is on since the fs patches are not on for the tests as they are the code under test |
59 | | - tags = ["no-sandbox"], |
60 | | - ) |
61 | | - for t in TESTS |
| 69 | + [ |
| 70 | + js_test( |
| 71 | + name = "{}_{}_test".format( |
| 72 | + t.replace(".mjs", "").replace(".js", ""), |
| 73 | + toolchain_name, |
| 74 | + ), |
| 75 | + data = [ |
| 76 | + "//:node_modules/inline-fixtures", |
| 77 | + "//js/private/node-patches/src:compile", |
| 78 | + ], |
| 79 | + entry_point = "copy_entry_{}".format(t) if (t in TESTS) else t, |
| 80 | + node_toolchain = toolchain, |
| 81 | + patch_node_fs = False, |
| 82 | + # Without node patches on for these tests, the program is going to escape the sandbox if it |
| 83 | + # is on since the fs patches are not on for the tests as they are the code under test |
| 84 | + tags = ["no-sandbox"], |
| 85 | + ) |
| 86 | + for t in TESTS |
| 87 | + ], |
| 88 | + [ |
| 89 | + js_test( |
| 90 | + name = "{}_{}_cjs_test".format( |
| 91 | + t.replace(".cjs", ""), |
| 92 | + toolchain_name, |
| 93 | + ), |
| 94 | + data = [ |
| 95 | + "//:node_modules/inline-fixtures", |
| 96 | + "//js/private/node-patches/src:compile", |
| 97 | + ], |
| 98 | + entry_point = "copy_entry_{}".format(t) if (t in TESTS) else t, |
| 99 | + node_toolchain = toolchain, |
| 100 | + patch_node_fs = False, |
| 101 | + # Without node patches on for these tests, the program is going to escape the sandbox if it |
| 102 | + # is on since the fs patches are not on for the tests as they are the code under test |
| 103 | + tags = ["no-sandbox"], |
| 104 | + ) |
| 105 | + for t in CJS_TESTS |
| 106 | + ], |
62 | 107 | ] |
63 | 108 | for toolchain_name, toolchain in zip( |
64 | 109 | TOOLCHAINS_NAMES, |
|
0 commit comments