From f93b143e1775f0ebebf629319dbe98249b1bcc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 24 Oct 2024 14:32:41 +0200 Subject: [PATCH] Add failing test for parallel loading of TLA modules --- packages/babel-core/test/async.js | 13 +++++++++++++ .../async/config-mjs-tla-native/babel.config.js | 5 +++++ .../async/config-mjs-tla-native/package.json | 1 + .../fixtures/async/config-mjs-tla-native/plugin.js | 9 +++++++++ .../test/fixtures/babel-compile-async-parallel.mjs | 12 ++++++++++++ packages/babel-core/test/helpers/esm.js | 5 +++++ 6 files changed, 45 insertions(+) create mode 100644 packages/babel-core/test/fixtures/async/config-mjs-tla-native/babel.config.js create mode 100644 packages/babel-core/test/fixtures/async/config-mjs-tla-native/package.json create mode 100644 packages/babel-core/test/fixtures/async/config-mjs-tla-native/plugin.js create mode 100755 packages/babel-core/test/fixtures/babel-compile-async-parallel.mjs diff --git a/packages/babel-core/test/async.js b/packages/babel-core/test/async.js index 9898948f81fb..570af51bc2da 100644 --- a/packages/babel-core/test/async.js +++ b/packages/babel-core/test/async.js @@ -4,6 +4,7 @@ import * as babel from "../lib/index.js"; import { spawnTransformAsync, + spawnTransformAsyncParallel, spawnTransformSync, supportsESM, } from "./helpers/esm.js"; @@ -253,6 +254,18 @@ describe("asynchronicity", () => { code: `"success"`, }); }); + + nodeGte14( + "called asynchronously twice in parallel when contain TLA", + async () => { + process.chdir("config-mjs-tla-native"); + + await expect(spawnTransformAsyncParallel()).resolves.toMatchObject([ + { code: `"success"` }, + { code: `"success"` }, + ]); + }, + ); }); }); diff --git a/packages/babel-core/test/fixtures/async/config-mjs-tla-native/babel.config.js b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/babel.config.js new file mode 100644 index 000000000000..221fad0b79a4 --- /dev/null +++ b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/babel.config.js @@ -0,0 +1,5 @@ +await Promise.resolve(0); + +export default { + plugins: ["./plugin.js"], +}; diff --git a/packages/babel-core/test/fixtures/async/config-mjs-tla-native/package.json b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/package.json new file mode 100644 index 000000000000..bb34440a3652 --- /dev/null +++ b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/package.json @@ -0,0 +1 @@ +{ "type": "module" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/async/config-mjs-tla-native/plugin.js b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/plugin.js new file mode 100644 index 000000000000..10195347cc37 --- /dev/null +++ b/packages/babel-core/test/fixtures/async/config-mjs-tla-native/plugin.js @@ -0,0 +1,9 @@ +export default function plugin({ types: t }) { + return { + visitor: { + Program(path) { + path.pushContainer("body", t.stringLiteral("success")); + }, + }, + }; +} diff --git a/packages/babel-core/test/fixtures/babel-compile-async-parallel.mjs b/packages/babel-core/test/fixtures/babel-compile-async-parallel.mjs new file mode 100755 index 000000000000..25689af9d977 --- /dev/null +++ b/packages/babel-core/test/fixtures/babel-compile-async-parallel.mjs @@ -0,0 +1,12 @@ +#!/usr/bin/env node + +// Usage: +// babel-compile-async-parallel.js [filename] +import { transformAsync } from "../../lib/index.js"; + +(async () => { + process.stdout.write(JSON.stringify(await Promise.all([ + transformAsync(""), + transformAsync("") + ]))); +})(); diff --git a/packages/babel-core/test/helpers/esm.js b/packages/babel-core/test/helpers/esm.js index 6c3c1408b2cb..9d0154095b88 100644 --- a/packages/babel-core/test/helpers/esm.js +++ b/packages/babel-core/test/helpers/esm.js @@ -38,6 +38,11 @@ export function spawnTransformAsync() { return spawn("compile-async"); } +export function spawnTransformAsyncParallel() { + // import() crashes with jest + return spawn("compile-async-parallel"); +} + export function spawnTransformSync() { // import() crashes with jest return spawn("compile-sync");