diff --git a/test/compiler.ts b/test/compiler.ts index 9e61a73..e1bfa80 100644 --- a/test/compiler.ts +++ b/test/compiler.ts @@ -1,59 +1,8 @@ -import HtmlBundlerPlugin from "html-bundler-webpack-plugin"; -import { join, resolve } from "path"; import webpack, { type Stats } from "webpack"; +import { createWebpackConfig } from "./create-webpack-config.js"; export default (fixture: string): Promise => { - const compiler = webpack({ - mode: "production", - devtool: "source-map", - context: join(import.meta.dirname, "fixture", fixture), - output: { - path: resolve(import.meta.dirname, "../artifacts/test/output", fixture), - filename: "bundle.js", - publicPath: "/path/to/public/", - assetModuleFilename: "[name].public[ext][query]", - }, - plugins: [ - new HtmlBundlerPlugin({ - entry: { - index: "index.html", - }, - loaderOptions: { - sources: [ - { - tag: "meta", - attributes: ["content"], - filter: ({ attributes: { name } }) => - name === "msapplication-config" || - name === "msapplication-TileImage", - }, - ], - }, - }), - ], - module: { - rules: [ - { - test: /\.(png|xml)$/, - type: "asset/resource", - }, - { - test: /\/browserconfig\.xml$/i, - type: "asset/resource", - use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"), - }, - { - test: /\/notification-[135]\.xml$/i, - type: "asset/resource", - generator: { - emit: false, - filename: "[name][ext]", - publicPath: "https://cdn.example.com/", - }, - }, - ], - }, - }); + const compiler = webpack(createWebpackConfig(fixture)); return new Promise((resolve, reject) => { compiler.run((err, stats) => { diff --git a/test/create-webpack-config.d.ts b/test/create-webpack-config.d.ts new file mode 100644 index 0000000..4ecf38d --- /dev/null +++ b/test/create-webpack-config.d.ts @@ -0,0 +1,3 @@ +import { Configuration } from "webpack"; + +declare function createWebpackConfig(fixture: string): Configuration; diff --git a/test/create-webpack-config.js b/test/create-webpack-config.js new file mode 100644 index 0000000..37b42a9 --- /dev/null +++ b/test/create-webpack-config.js @@ -0,0 +1,61 @@ +import HtmlBundlerPlugin from "html-bundler-webpack-plugin"; +import { resolve } from "path"; + +/** + * @param {string} fixture + * @returns {import('webpack').Configuration} + */ +export function createWebpackConfig(fixture) { + return { + mode: "production", + devtool: "source-map", + context: resolve(import.meta.dirname, "fixture", fixture), + entry: "./index.html", + output: { + path: resolve(import.meta.dirname, "../artifacts/integration"), + filename: "bundle.js", + publicPath: "/path/to/public/", + assetModuleFilename: "[name].public[ext][query]", + }, + plugins: [ + new HtmlBundlerPlugin({ + entry: { + index: "index.html", + }, + loaderOptions: { + sources: [ + { + tag: "meta", + attributes: ["content"], + filter: ({ attributes: { name } }) => + name === "msapplication-config" || + name === "msapplication-TileImage", + }, + ], + }, + }), + ], + module: { + rules: [ + { + test: /\.(png|xml)$/, + type: "asset/resource", + }, + { + test: /\/browserconfig\.xml$/i, + type: "asset/resource", + use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"), + }, + { + test: /\/notification-[135]\.xml$/i, + type: "asset/resource", + generator: { + emit: false, + filename: "[name][ext]", + publicPath: "https://cdn.example.com/", + }, + }, + ], + }, + }; +} diff --git a/test/webpack.config.js b/test/webpack.config.js index 70cc51a..2206546 100644 --- a/test/webpack.config.js +++ b/test/webpack.config.js @@ -1,62 +1,7 @@ -import HtmlBundlerPlugin from "html-bundler-webpack-plugin"; -import { resolve } from "path"; +import { createWebpackConfig } from "./create-webpack-config.js"; const fixture = process.env.FIXTURE; if (!fixture) throw new Error("FIXTURE is required"); -/** @type {import('webpack').Configuration} */ -const config = { - mode: "production", - devtool: "source-map", - context: resolve(import.meta.dirname, "fixture", fixture), - entry: "./index.html", - output: { - path: resolve(import.meta.dirname, "../artifacts/integration"), - filename: "bundle.js", - publicPath: "/path/to/public/", - assetModuleFilename: "[name].public[ext][query]", - }, - plugins: [ - new HtmlBundlerPlugin({ - entry: { - index: "index.html", - }, - loaderOptions: { - sources: [ - { - tag: "meta", - attributes: ["content"], - filter: ({ attributes: { name } }) => - name === "msapplication-config" || - name === "msapplication-TileImage", - }, - ], - }, - }), - ], - module: { - rules: [ - { - test: /\.(png|xml)$/, - type: "asset/resource", - }, - { - test: /\/browserconfig\.xml$/i, - type: "asset/resource", - use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"), - }, - { - test: /\/notification-[135]\.xml$/i, - type: "asset/resource", - generator: { - emit: false, - filename: "[name][ext]", - publicPath: "https://cdn.example.com/", - }, - }, - ], - }, -}; - -export default config; +export default createWebpackConfig(fixture);