From a52f9aa745ebe4c4b411ce2ce8a295042302f467 Mon Sep 17 00:00:00 2001 From: Ben Heidemann Date: Sun, 21 Mar 2021 13:38:28 +0000 Subject: [PATCH] test: enable building tests with webpack as well as parcel --- tests/webpack-tests.js | 8 ++++++ tests/webpack.config.js | 61 ++++++++++++++++++++++++++++++++++++++++ tests/webpack.index.html | 10 +++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/webpack-tests.js create mode 100644 tests/webpack.config.js create mode 100644 tests/webpack.index.html diff --git a/tests/webpack-tests.js b/tests/webpack-tests.js new file mode 100644 index 0000000..29e1dd0 --- /dev/null +++ b/tests/webpack-tests.js @@ -0,0 +1,8 @@ +// Include the mocha css +require('mocha/mocha.css'); + +// Setup mocha and set it to run tests on window load +require('./setup-mocha'); + +// Add any new tests to `tests/index.js` +require('./index'); diff --git a/tests/webpack.config.js b/tests/webpack.config.js new file mode 100644 index 0000000..eb14a64 --- /dev/null +++ b/tests/webpack.config.js @@ -0,0 +1,61 @@ +const webpack = require('webpack'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const path = require('path'); + +module.exports = env => ({ + mode: 'development', + entry: path.resolve(__dirname, './webpack-tests.js'), + resolve: { + alias: { + 'fsProvider': path.resolve(__dirname, '../shims/providers/default'), + }, + }, + output: { + path: path.resolve(__dirname, './dist-webpack'), + filename: 'index.js', + }, + plugins: [ + new webpack.ContextReplacementPlugin( + // Mocha safely uses require in such a way that webpack cannot statically extract dependancies. + // If the ignoreRequestDependancyExpressionWarnings env is set, we will aggregate these warnings + // into one summary warning to minimise spamming the console. + /\/node_modules\/mocha\/lib/, + (data) => { + if (env.ignoreRequestDependancyExpressionWarnings) { + let requestDependencyExpressionsIgnored = 0; + data.dependencies.forEach((dependancy) => { + if (dependancy.critical === 'the request of a dependency is an expression') { + dependancy.critical = undefined; + requestDependencyExpressionsIgnored += 1; + } + }); + console.log(`WARNING: Ignoring ${requestDependencyExpressionsIgnored} "request of a dependency is an expression" warnings from "node_modules/mocha/lib".`); + } + return data; + }, + ), + new NodePolyfillPlugin(), + new MiniCssExtractPlugin(), + new HtmlWebpackPlugin({ + title: 'Filer Tests - Webpack Build', + template: './tests/webpack.index.html', + }), + ], + module: { + rules: [ + { + test: /\.css$/i, + use: [MiniCssExtractPlugin.loader, 'css-loader'], + }, + ], + }, + optimization: { + minimize: false, + }, + devtool: 'inline-source-map', + devServer: { + contentBase: path.resolve(__dirname, './dist-webpack'), + } +}); diff --git a/tests/webpack.index.html b/tests/webpack.index.html new file mode 100644 index 0000000..421df15 --- /dev/null +++ b/tests/webpack.index.html @@ -0,0 +1,10 @@ + + + + + <%= htmlWebpackPlugin.options.title %> + + +
+ + \ No newline at end of file