test: more case about cjs bundle to esm lib (#19787)

This commit is contained in:
hai-x 2025-08-13 03:14:02 +08:00 committed by GitHub
parent ad23854a27
commit 61a15a672e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 110 additions and 6 deletions

View File

@ -0,0 +1,5 @@
module.exports = {
name: "adding-exports-cjs"
};
module.exports.foo = "foo";

View File

@ -0,0 +1,3 @@
exports = {
name: "exports-shortcut-cjs"
};

View File

@ -0,0 +1,5 @@
module.exports.foo = "foo";
module.exports = {
name: "overrides-exports-cjs"
};

View File

@ -0,0 +1,3 @@
exports.name
module.name
this.name

View File

@ -806,7 +806,64 @@ module.exports = (env, { testPath }) => [
{ {
entry: "./class-commonjs", entry: "./class-commonjs",
output: { output: {
filename: "commonjs-bundle-to-esm.mjs", uniqueName: "class-commonjs",
filename: "commonjs-bundle-to-esm-1.mjs",
module: true,
library: {
type: "module"
}
},
experiments: {
outputModule: true
}
},
{
entry: "./exports-shortcut-cjs",
output: {
uniqueName: "exports-shortcut-cjs",
filename: "commonjs-bundle-to-esm-2.mjs",
module: true,
library: {
type: "module"
}
},
experiments: {
outputModule: true
}
},
{
entry: "./overrides-exports-cjs",
output: {
uniqueName: "overrides-exports-cjs",
filename: "commonjs-bundle-to-esm-3.mjs",
module: true,
library: {
type: "module"
}
},
experiments: {
outputModule: true
}
},
{
entry: "./self-reference-cjs",
output: {
uniqueName: "self-reference-cjs",
filename: "commonjs-bundle-to-esm-4.mjs",
module: true,
library: {
type: "module"
}
},
experiments: {
outputModule: true
}
},
{
entry: "./adding-exports-cjs",
output: {
uniqueName: "adding-exports-cjs",
filename: "commonjs-bundle-to-esm-5.mjs",
module: true, module: true,
library: { library: {
type: "module" type: "module"

View File

@ -1,8 +1,19 @@
import library from "library"; import lib1 from "lib1";
import lib2 from "lib2";
import lib3 from "lib3";
import lib4 from "lib4";
import lib5 from "lib5";
it( it(
"should be able to import harmony exports from library (" + NAME + ")", "should be able to import harmony exports from library (" + NAME + ")",
function () { function () {
expect(new library().getNumber()).toBe(1); expect(new lib1().getNumber()).toBe(1);
expect(lib2).toMatchObject({});
expect(lib3.name).toBe("overrides-exports-cjs");
expect(lib3.foo).toBe(undefined);
expect(lib4).toEqual({});
expect(lib5.name).toBe("adding-exports-cjs")
expect(lib5.foo).toBe("foo")
} }
); );

View File

@ -695,9 +695,29 @@ module.exports = (env, { testPath }) => [
}, },
experiments: { outputModule: true }, experiments: { outputModule: true },
externals: { externals: {
library: path.resolve( lib1: path.resolve(
testPath, testPath,
"../0-create-library/commonjs-bundle-to-esm.mjs" "../0-create-library/commonjs-bundle-to-esm-1.mjs"
),
lib2: path.resolve(
testPath,
"../0-create-library/commonjs-bundle-to-esm-2.mjs"
),
lib3: path.resolve(
testPath,
"../0-create-library/commonjs-bundle-to-esm-3.mjs"
),
lib4: path.resolve(
testPath,
"../0-create-library/commonjs-bundle-to-esm-4.mjs"
),
lib5: path.resolve(
testPath,
"../0-create-library/commonjs-bundle-to-esm-5.mjs"
),
lib6: path.resolve(
testPath,
"../0-create-library/commonjs-bundle-to-esm-6.mjs"
) )
}, },
externalsType: "module-import", externalsType: "module-import",