Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 8, 2024
1 parent e2e8b74 commit 415e327
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ packages/rspack-plugin-mini-css-extract/test/cases/**/*

crates/**/*
target/**/*
tests/**/*
tests/**/*.*
!tests/**/test.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ module.exports = (env, { testPath }) => [
outputModule: true
}
},
{
output: {
uniqueName: "modern-module",
filename: "modern-module.js",
libraryTarget: "modern-module"
},
target: "node14",
resolve: {
alias: {
external: "./non-external"
}
},
experiments: {
outputModule: true
}
},
{
output: {
uniqueName: "esm-runtimeChunk",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import d from "library";

it("should tree-shake other exports from library (" + NAME + ")", function() {
expect(d).toBe("default-value");
});
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4313"}
module.exports = () => {
// Not all test cases are supported.
// See "https://github.com/web-infra-dev/rspack/issues/4313".
return true;
};
144 changes: 91 additions & 53 deletions tests/webpack-test/configCases/library/1-use-library/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,105 @@ module.exports = (env, { testPath }) => [
]
},
{
resolve: {
alias: {
library: path.resolve(
testPath,
"../0-create-library/esm-runtimeChunk/main.js"
)
}
entry: "./default-test-modern-module.js",
optimization: {
minimize: true
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("esm-runtimeChunk")
})
]
},
{
resolve: {
alias: {
library: path.resolve(testPath, "../0-create-library/commonjs.js")
library: path.resolve(testPath, "../0-create-library/modern-module.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("commonjs")
})
NAME: JSON.stringify("modern-module-tree-shakable")
}),
/**
* @this {Compiler} compiler
*/
function () {
/**
* @param {Compilation} compilation compilation
* @returns {void}
*/
const handler = compilation => {
compilation.hooks.afterProcessAssets.tap("testcase", assets => {
for (const asset of Object.keys(assets)) {
const source = assets[asset].source();
expect(source).not.toContain('"a"');
expect(source).not.toContain('"b"');
expect(source).not.toContain('"non-external"');
}
});
};
this.hooks.compilation.tap("testcase", handler);
}
]
},
{
resolve: {
alias: {
library: path.resolve(testPath, "../0-create-library/commonjs-iife.js")
library: path.resolve(
testPath,
"../0-create-library/esm-runtimeChunk/main.js"
)
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("commonjs-iife")
NAME: JSON.stringify("esm-runtimeChunk")
})
]
},
{
resolve: {
alias: {
library: path.resolve(testPath, "../0-create-library/amd.js")
library: path.resolve(testPath, "../0-create-library/commonjs.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("amd")
NAME: JSON.stringify("commonjs")
})
]
},
{
resolve: {
alias: {
library: path.resolve(testPath, "../0-create-library/amd-iife.js")
library: path.resolve(testPath, "../0-create-library/commonjs-iife.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("amd-iife")
NAME: JSON.stringify("commonjs-iife")
})
]
},
// TODO: https://github.com/web-infra-dev/rspack/issues/4313
// {
// resolve: {
// alias: {
// library: path.resolve(testPath, "../0-create-library/amd.js")
// }
// },
// plugins: [
// new webpack.DefinePlugin({
// NAME: JSON.stringify("amd")
// })
// ]
// },
// {
// resolve: {
// alias: {
// library: path.resolve(testPath, "../0-create-library/amd-iife.js")
// }
// },
// plugins: [
// new webpack.DefinePlugin({
// NAME: JSON.stringify("amd-iife")
// })
// ]
// },
{
externals: {
library: `promise (require(${JSON.stringify(
Expand Down Expand Up @@ -275,23 +312,24 @@ module.exports = (env, { testPath }) => [
})
]
},
{
resolve: {
alias: {
library: path.resolve(
testPath,
"../0-create-library/commonjs-static-external.js"
),
external: path.resolve(__dirname, "node_modules/external.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("commonjs-static with external"),
TEST_EXTERNAL: true
})
]
},
// TODO: https://github.com/web-infra-dev/rspack/issues/4313
// {
// resolve: {
// alias: {
// library: path.resolve(
// testPath,
// "../0-create-library/commonjs-static-external.js"
// ),
// external: path.resolve(__dirname, "node_modules/external.js")
// }
// },
// plugins: [
// new webpack.DefinePlugin({
// NAME: JSON.stringify("commonjs-static with external"),
// TEST_EXTERNAL: true
// })
// ]
// },
{
resolve: {
alias: {
Expand Down Expand Up @@ -387,7 +425,6 @@ module.exports = (env, { testPath }) => [
})
]
},

{
resolve: {
alias: {
Expand All @@ -412,16 +449,17 @@ module.exports = (env, { testPath }) => [
})
]
},
{
resolve: {
alias: {
library: path.resolve(testPath, "../0-create-library/entryC.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("entryC")
})
]
}
// TODO: https://github.com/web-infra-dev/rspack/issues/4313
// {
// resolve: {
// alias: {
// library: path.resolve(testPath, "../0-create-library/entryC.js")
// }
// },
// plugins: [
// new webpack.DefinePlugin({
// NAME: JSON.stringify("entryC")
// })
// ]
// }
];

0 comments on commit 415e327

Please sign in to comment.