|
1 | 1 | import { execFile } from "child_process"; |
2 | 2 | import { createRequire } from "module"; |
3 | | -import { describeESM, describeGte, itLt } from "$repo-utils"; |
| 3 | +import { |
| 4 | + describeESM, |
| 5 | + describeSatisfies, |
| 6 | + itNegate, |
| 7 | + itSatisfies, |
| 8 | +} from "$repo-utils"; |
4 | 9 |
|
5 | 10 | const require = createRequire(import.meta.url); |
6 | 11 |
|
7 | 12 | // "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 20 |
8 | | -const nodeLt22_12 = itLt("22.12.0"); |
| 13 | +const versionHasRequireESM = "^20.19.0 || >=22.12.0"; |
9 | 14 |
|
10 | 15 | async function run(name, ...flags) { |
11 | 16 | return new Promise((res, rej) => { |
@@ -116,61 +121,70 @@ describeESM("usage from cjs", () => { |
116 | 121 | }); |
117 | 122 |
|
118 | 123 | describeESM("sync loading of ESM plugins", () => { |
119 | | - nodeLt22_12("without --experimental-require-module flag", async () => { |
120 | | - await expect(run("transform-sync-esm-plugin.mjs")).rejects.toThrow( |
121 | | - "You appear to be using a native ECMAScript module plugin, which is " + |
122 | | - "only supported when running Babel asynchronously or when using the " + |
123 | | - "Node.js `--experimental-require-module` flag.", |
124 | | - ); |
125 | | - }); |
126 | | - |
127 | | - describeGte("22.12.0")("without --experimental-require-module flag", () => { |
128 | | - it("sync", async () => { |
129 | | - const { stdout } = await run( |
130 | | - "transform-sync-esm-plugin.mjs", |
131 | | - "--experimental-require-module", |
| 124 | + itNegate(itSatisfies(versionHasRequireESM))( |
| 125 | + "without --experimental-require-module flag", |
| 126 | + async () => { |
| 127 | + await expect(run("transform-sync-esm-plugin.mjs")).rejects.toThrow( |
| 128 | + "You appear to be using a native ECMAScript module plugin, which is " + |
| 129 | + "only supported when running Babel asynchronously or when using the " + |
| 130 | + "Node.js `--experimental-require-module` flag.", |
132 | 131 | ); |
133 | | - expect(stdout).toMatchInlineSnapshot(` |
| 132 | + }, |
| 133 | + ); |
| 134 | + |
| 135 | + describeSatisfies(versionHasRequireESM)( |
| 136 | + "without --experimental-require-module flag", |
| 137 | + () => { |
| 138 | + it("sync", async () => { |
| 139 | + const { stdout } = await run( |
| 140 | + "transform-sync-esm-plugin.mjs", |
| 141 | + "--experimental-require-module", |
| 142 | + ); |
| 143 | + expect(stdout).toMatchInlineSnapshot(` |
134 | 144 | "\\"Replaced!\\"; |
135 | 145 | " |
136 | 146 | `); |
137 | | - }); |
138 | | - |
139 | | - it("top-level await", async () => { |
140 | | - await expect( |
141 | | - run( |
142 | | - "transform-sync-esm-plugin-tla.mjs", |
| 147 | + }); |
| 148 | + |
| 149 | + it("top-level await", async () => { |
| 150 | + await expect( |
| 151 | + run( |
| 152 | + "transform-sync-esm-plugin-tla.mjs", |
| 153 | + "--experimental-require-module", |
| 154 | + ), |
| 155 | + ).rejects.toThrow( |
| 156 | + "You appear to be using a plugin that contains top-level await, " + |
| 157 | + "which is only supported when running Babel asynchronously.", |
| 158 | + ); |
| 159 | + }); |
| 160 | + }, |
| 161 | + ); |
| 162 | + |
| 163 | + describeSatisfies(">=20.0.0 < 20.19.0")( |
| 164 | + "with --experimental-require-module flag", |
| 165 | + () => { |
| 166 | + it("sync with --experimental-require-module flag", async () => { |
| 167 | + const { stdout } = await run( |
| 168 | + "transform-sync-esm-plugin.mjs", |
143 | 169 | "--experimental-require-module", |
144 | | - ), |
145 | | - ).rejects.toThrow( |
146 | | - "You appear to be using a plugin that contains top-level await, " + |
147 | | - "which is only supported when running Babel asynchronously.", |
148 | | - ); |
149 | | - }); |
150 | | - }); |
151 | | - |
152 | | - describeGte("20.0.0")("with --experimental-require-module flag", () => { |
153 | | - it("sync with --experimental-require-module flag", async () => { |
154 | | - const { stdout } = await run( |
155 | | - "transform-sync-esm-plugin.mjs", |
156 | | - "--experimental-require-module", |
157 | | - ); |
158 | | - expect(stdout).toMatchInlineSnapshot(` |
| 170 | + ); |
| 171 | + expect(stdout).toMatchInlineSnapshot(` |
159 | 172 | "\\"Replaced!\\"; |
160 | 173 | " |
161 | 174 | `); |
162 | | - }); |
163 | | - |
164 | | - it("top-level await with --experimental-require-module flag", async () => { |
165 | | - await expect( |
166 | | - run( |
167 | | - "transform-sync-esm-plugin-tla.mjs", |
168 | | - "--experimental-require-module", |
169 | | - ), |
170 | | - ).rejects.toThrow( |
171 | | - "You appear to be using a plugin that contains top-level await, " + |
172 | | - "which is only supported when running Babel asynchronously.", |
173 | | - ); |
174 | | - }); |
175 | | - }); |
| 175 | + }); |
| 176 | + |
| 177 | + it("top-level await with --experimental-require-module flag", async () => { |
| 178 | + await expect( |
| 179 | + run( |
| 180 | + "transform-sync-esm-plugin-tla.mjs", |
| 181 | + "--experimental-require-module", |
| 182 | + ), |
| 183 | + ).rejects.toThrow( |
| 184 | + "You appear to be using a plugin that contains top-level await, " + |
| 185 | + "which is only supported when running Babel asynchronously.", |
| 186 | + ); |
| 187 | + }); |
| 188 | + }, |
| 189 | + ); |
176 | 190 | }); |
0 commit comments