|
| 1 | +import path from "path"; |
| 2 | + |
| 3 | +import WISLWebpackTestCompiler from "./helpers/WISLWebpackTestCompiler"; |
| 4 | + |
| 5 | +describe.each([4, 5] as const)( |
| 6 | + "v%d resize loader with options", |
| 7 | + (webpackVersion) => { |
| 8 | + it("should work with options in webpackConfig", async () => { |
| 9 | + const compiler = new WISLWebpackTestCompiler({ webpackVersion }); |
| 10 | + const bundle = await compiler.compile({ |
| 11 | + loaderOptions: { |
| 12 | + sizes: ["300w", "original"], |
| 13 | + }, |
| 14 | + resizeLoaderOptions: { |
| 15 | + quality: 80, |
| 16 | + }, |
| 17 | + }); |
| 18 | + |
| 19 | + expect(bundle.execute("main.js")).toMatchSnapshot("result"); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should work with options in query", async () => { |
| 23 | + const loaderPath = path.resolve(__dirname, "../../test-dist/cjs.js"); |
| 24 | + const loaderOptions = { |
| 25 | + sizes: ["300w", "original"], |
| 26 | + }; |
| 27 | + const loaderOptionsString = JSON.stringify(loaderOptions); |
| 28 | + const resizeLoaderOptions = { |
| 29 | + quality: 80, |
| 30 | + }; |
| 31 | + const resizeLoaderOptionssString = JSON.stringify(resizeLoaderOptions); |
| 32 | + |
| 33 | + const compiler = new WISLWebpackTestCompiler({ webpackVersion }); |
| 34 | + const bundle = await compiler.compile({ |
| 35 | + fileContentOverride: `__export__ = require('-!${loaderPath}?${loaderOptionsString}!webpack-image-resize-loader?${resizeLoaderOptionssString}!./Macaca_nigra_self-portrait_large.jpg');`, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(bundle.execute("main.js")).toMatchSnapshot("result"); |
| 39 | + }); |
| 40 | + } |
| 41 | +); |
0 commit comments