Skip to content

Commit

Permalink
Add failing test for parallel loading of TLA modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 24, 2024
1 parent 56658ac commit f93b143
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/babel-core/test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as babel from "../lib/index.js";

import {
spawnTransformAsync,
spawnTransformAsyncParallel,
spawnTransformSync,
supportsESM,
} from "./helpers/esm.js";
Expand Down Expand Up @@ -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"` },
]);
},
);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
await Promise.resolve(0);

export default {
plugins: ["./plugin.js"],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "module" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function plugin({ types: t }) {
return {
visitor: {
Program(path) {
path.pushContainer("body", t.stringLiteral("success"));
},
},
};
}
12 changes: 12 additions & 0 deletions packages/babel-core/test/fixtures/babel-compile-async-parallel.mjs
Original file line number Diff line number Diff line change
@@ -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("")
])));
})();
5 changes: 5 additions & 0 deletions packages/babel-core/test/helpers/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f93b143

Please sign in to comment.