Skip to content

Commit 24119d5

Browse files
test: test case for the cjs extension (#1799)
1 parent 6ad0e55 commit 24119d5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spec/basic.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,23 @@ describe('HtmlWebpackPlugin', () => {
23022302
}, ['templateParams keys: "compilation,webpackConfig,htmlWebpackPlugin"'], null, done);
23032303
});
23042304

2305+
it('should add the webpack compilation object as a property of the templateParam object with cjs', done => {
2306+
testHtmlPlugin({
2307+
mode: 'production',
2308+
entry: path.join(__dirname, 'fixtures/index.js'),
2309+
output: {
2310+
path: OUTPUT_DIR,
2311+
filename: 'index_bundle.js'
2312+
},
2313+
plugins: [
2314+
new HtmlWebpackPlugin({
2315+
template: path.join(__dirname, 'fixtures/templateParam.cjs'),
2316+
inject: false
2317+
})
2318+
]
2319+
}, ['templateParams keys: "compilation,webpackConfig,htmlWebpackPlugin"'], null, done);
2320+
});
2321+
23052322
it('should allow to disable template parameters', done => {
23062323
testHtmlPlugin({
23072324
mode: 'production',

spec/fixtures/templateParam.cjs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = function (templateParams) {
2+
const version = parseInt(process.version.match(/^v(\d+)/)[1]);
3+
4+
if (typeof URL !== 'function') {
5+
throw new Error('Error');
6+
}
7+
8+
if (typeof URLSearchParams !== 'function') {
9+
throw new Error('Error');
10+
}
11+
12+
if (version >= 11 && typeof TextEncoder !== 'function') {
13+
throw new Error('Error');
14+
}
15+
16+
if (version >= 11 && typeof TextDecoder !== 'function') {
17+
throw new Error('Error');
18+
}
19+
20+
return 'templateParams keys: "' + Object.keys(templateParams).join(',') + '"';
21+
};

0 commit comments

Comments
 (0)