Skip to content

Commit

Permalink
test: test case for the cjs extension (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 9, 2023
1 parent 6ad0e55 commit 24119d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/basic.spec.js
Expand Up @@ -2302,6 +2302,23 @@ describe('HtmlWebpackPlugin', () => {
}, ['templateParams keys: "compilation,webpackConfig,htmlWebpackPlugin"'], null, done);
});

it('should add the webpack compilation object as a property of the templateParam object with cjs', done => {
testHtmlPlugin({
mode: 'production',
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'fixtures/templateParam.cjs'),
inject: false
})
]
}, ['templateParams keys: "compilation,webpackConfig,htmlWebpackPlugin"'], null, done);
});

it('should allow to disable template parameters', done => {
testHtmlPlugin({
mode: 'production',
Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/templateParam.cjs
@@ -0,0 +1,21 @@
module.exports = function (templateParams) {
const version = parseInt(process.version.match(/^v(\d+)/)[1]);

if (typeof URL !== 'function') {
throw new Error('Error');
}

if (typeof URLSearchParams !== 'function') {
throw new Error('Error');
}

if (version >= 11 && typeof TextEncoder !== 'function') {
throw new Error('Error');
}

if (version >= 11 && typeof TextDecoder !== 'function') {
throw new Error('Error');
}

return 'templateParams keys: "' + Object.keys(templateParams).join(',') + '"';
};

0 comments on commit 24119d5

Please sign in to comment.