Specify runtime exports (#10853)
This commit is contained in:
3
test/esm/README.md
Normal file
3
test/esm/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# test/esm
|
||||
|
||||
Holds esm related test for `@babel/*` packages. They should be migrated to Jest tests once Jest supports esm
|
||||
69
test/esm/babel-runtime-corejs3.mjs
Normal file
69
test/esm/babel-runtime-corejs3.mjs
Normal file
@@ -0,0 +1,69 @@
|
||||
import assert from "assert";
|
||||
|
||||
export default {
|
||||
title: "@babel/runtime-corejs3",
|
||||
testcases: [
|
||||
[
|
||||
"it should throw on unknown helpers",
|
||||
() =>
|
||||
assert.rejects(
|
||||
async () =>
|
||||
import("@babel/runtime-corejs3/helpers/esm/unknown-helper"),
|
||||
{
|
||||
name: "Error",
|
||||
code: "ERR_MODULE_NOT_FOUND",
|
||||
}
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on helpers importing internal helpers",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () =>
|
||||
import("@babel/runtime-corejs3/helpers/esm/wrapNativeSuper"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it supports importing with explicit extension",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime/helpers/esm/wrapNativeSuper.js"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on importing core-js helpers",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime-corejs3/core-js/array/is-array"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on importing core-js helpers with explicit extension",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () =>
|
||||
import("@babel/runtime-corejs3/core-js/array/is-array.js"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on importing regenerator helpers",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime-corejs3/regenerator"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on importing regenerator helpers with explicit extension",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime-corejs3/regenerator/index.js"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
],
|
||||
};
|
||||
34
test/esm/babel-runtime.mjs
Normal file
34
test/esm/babel-runtime.mjs
Normal file
@@ -0,0 +1,34 @@
|
||||
import assert from "assert";
|
||||
|
||||
export default {
|
||||
title: "@babel/runtime",
|
||||
testcases: [
|
||||
[
|
||||
"it should throw on unknown helpers",
|
||||
() =>
|
||||
assert.rejects(
|
||||
async () => import("@babel/runtime/helpers/esm/unknown-helper"),
|
||||
{
|
||||
name: "Error",
|
||||
code: "ERR_MODULE_NOT_FOUND",
|
||||
}
|
||||
),
|
||||
],
|
||||
[
|
||||
"it supports importing with explicit extension",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime/helpers/esm/wrapNativeSuper.js"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
[
|
||||
"it should not throw on helpers importing internal helpers",
|
||||
() =>
|
||||
assert.doesNotReject(
|
||||
async () => import("@babel/runtime/helpers/esm/wrapNativeSuper"),
|
||||
Error
|
||||
),
|
||||
],
|
||||
],
|
||||
};
|
||||
8
test/esm/index.mjs
Normal file
8
test/esm/index.mjs
Normal file
@@ -0,0 +1,8 @@
|
||||
import babelRuntimeTestcases from "./babel-runtime.mjs";
|
||||
import babelRuntimeCorejs3Testcases from "./babel-runtime-corejs3.mjs";
|
||||
import testRunner from "./test-runner.mjs";
|
||||
|
||||
(async () => {
|
||||
await testRunner(babelRuntimeTestcases);
|
||||
await testRunner(babelRuntimeCorejs3Testcases);
|
||||
})();
|
||||
11
test/esm/package.json
Normal file
11
test/esm/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@babel/test-esm",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": "./index.mjs",
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "workspace:*",
|
||||
"@babel/runtime-corejs3": "workspace:*",
|
||||
"chalk": "^4.1.0"
|
||||
}
|
||||
}
|
||||
15
test/esm/test-runner.mjs
Normal file
15
test/esm/test-runner.mjs
Normal file
@@ -0,0 +1,15 @@
|
||||
import chalk from "chalk";
|
||||
|
||||
export default async function testRunner({ title, testcases }) {
|
||||
console.log(title);
|
||||
const indent = " ";
|
||||
for (const [subtitle, testcase] of testcases) {
|
||||
try {
|
||||
await testcase();
|
||||
console.log(chalk.green(indent + "✓ " + subtitle));
|
||||
} catch (e) {
|
||||
console.log(chalk.red(indent + "✗ " + subtitle));
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user