From fbb57b13e40ea3705b82cb3a87c6abee6dd33dfe Mon Sep 17 00:00:00 2001 From: Alexander Akait Date: Thu, 12 Nov 2020 18:46:12 +0300 Subject: [PATCH] style: prettier default (#220) --- .eslintrc.js | 2 +- .prettierrc.js | 1 - README.md | 30 +- babel.config.js | 4 +- commitlint.config.js | 2 +- husky.config.js | 4 +- jest.config.js | 4 +- lint-staged.config.js | 4 +- src/Webpack4Cache.js | 10 +- src/Webpack5Cache.js | 2 +- src/cjs.js | 2 +- src/index.js | 64 ++-- test/CompressionPlugin.test.js | 302 +++++++++--------- test/algorithm.test.js | 42 +-- test/cache-option.test.js | 190 +++++------ test/cjs.test.js | 8 +- test/compressionOptions-option.test.js | 62 ++-- test/deleteOriginalAssets.test.js | 70 ++-- test/exclude-option.test.js | 26 +- test/filename-option.test.js | 74 ++--- test/helpers/CopyPluginWithAssetInfo.js | 4 +- test/helpers/ModifyExistingAsset.js | 6 +- test/helpers/execute.js | 8 +- test/helpers/getAssetsNameAndSize.js | 4 +- test/helpers/getCacheDirectory.js | 6 +- test/helpers/getCompiler.js | 22 +- test/helpers/getErrors.js | 2 +- test/helpers/getWarnings.js | 2 +- test/helpers/index.js | 24 +- test/helpers/loader-with-child-compilation.js | 4 +- test/helpers/normalizeErrors.js | 10 +- test/helpers/readAsset.js | 6 +- test/helpers/readAssets.js | 2 +- test/helpers/removeCache.js | 4 +- test/helpers/snapshotResolver.js | 16 +- test/include-option.test.js | 26 +- test/minRatio-option.test.js | 22 +- test/test-option.test.js | 42 +-- test/threshold-option.test.js | 38 +-- test/validate-options.test.js | 58 ++-- 40 files changed, 604 insertions(+), 605 deletions(-) delete mode 100644 .prettierrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 095ce2a..29e7717 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,4 @@ module.exports = { root: true, - extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'], + extends: ["@webpack-contrib/eslint-config-webpack", "prettier"], }; diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 4f14003..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { singleQuote: true }; diff --git a/README.md b/README.md index 67318a7..862d561 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Then add the plugin to your `webpack` config. For example: **webpack.config.js** ```js -const CompressionPlugin = require('compression-webpack-plugin'); +const CompressionPlugin = require("compression-webpack-plugin"); module.exports = { plugins: [new CompressionPlugin()], @@ -129,7 +129,7 @@ The algorithm is taken from [zlib](https://nodejs.org/api/zlib.html). module.exports = { plugins: [ new CompressionPlugin({ - algorithm: 'gzip', + algorithm: "gzip", }), ], }; @@ -259,7 +259,7 @@ For example we have `assets/images/image.png?foo=bar#hash`: module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path][base].gz', + filename: "[path][base].gz", }), ], }; @@ -277,10 +277,10 @@ module.exports = { // The `pathData` argument contains all placeholders - `path`/`name`/`ext`/etc // Available properties described above, for the `String` notation if (/\.svg$/.test(pathData.file)) { - return 'assets/svg/[path][base].gz'; + return "assets/svg/[path][base].gz"; } - return 'assets/js/[path][base].gz'; + return "assets/js/[path][base].gz"; }, }), ], @@ -355,7 +355,7 @@ Enable file caching and set path to cache directory. module.exports = { plugins: [ new CompressionPlugin({ - cache: 'path/to/cache', + cache: "path/to/cache", }), ], }; @@ -378,7 +378,7 @@ $ npm install @gfx/zopfli --save-dev **webpack.config.js** ```js -const zopfli = require('@gfx/zopfli'); +const zopfli = require("@gfx/zopfli"); module.exports = { plugins: [ @@ -405,13 +405,13 @@ We can take advantage of this built-in support for Brotli in Node 10.16.0 and la **webpack.config.js** ```js -const zlib = require('zlib'); +const zlib = require("zlib"); module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path][base].br', - algorithm: 'brotliCompress', + filename: "[path][base].br", + algorithm: "brotliCompress", test: /\.(js|css|html|svg)$/, compressionOptions: { params: { @@ -434,20 +434,20 @@ You can find all Brotli’s options in [the relevant part of the zlib module doc **webpack.config.js** ```js -const zlib = require('zlib'); +const zlib = require("zlib"); module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path][base].gz', - algorithm: 'gzip', + filename: "[path][base].gz", + algorithm: "gzip", test: /\.js$|\.css$|\.html$/, threshold: 10240, minRatio: 0.8, }), new CompressionPlugin({ - filename: '[path][base].br', - algorithm: 'brotliCompress', + filename: "[path][base].br", + algorithm: "brotliCompress", test: /\.(js|css|html|svg)$/, compressionOptions: { params: { diff --git a/babel.config.js b/babel.config.js index 190c338..65000d4 100644 --- a/babel.config.js +++ b/babel.config.js @@ -7,10 +7,10 @@ module.exports = (api) => { return { presets: [ [ - '@babel/preset-env', + "@babel/preset-env", { targets: { - node: '10.13.0', + node: "10.13.0", }, }, ], diff --git a/commitlint.config.js b/commitlint.config.js index 84dcb12..69b4242 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,3 @@ module.exports = { - extends: ['@commitlint/config-conventional'], + extends: ["@commitlint/config-conventional"], }; diff --git a/husky.config.js b/husky.config.js index 4c2ec3a..6cf9b3f 100644 --- a/husky.config.js +++ b/husky.config.js @@ -1,6 +1,6 @@ module.exports = { hooks: { - 'pre-commit': 'lint-staged', - 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', + "pre-commit": "lint-staged", + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", }, }; diff --git a/jest.config.js b/jest.config.js index c89d4ff..eafaef1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,4 @@ module.exports = { - testEnvironment: 'node', - snapshotResolver: './test/helpers/snapshotResolver.js', + testEnvironment: "node", + snapshotResolver: "./test/helpers/snapshotResolver.js", }; diff --git a/lint-staged.config.js b/lint-staged.config.js index c417cb1..dc1bf51 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ module.exports = { - '*.js': ['prettier --write', 'eslint --fix'], - '*.{json,md,yml,css,ts}': ['prettier --write'], + "*.js": ["eslint --fix", "prettier --write"], + "*.{json,md,yml,css,ts}": ["prettier --write"], }; diff --git a/src/Webpack4Cache.js b/src/Webpack4Cache.js index 5113ac8..0937eba 100644 --- a/src/Webpack4Cache.js +++ b/src/Webpack4Cache.js @@ -1,8 +1,8 @@ -import os from 'os'; +import os from "os"; -import cacache from 'cacache'; -import findCacheDir from 'find-cache-dir'; -import serialize from 'serialize-javascript'; +import cacache from "cacache"; +import findCacheDir from "find-cache-dir"; +import serialize from "serialize-javascript"; export default class Webpack4Cache { constructor(compilation, options, weakCache) { @@ -14,7 +14,7 @@ export default class Webpack4Cache { } static getCacheDirectory() { - return findCacheDir({ name: 'compression-webpack-plugin' }) || os.tmpdir(); + return findCacheDir({ name: "compression-webpack-plugin" }) || os.tmpdir(); } async get(cacheData, { RawSource }) { diff --git a/src/Webpack5Cache.js b/src/Webpack5Cache.js index 1500d71..ac6e321 100644 --- a/src/Webpack5Cache.js +++ b/src/Webpack5Cache.js @@ -1,6 +1,6 @@ export default class Cache { constructor(compilation) { - this.cache = compilation.getCache('CompressionWebpackPlugin'); + this.cache = compilation.getCache("CompressionWebpackPlugin"); } async get(cacheData) { diff --git a/src/cjs.js b/src/cjs.js index 82657ce..0f29dbe 100644 --- a/src/cjs.js +++ b/src/cjs.js @@ -1 +1 @@ -module.exports = require('./index').default; +module.exports = require("./index").default; diff --git a/src/index.js b/src/index.js index 92bcee3..cccccd4 100644 --- a/src/index.js +++ b/src/index.js @@ -3,27 +3,27 @@ Author Tobias Koppers @sokra */ -import crypto from 'crypto'; -import path from 'path'; +import crypto from "crypto"; +import path from "path"; import webpack, { ModuleFilenameHelpers, version as webpackVersion, -} from 'webpack'; -import { validate } from 'schema-utils'; -import serialize from 'serialize-javascript'; +} from "webpack"; +import { validate } from "schema-utils"; +import serialize from "serialize-javascript"; -import schema from './options.json'; +import schema from "./options.json"; const { RawSource } = // eslint-disable-next-line global-require - webpack.sources || require('webpack-sources'); + webpack.sources || require("webpack-sources"); class CompressionPlugin { constructor(options = {}) { validate(schema, options, { - name: 'Compression Plugin', - baseDataPath: 'options', + name: "Compression Plugin", + baseDataPath: "options", }); const { @@ -31,9 +31,9 @@ class CompressionPlugin { include, exclude, cache = true, - algorithm = 'gzip', + algorithm = "gzip", compressionOptions = {}, - filename = '[path][base].gz', + filename = "[path][base].gz", threshold = 0, minRatio = 0.8, deleteOriginalAssets = false, @@ -54,9 +54,9 @@ class CompressionPlugin { this.algorithm = this.options.algorithm; - if (typeof this.algorithm === 'string') { + if (typeof this.algorithm === "string") { // eslint-disable-next-line global-require - const zlib = require('zlib'); + const zlib = require("zlib"); this.algorithm = zlib[this.algorithm]; @@ -157,7 +157,7 @@ class CompressionPlugin { async compress(compilation, assets, CacheEngine, weakCache) { const assetNames = Object.keys( - typeof assets === 'undefined' ? compilation.assets : assets + typeof assets === "undefined" ? compilation.assets : assets ).filter((assetName) => // eslint-disable-next-line no-undefined ModuleFilenameHelpers.matchObject.bind(undefined, this.options)(assetName) @@ -188,18 +188,18 @@ class CompressionPlugin { let relatedName; - if (typeof this.options.algorithm === 'function') { + if (typeof this.options.algorithm === "function") { let filenameForRelatedName = this.options.filename; - const index = filenameForRelatedName.lastIndexOf('?'); + const index = filenameForRelatedName.lastIndexOf("?"); if (index >= 0) { filenameForRelatedName = filenameForRelatedName.substr(0, index); } relatedName = `${path.extname(filenameForRelatedName).slice(1)}ed`; - } else if (this.options.algorithm === 'gzip') { - relatedName = 'gzipped'; + } else if (this.options.algorithm === "gzip") { + relatedName = "gzipped"; } else { relatedName = `${this.options.algorithm}ed`; } @@ -224,12 +224,12 @@ class CompressionPlugin { cacheData.cacheKeys = { nodeVersion: process.version, // eslint-disable-next-line global-require - 'compression-webpack-plugin': require('../package.json').version, + "compression-webpack-plugin": require("../package.json").version, algorithm: this.algorithm, originalAlgorithm: this.options.algorithm, compressionOptions: this.options.compressionOptions, name, - contentHash: crypto.createHash('md4').update(input).digest('hex'), + contentHash: crypto.createHash("md4").update(input).digest("hex"), }; } else { cacheData.name = serialize({ @@ -261,8 +261,8 @@ class CompressionPlugin { const match = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(name); const [, replacerFile] = match; - const replacerQuery = match[2] || ''; - const replacerFragment = match[3] || ''; + const replacerQuery = match[2] || ""; + const replacerFragment = match[3] || ""; const replacerExt = path.extname(replacerFile); const replacerBase = path.basename(replacerFile); const replacerName = replacerBase.slice( @@ -280,12 +280,12 @@ class CompressionPlugin { path: replacerPath, base: replacerBase, name: replacerName, - ext: replacerExt || '', + ext: replacerExt || "", }; let newFilename = this.options.filename; - if (typeof newFilename === 'function') { + if (typeof newFilename === "function") { newFilename = newFilename(pathData); } @@ -301,7 +301,7 @@ class CompressionPlugin { } if (this.options.deleteOriginalAssets) { - if (this.options.deleteOriginalAssets === 'keep-source-map') { + if (this.options.deleteOriginalAssets === "keep-source-map") { // TODO `...` required only for webpack@4 const updatedAssetInfo = { ...info, @@ -341,7 +341,7 @@ class CompressionPlugin { } static isWebpack4() { - return webpackVersion[0] === '4'; + return webpackVersion[0] === "4"; } apply(compiler) { @@ -349,7 +349,7 @@ class CompressionPlugin { if (CompressionPlugin.isWebpack4()) { // eslint-disable-next-line global-require - const CacheEngine = require('./Webpack4Cache').default; + const CacheEngine = require("./Webpack4Cache").default; const weakCache = new WeakMap(); compiler.hooks.emit.tapPromise({ name: pluginName }, (compilation) => @@ -358,11 +358,11 @@ class CompressionPlugin { ); } else { // eslint-disable-next-line global-require - const CacheEngine = require('./Webpack5Cache').default; + const CacheEngine = require("./Webpack5Cache").default; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { // eslint-disable-next-line global-require - const Compilation = require('webpack/lib/Compilation'); + const Compilation = require("webpack/lib/Compilation"); compilation.hooks.processAssets.tapPromise( { @@ -374,12 +374,12 @@ class CompressionPlugin { compilation.hooks.statsPrinter.tap(pluginName, (stats) => { stats.hooks.print - .for('asset.info.compressed') + .for("asset.info.compressed") .tap( - 'compression-webpack-plugin', + "compression-webpack-plugin", (compressed, { green, formatFlag }) => // eslint-disable-next-line no-undefined - compressed ? green(formatFlag('compressed')) : undefined + compressed ? green(formatFlag("compressed")) : undefined ); }); }); diff --git a/test/CompressionPlugin.test.js b/test/CompressionPlugin.test.js index 075cfaf..5d58a01 100644 --- a/test/CompressionPlugin.test.js +++ b/test/CompressionPlugin.test.js @@ -1,13 +1,13 @@ -import zlib from 'zlib'; -import path from 'path'; +import zlib from "zlib"; +import path from "path"; -import webpack from 'webpack'; -import findCacheDir from 'find-cache-dir'; -import cacache from 'cacache'; -import WorkboxPlugin from 'workbox-webpack-plugin'; +import webpack from "webpack"; +import findCacheDir from "find-cache-dir"; +import cacache from "cacache"; +import WorkboxPlugin from "workbox-webpack-plugin"; -import Webpack4Cache from '../src/Webpack4Cache'; -import CompressionPlugin from '../src/index'; +import Webpack4Cache from "../src/Webpack4Cache"; +import CompressionPlugin from "../src/index"; import { compile, @@ -18,14 +18,14 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; -const cacheDir1 = findCacheDir({ name: 'compression-webpack-plugin-cache-1' }); -const cacheDir2 = findCacheDir({ name: 'compression-webpack-plugin-cache-2' }); -const cacheDir3 = findCacheDir({ name: 'compression-webpack-plugin-cache-3' }); -const cacheDir4 = findCacheDir({ name: 'compression-webpack-plugin-cache-4' }); +const cacheDir1 = findCacheDir({ name: "compression-webpack-plugin-cache-1" }); +const cacheDir2 = findCacheDir({ name: "compression-webpack-plugin-cache-2" }); +const cacheDir3 = findCacheDir({ name: "compression-webpack-plugin-cache-3" }); +const cacheDir4 = findCacheDir({ name: "compression-webpack-plugin-cache-4" }); -describe('CompressionPlugin', () => { +describe("CompressionPlugin", () => { beforeAll(() => { return Promise.all([ removeCache(), @@ -36,15 +36,15 @@ describe('CompressionPlugin', () => { ]); }); - it('should work', async () => { + it("should work", async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); @@ -53,21 +53,21 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work with assets info', async () => { + it("should work with assets info", async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { - devtool: 'source-map', + devtool: "source-map", output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); @@ -77,21 +77,21 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work child compilations', async () => { - const gzipSpy = jest.spyOn(zlib, 'gzip'); + it("should work child compilations", async () => { + const gzipSpy = jest.spyOn(zlib, "gzip"); const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, module: { rules: [ @@ -100,7 +100,7 @@ describe('CompressionPlugin', () => { rules: [ { loader: require.resolve( - './helpers/loader-with-child-compilation.js' + "./helpers/loader-with-child-compilation.js" ), }, ], @@ -109,7 +109,7 @@ describe('CompressionPlugin', () => { test: /\.(png|jpg|gif|svg)$/i, rules: [ { - loader: 'file-loader', + loader: "file-loader", }, ], }, @@ -123,66 +123,66 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); expect(gzipSpy).toHaveBeenCalledTimes(5); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); gzipSpy.mockRestore(); }); - it('should work with multiple plugins', async () => { + it("should work with multiple plugins", async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); new CompressionPlugin({ - algorithm: 'gzip', - filename: '[path][base].gz', + algorithm: "gzip", + filename: "[path][base].gz", }).apply(compiler); new CompressionPlugin({ - algorithm: 'brotliCompress', - filename: '[path][base].br', + algorithm: "brotliCompress", + filename: "[path][base].br", }).apply(compiler); new CompressionPlugin({ minRatio: Infinity, algorithm: (input, options, callback) => { return callback(null, input); }, - filename: '[path][base].compress', + filename: "[path][base].compress", }).apply(compiler); new CompressionPlugin({ minRatio: Infinity, algorithm: (input, options, callback) => { return callback(null, input); }, - filename: '[path][base].custom?foo=bar#hash', + filename: "[path][base].custom?foo=bar#hash", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and show compress assets in stats', async () => { + it("should work and show compress assets in stats", async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { - stats: 'verbose', + stats: "verbose", output: { path: `${__dirname}/dist`, - filename: '[name].js', - chunkFilename: '[id].[name].js', + filename: "[name].js", + chunkFilename: "[id].[name].js", }, } ); @@ -196,21 +196,21 @@ describe('CompressionPlugin', () => { expect(printedCompressed ? printedCompressed.length : 0).toBe( getCompiler.isWebpack4() ? 0 : 3 ); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and keep assets info', async () => { + it("should work and keep assets info", async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { - stats: 'verbose', + stats: "verbose", output: { path: `${__dirname}/dist`, - filename: '[name].[contenthash].js', - chunkFilename: '[id].[name].[contenthash].js', + filename: "[name].[contenthash].js", + chunkFilename: "[id].[name].[contenthash].js", }, } ); @@ -223,25 +223,25 @@ describe('CompressionPlugin', () => { expect(info.immutable).toBe(true); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should work and use memory cache without options in the "development" mode', async () => { const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return cacheDir1; }); - const compiler = getCompiler('./entry.js', {}, { mode: 'development' }); + const compiler = getCompiler("./entry.js", {}, { mode: "development" }); new CompressionPlugin().apply(compiler); const stats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(stats.compilation.assets).filter( (assetName) => stats.compilation.assets[assetName].emitted @@ -251,14 +251,14 @@ describe('CompressionPlugin', () => { expect(stats.compilation.emittedAssets.size).toBe(7); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); await new Promise(async (resolve) => { const newStats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(newStats.compilation.assets).filter( (assetName) => newStats.compilation.assets[assetName].emitted @@ -269,10 +269,10 @@ describe('CompressionPlugin', () => { } expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); getCacheDirectorySpy.mockRestore(); @@ -282,20 +282,20 @@ describe('CompressionPlugin', () => { it('should work and use memory cache when the "cache" option is "true"', async () => { const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return cacheDir2; }); const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: true, output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js', - chunkFilename: '[id].js', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js", + chunkFilename: "[id].js", }, } ); @@ -304,7 +304,7 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(stats.compilation.assets).filter( (assetName) => stats.compilation.assets[assetName].emitted @@ -314,14 +314,14 @@ describe('CompressionPlugin', () => { expect(stats.compilation.emittedAssets.size).toBe(7); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); await new Promise(async (resolve) => { const newStats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(newStats.compilation.assets).filter( (assetName) => newStats.compilation.assets[assetName].emitted @@ -332,10 +332,10 @@ describe('CompressionPlugin', () => { } expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); getCacheDirectorySpy.mockRestore(); @@ -345,20 +345,20 @@ describe('CompressionPlugin', () => { it('should work and use memory cache when the "cache" option is "true" and the asset has been changed', async () => { const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return cacheDir3; }); const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: true, output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js', - chunkFilename: '[id].js', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js", + chunkFilename: "[id].js", }, } ); @@ -367,7 +367,7 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(stats.compilation.assets).filter( (assetName) => stats.compilation.assets[assetName].emitted @@ -377,16 +377,16 @@ describe('CompressionPlugin', () => { expect(stats.compilation.emittedAssets.size).toBe(7); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); - new ModifyExistingAsset({ name: 'main.js' }).apply(compiler); + new ModifyExistingAsset({ name: "main.js" }).apply(compiler); await new Promise(async (resolve) => { const newStats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(newStats.compilation.assets).filter( (assetName) => newStats.compilation.assets[assetName].emitted @@ -397,10 +397,10 @@ describe('CompressionPlugin', () => { } expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); getCacheDirectorySpy.mockRestore(); @@ -410,43 +410,43 @@ describe('CompressionPlugin', () => { it('should work and use memory cache when the "cache" option is "true" with multiple plugins', async () => { const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return cacheDir4; }); const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: true, output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js', - chunkFilename: '[id].js', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js", + chunkFilename: "[id].js", }, } ); new CompressionPlugin({ - filename: '[path][base].gz', - algorithm: 'gzip', + filename: "[path][base].gz", + algorithm: "gzip", }).apply(compiler); new CompressionPlugin({ - filename: '[path][base].br', - algorithm: 'brotliCompress', + filename: "[path][base].br", + algorithm: "brotliCompress", }).apply(compiler); new CompressionPlugin({ minRatio: Infinity, algorithm: (input, options, callback) => { return callback(null, input); }, - filename: '[path][base].custom', + filename: "[path][base].custom", }).apply(compiler); const stats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(stats.compilation.assets).filter( (assetName) => stats.compilation.assets[assetName].emitted @@ -456,14 +456,14 @@ describe('CompressionPlugin', () => { expect(stats.compilation.emittedAssets.size).toBe(14); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); await new Promise(async (resolve) => { const newStats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(newStats.compilation.assets).filter( (assetName) => newStats.compilation.assets[assetName].emitted @@ -474,10 +474,10 @@ describe('CompressionPlugin', () => { } expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); getCacheDirectorySpy.mockRestore(); @@ -487,27 +487,27 @@ describe('CompressionPlugin', () => { it('should work and do not use memory cache when the "cache" option is "false"', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", { - name: '[name].[ext]', + name: "[name].[ext]", }, { cache: false, output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js', - chunkFilename: '[id].[name].js', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js", + chunkFilename: "[id].[name].js", }, } ); new CompressionPlugin( - webpack.version[0] === '4' ? { cache: false } : {} + webpack.version[0] === "4" ? { cache: false } : {} ).apply(compiler); const stats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(stats.compilation.assets).filter( (assetName) => stats.compilation.assets[assetName].emitted @@ -517,14 +517,14 @@ describe('CompressionPlugin', () => { expect(stats.compilation.emittedAssets.size).toBe(7); } - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); await new Promise(async (resolve) => { const newStats = await compile(compiler); - if (webpack.version[0] === '4') { + if (webpack.version[0] === "4") { expect( Object.keys(newStats.compilation.assets).filter( (assetName) => newStats.compilation.assets[assetName].emitted @@ -535,10 +535,10 @@ describe('CompressionPlugin', () => { } expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); resolve(); }); @@ -547,12 +547,12 @@ describe('CompressionPlugin', () => { // TODO https://github.com/webpack-contrib/compression-webpack-plugin/issues/218 it.skip('should work with "workbox-webpack-plugin" plugin ("GenerateSW")', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - filename: '[name].js', - chunkFilename: '[id].[name].js', + filename: "[name].js", + chunkFilename: "[id].[name].js", }, } ); @@ -562,35 +562,35 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); // TODO https://github.com/webpack-contrib/compression-webpack-plugin/issues/218 it.skip('should work with "workbox-webpack-plugin" plugin ("InjectManifest")', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - filename: '[name].js', - chunkFilename: '[id].[name].js', + filename: "[name].js", + chunkFilename: "[id].[name].js", }, } ); new WorkboxPlugin.InjectManifest({ - swSrc: path.resolve(__dirname, './fixtures/sw.js'), - swDest: 'sw.js', + swSrc: path.resolve(__dirname, "./fixtures/sw.js"), + swDest: "sw.js", exclude: [/\.(gz|br)$/], }).apply(compiler); new CompressionPlugin().apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/algorithm.test.js b/test/algorithm.test.js index 7606663..8564cab 100644 --- a/test/algorithm.test.js +++ b/test/algorithm.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,44 +7,44 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"algorithm" option', () => { let compiler; beforeEach(() => { - compiler = getCompiler('./entry.js'); + compiler = getCompiler("./entry.js"); return removeCache(); }); - it('matches snapshot for `unknown` value ({String})', () => { + it("matches snapshot for `unknown` value ({String})", () => { expect(() => { new CompressionPlugin({ minRatio: 1, - algorithm: 'unknown', + algorithm: "unknown", }).apply(compiler); }).toThrowErrorMatchingSnapshot(); }); - it('matches snapshot for `gzip` value ({String})', async () => { + it("matches snapshot for `gzip` value ({String})", async () => { new CompressionPlugin({ minRatio: 1, - algorithm: 'gzip', + algorithm: "gzip", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for custom function ({Function})', async () => { + it("matches snapshot for custom function ({Function})", async () => { new CompressionPlugin({ minRatio: 1, algorithm(input, compressionOptions, callback) { - expect(compressionOptions).toMatchSnapshot('compressionOptions'); + expect(compressionOptions).toMatchSnapshot("compressionOptions"); return callback(null, input); }, @@ -52,25 +52,25 @@ describe('"algorithm" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for custom function with error ({Function})', async () => { + it("matches snapshot for custom function with error ({Function})", async () => { new CompressionPlugin({ minRatio: 1, algorithm(input, compressionOptions, callback) { - expect(compressionOptions).toMatchSnapshot('compressionOptions'); + expect(compressionOptions).toMatchSnapshot("compressionOptions"); - return callback('Error', input); + return callback("Error", input); }, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/cache-option.test.js b/test/cache-option.test.js index a4720f0..6b5bb08 100644 --- a/test/cache-option.test.js +++ b/test/cache-option.test.js @@ -1,12 +1,12 @@ -import path from 'path'; -import zlib from 'zlib'; +import path from "path"; +import zlib from "zlib"; -import cacache from 'cacache'; -import findCacheDir from 'find-cache-dir'; -import del from 'del'; +import cacache from "cacache"; +import findCacheDir from "find-cache-dir"; +import del from "del"; -import CompressionPlugin from '../src/index'; -import Webpack4Cache from '../src/Webpack4Cache'; +import CompressionPlugin from "../src/index"; +import Webpack4Cache from "../src/Webpack4Cache"; import { compile, @@ -14,15 +14,15 @@ import { getCompiler, getErrors, getWarnings, -} from './helpers/index'; +} from "./helpers/index"; -const falseCacheDirectory = findCacheDir({ name: 'false-cache-directory' }); -const cacheDir = findCacheDir({ name: 'compression-webpack-plugin' }); -const otherCacheDir = findCacheDir({ name: 'other-cache-directory' }); +const falseCacheDirectory = findCacheDir({ name: "false-cache-directory" }); +const cacheDir = findCacheDir({ name: "compression-webpack-plugin" }); +const otherCacheDir = findCacheDir({ name: "other-cache-directory" }); const otherOtherCacheDir = findCacheDir({ - name: 'other-other-cache-directory', + name: "other-other-cache-directory", }); -const uniqueCacheDirectory = findCacheDir({ name: 'unique-cache-directory' }); +const uniqueCacheDirectory = findCacheDir({ name: "unique-cache-directory" }); if (getCompiler.isWebpack4()) { describe('"cache" option', () => { @@ -36,8 +36,8 @@ if (getCompiler.isWebpack4()) { ]); }); - it('matches snapshot for `false` value ({Boolean})', async () => { - const compiler = getCompiler('./entry.js'); + it("matches snapshot for `false` value ({Boolean})", async () => { + const compiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: false, minRatio: 1 }).apply(compiler); @@ -45,16 +45,16 @@ if (getCompiler.isWebpack4()) { cacache.put = jest.fn(cacache.put); const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return falseCacheDirectory; }); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); // Cache disabled so we don't run `get` or `put` expect(cacache.get.mock.calls.length).toBe(0); @@ -68,8 +68,8 @@ if (getCompiler.isWebpack4()) { getCacheDirectorySpy.mockRestore(); }); - it('matches snapshot for `true` value ({Boolean})', async () => { - const beforeCacheCompiler = getCompiler('./entry.js'); + it("matches snapshot for `true` value ({Boolean})", async () => { + const beforeCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: true, minRatio: 1 }).apply( beforeCacheCompiler @@ -79,7 +79,7 @@ if (getCompiler.isWebpack4()) { cacache.put = jest.fn(cacache.put); const getCacheDirectorySpy = jest - .spyOn(Webpack4Cache, 'getCacheDirectory') + .spyOn(Webpack4Cache, "getCacheDirectory") .mockImplementation(() => { return uniqueCacheDirectory; }); @@ -87,10 +87,10 @@ if (getCompiler.isWebpack4()) { const stats = await compile(beforeCacheCompiler); expect(getAssetsNameAndSize(stats, beforeCacheCompiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); const countAssets = Object.keys(stats.compilation.assets).length; @@ -121,7 +121,7 @@ if (getCompiler.isWebpack4()) { cacache.get.mockClear(); cacache.put.mockClear(); - const afterCacheCompiler = getCompiler('./entry.js'); + const afterCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: true, minRatio: 1 }).apply( afterCacheCompiler @@ -131,9 +131,9 @@ if (getCompiler.isWebpack4()) { expect( getAssetsNameAndSize(newStats, afterCacheCompiler) - ).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + ).toMatchSnapshot("assets"); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); const newCountAssets = Object.keys(newStats.compilation.assets).length; @@ -144,8 +144,8 @@ if (getCompiler.isWebpack4()) { getCacheDirectorySpy.mockRestore(); }); - it('matches snapshot for `other-cache-directory` value ({String})', async () => { - const beforeCacheCompiler = getCompiler('./entry.js'); + it("matches snapshot for `other-cache-directory` value ({String})", async () => { + const beforeCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: otherCacheDir, minRatio: 1 }).apply( beforeCacheCompiler @@ -157,10 +157,10 @@ if (getCompiler.isWebpack4()) { const stats = await compile(beforeCacheCompiler); expect(getAssetsNameAndSize(stats, beforeCacheCompiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); const countAssets = Object.keys(stats.compilation.assets).length; @@ -190,7 +190,7 @@ if (getCompiler.isWebpack4()) { cacache.get.mockClear(); cacache.put.mockClear(); - const afterCacheCompiler = getCompiler('./entry.js'); + const afterCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: otherCacheDir, minRatio: 1 }).apply( afterCacheCompiler @@ -200,9 +200,9 @@ if (getCompiler.isWebpack4()) { expect( getAssetsNameAndSize(newStats, afterCacheCompiler) - ).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + ).toMatchSnapshot("assets"); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); const newCountAssets = Object.keys(newStats.compilation.assets).length; @@ -212,7 +212,7 @@ if (getCompiler.isWebpack4()) { }); it('matches snapshot for `other-other-cache-directory` value ({String}) with the "algorithm" option', async () => { - const beforeCacheCompiler = getCompiler('./entry.js'); + const beforeCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: otherOtherCacheDir, @@ -234,10 +234,10 @@ if (getCompiler.isWebpack4()) { const stats = await compile(beforeCacheCompiler); expect(getAssetsNameAndSize(stats, beforeCacheCompiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); const countAssets = Object.keys(stats.compilation.assets).length; @@ -267,7 +267,7 @@ if (getCompiler.isWebpack4()) { cacache.get.mockClear(); cacache.put.mockClear(); - const afterCacheCompiler = getCompiler('./entry.js'); + const afterCacheCompiler = getCompiler("./entry.js"); new CompressionPlugin({ cache: otherOtherCacheDir, @@ -287,9 +287,9 @@ if (getCompiler.isWebpack4()) { expect( getAssetsNameAndSize(newStats, afterCacheCompiler) - ).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + ).toMatchSnapshot("assets"); + expect(getWarnings(newStats)).toMatchSnapshot("errors"); + expect(getErrors(newStats)).toMatchSnapshot("warnings"); const newCountAssets = Object.keys(newStats.compilation.assets).length; @@ -302,24 +302,24 @@ if (getCompiler.isWebpack4()) { describe('"cache" option', () => { const fileSystemCacheDirectory = path.resolve( __dirname, - './outputs/type-filesystem' + "./outputs/type-filesystem" ); beforeAll(() => { return Promise.all([del(fileSystemCacheDirectory)]); }); - it('should work when `cache` is `false`', async () => { - const compiler = getCompiler('./entry.js', {}, { cache: false }); + it("should work when `cache` is `false`", async () => { + const compiler = getCompiler("./entry.js", {}, { cache: false }); new CompressionPlugin().apply(compiler); let getCounter = 0; compiler.cache.hooks.get.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { getCounter += 1; } } @@ -328,9 +328,9 @@ if (getCompiler.isWebpack4()) { let storeCounter = 0; compiler.cache.hooks.store.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { storeCounter += 1; } } @@ -342,9 +342,9 @@ if (getCompiler.isWebpack4()) { expect(getCounter).toBe(4); // Without cache webpack always try to store expect(storeCounter).toBe(4); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); getCounter = 0; storeCounter = 0; @@ -356,19 +356,19 @@ if (getCompiler.isWebpack4()) { // Without cache webpack always try to store expect(storeCounter).toBe(4); expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getErrors(newStats)).toMatchSnapshot('errors'); - expect(getWarnings(newStats)).toMatchSnapshot('warnings'); + expect(getErrors(newStats)).toMatchSnapshot("errors"); + expect(getWarnings(newStats)).toMatchSnapshot("warnings"); }); it('should work with "memory" value for the "cache.type" option', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: { - type: 'memory', + type: "memory", }, } ); @@ -378,9 +378,9 @@ if (getCompiler.isWebpack4()) { let getCounter = 0; compiler.cache.hooks.get.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { getCounter += 1; } } @@ -389,9 +389,9 @@ if (getCompiler.isWebpack4()) { let storeCounter = 0; compiler.cache.hooks.store.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { storeCounter += 1; } } @@ -403,9 +403,9 @@ if (getCompiler.isWebpack4()) { expect(getCounter).toBe(4); // Store cached assets expect(storeCounter).toBe(4); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); getCounter = 0; storeCounter = 0; @@ -417,19 +417,19 @@ if (getCompiler.isWebpack4()) { // No need to store, we got cached assets expect(storeCounter).toBe(0); expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getErrors(newStats)).toMatchSnapshot('errors'); - expect(getWarnings(newStats)).toMatchSnapshot('warnings'); + expect(getErrors(newStats)).toMatchSnapshot("errors"); + expect(getWarnings(newStats)).toMatchSnapshot("warnings"); }); it('should work with "filesystem" value for the "cache.type" option', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: { - type: 'filesystem', + type: "filesystem", cacheDirectory: fileSystemCacheDirectory, }, } @@ -440,9 +440,9 @@ if (getCompiler.isWebpack4()) { let getCounter = 0; compiler.cache.hooks.get.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { getCounter += 1; } } @@ -451,9 +451,9 @@ if (getCompiler.isWebpack4()) { let storeCounter = 0; compiler.cache.hooks.store.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { storeCounter += 1; } } @@ -465,9 +465,9 @@ if (getCompiler.isWebpack4()) { expect(getCounter).toBe(4); // Store cached assets expect(storeCounter).toBe(4); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); getCounter = 0; storeCounter = 0; @@ -479,19 +479,19 @@ if (getCompiler.isWebpack4()) { // No need to store, we got cached assets expect(storeCounter).toBe(0); expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getErrors(newStats)).toMatchSnapshot('errors'); - expect(getWarnings(newStats)).toMatchSnapshot('warnings'); + expect(getErrors(newStats)).toMatchSnapshot("errors"); + expect(getWarnings(newStats)).toMatchSnapshot("warnings"); }); it('should work with "filesystem" value for the "cache.type" option and with the "algorithm" option', async () => { const compiler = getCompiler( - './entry.js', + "./entry.js", {}, { cache: { - type: 'filesystem', + type: "filesystem", cacheDirectory: fileSystemCacheDirectory, }, } @@ -512,9 +512,9 @@ if (getCompiler.isWebpack4()) { let getCounter = 0; compiler.cache.hooks.get.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { getCounter += 1; } } @@ -523,9 +523,9 @@ if (getCompiler.isWebpack4()) { let storeCounter = 0; compiler.cache.hooks.store.tap( - { name: 'TestCache', stage: -100 }, + { name: "TestCache", stage: -100 }, (identifier) => { - if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + if (identifier.indexOf("CompressionWebpackPlugin") !== -1) { storeCounter += 1; } } @@ -537,9 +537,9 @@ if (getCompiler.isWebpack4()) { expect(getCounter).toBe(4); // Store cached assets expect(storeCounter).toBe(4); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); getCounter = 0; storeCounter = 0; @@ -551,10 +551,10 @@ if (getCompiler.isWebpack4()) { // No need to store, we got cached assets expect(storeCounter).toBe(0); expect(getAssetsNameAndSize(newStats, compiler)).toMatchSnapshot( - 'assets' + "assets" ); - expect(getErrors(newStats)).toMatchSnapshot('errors'); - expect(getWarnings(newStats)).toMatchSnapshot('warnings'); + expect(getErrors(newStats)).toMatchSnapshot("errors"); + expect(getWarnings(newStats)).toMatchSnapshot("warnings"); }); }); } diff --git a/test/cjs.test.js b/test/cjs.test.js index 8aba6ba..dc8321a 100644 --- a/test/cjs.test.js +++ b/test/cjs.test.js @@ -1,8 +1,8 @@ -import src from '../src'; -import cjs from '../src/cjs'; +import src from "../src"; +import cjs from "../src/cjs"; -describe('cjs', () => { - it('should exported', () => { +describe("cjs", () => { + it("should exported", () => { expect(cjs).toEqual(src); }); }); diff --git a/test/compressionOptions-option.test.js b/test/compressionOptions-option.test.js index db07f80..f255248 100644 --- a/test/compressionOptions-option.test.js +++ b/test/compressionOptions-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,30 +7,30 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"compressionOptions" option', () => { let compiler; beforeEach(() => { - compiler = getCompiler('./entry.js'); + compiler = getCompiler("./entry.js"); return removeCache(); }); - it('matches snapshot without values', async () => { + it("matches snapshot without values", async () => { new CompressionPlugin({ minRatio: 1, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for custom options ({Object})', async () => { + it("matches snapshot for custom options ({Object})", async () => { new CompressionPlugin({ compressionOptions: { level: 9, @@ -40,56 +40,56 @@ describe('"compressionOptions" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('set default compression level to maximum for gzip', async () => { + it("set default compression level to maximum for gzip", async () => { new CompressionPlugin({ - algorithm: 'gzip', + algorithm: "gzip", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('set default compression level to maximum for deflate', async () => { + it("set default compression level to maximum for deflate", async () => { new CompressionPlugin({ - algorithm: 'deflate', + algorithm: "deflate", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('set default compression level to maximum for deflateRaw', async () => { + it("set default compression level to maximum for deflateRaw", async () => { new CompressionPlugin({ - algorithm: 'deflateRaw', + algorithm: "deflateRaw", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('set default compression level to maximum for brotli', async () => { + it("set default compression level to maximum for brotli", async () => { new CompressionPlugin({ - algorithm: 'brotliCompress', + algorithm: "brotliCompress", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/deleteOriginalAssets.test.js b/test/deleteOriginalAssets.test.js index 801fa11..6ce6a16 100644 --- a/test/deleteOriginalAssets.test.js +++ b/test/deleteOriginalAssets.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,30 +7,30 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"deleteOriginalAssets" option', () => { let compiler; beforeEach(() => { - compiler = getCompiler('./entry.js'); + compiler = getCompiler("./entry.js"); return removeCache(); }); - it('should work and keep original assets by default', async () => { - compiler = getCompiler('./entry.js'); + it("should work and keep original assets by default", async () => { + compiler = getCompiler("./entry.js"); new CompressionPlugin().apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and keep original assets', async () => { + it("should work and keep original assets", async () => { new CompressionPlugin({ minRatio: 1, deleteOriginalAssets: false, @@ -38,12 +38,12 @@ describe('"deleteOriginalAssets" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and delete original assets', async () => { + it("should work and delete original assets", async () => { new CompressionPlugin({ minRatio: 1, deleteOriginalAssets: true, @@ -51,59 +51,59 @@ describe('"deleteOriginalAssets" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and report errors on duplicate assets', async () => { - compiler = getCompiler('./entry.js'); + it("should work and report errors on duplicate assets", async () => { + compiler = getCompiler("./entry.js"); new CompressionPlugin({ - filename: '[path][base]', + filename: "[path][base]", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work and do not report errors on duplicate assets when original assets were removed', async () => { - compiler = getCompiler('./entry.js'); + it("should work and do not report errors on duplicate assets when original assets were removed", async () => { + compiler = getCompiler("./entry.js"); new CompressionPlugin({ - filename: '[path][base]', + filename: "[path][base]", deleteOriginalAssets: true, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should delete original assets and keep source maps with option "keep-source-map"', async () => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { - devtool: 'source-map', + devtool: "source-map", } ); new CompressionPlugin({ - filename: '[path][base]', + filename: "[path][base]", exclude: /\.map$/, - deleteOriginalAssets: 'keep-source-map', + deleteOriginalAssets: "keep-source-map", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/exclude-option.test.js b/test/exclude-option.test.js index 87c30ad..5213105 100644 --- a/test/exclude-option.test.js +++ b/test/exclude-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,20 +7,20 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"exclude" option', () => { let compiler; beforeEach(() => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); @@ -28,7 +28,7 @@ describe('"exclude" option', () => { return removeCache(); }); - it('matches snapshot for a single `exclude` value ({RegExp})', async () => { + it("matches snapshot for a single `exclude` value ({RegExp})", async () => { new CompressionPlugin({ exclude: /\.svg(\?.*)?$/i, minRatio: 1, @@ -36,12 +36,12 @@ describe('"exclude" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for multiple `exclude` values ({Array})', async () => { + it("matches snapshot for multiple `exclude` values ({Array})", async () => { new CompressionPlugin({ exclude: [/\.svg(\?.*)?$/i, /\.png(\?.*)?$/i], minRatio: 1, @@ -49,8 +49,8 @@ describe('"exclude" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/filename-option.test.js b/test/filename-option.test.js index 3a5898a..08c037e 100644 --- a/test/filename-option.test.js +++ b/test/filename-option.test.js @@ -1,6 +1,6 @@ -import path from 'path'; +import path from "path"; -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -9,7 +9,7 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"filename" option', () => { let compiler; @@ -18,15 +18,15 @@ describe('"filename" option', () => { return removeCache(); }); - it('show work', async () => { + it("show work", async () => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - path: path.resolve(__dirname, './outputs'), - filename: 'assets/scripts/[name].js?var=[hash]#hash', - chunkFilename: 'assets/scripts/[id].[name].js?ver=[hash]#hash', + path: path.resolve(__dirname, "./outputs"), + filename: "assets/scripts/[name].js?var=[hash]#hash", + chunkFilename: "assets/scripts/[id].[name].js?ver=[hash]#hash", }, } ); @@ -37,70 +37,70 @@ describe('"filename" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for `[path][base].super-compressed.gz[query][fragment]` value ({String})', async () => { + it("matches snapshot for `[path][base].super-compressed.gz[query][fragment]` value ({String})", async () => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - path: path.resolve(__dirname, './outputs'), - filename: 'assets/js/[name].js?var=[hash]#hash', - chunkFilename: 'assets/js/[id].[name].js?ver=[hash]#hash', + path: path.resolve(__dirname, "./outputs"), + filename: "assets/js/[name].js?var=[hash]#hash", + chunkFilename: "assets/js/[id].[name].js?ver=[hash]#hash", }, } ); new CompressionPlugin({ minRatio: 1, - filename: '[path][base].super-compressed.gz[query][fragment]', + filename: "[path][base].super-compressed.gz[query][fragment]", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for `[name][ext].super-compressed.gz[query]` value ({String})', async () => { + it("matches snapshot for `[name][ext].super-compressed.gz[query]` value ({String})", async () => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); new CompressionPlugin({ minRatio: 1, - filename: '[name].super-compressed[ext].gz[query]', + filename: "[name].super-compressed[ext].gz[query]", }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for custom function ({Function})', async () => { + it("matches snapshot for custom function ({Function})", async () => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { - path: path.resolve(__dirname, './outputs'), - filename: '[name].js?var=[hash]#hash', - chunkFilename: '[id].[name].js?ver=[hash]#hash', + path: path.resolve(__dirname, "./outputs"), + filename: "[name].js?var=[hash]#hash", + chunkFilename: "[id].[name].js?ver=[hash]#hash", }, } ); @@ -114,8 +114,8 @@ describe('"filename" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/helpers/CopyPluginWithAssetInfo.js b/test/helpers/CopyPluginWithAssetInfo.js index 73b8b90..7a4f84e 100644 --- a/test/helpers/CopyPluginWithAssetInfo.js +++ b/test/helpers/CopyPluginWithAssetInfo.js @@ -1,4 +1,4 @@ -import { RawSource } from 'webpack-sources'; +import { RawSource } from "webpack-sources"; export default class CopyPluginWithAssetInfo { apply(compiler) { @@ -7,7 +7,7 @@ export default class CopyPluginWithAssetInfo { compiler.hooks.thisCompilation.tap(plugin, (compilation) => { compilation.hooks.additionalAssets.tap(plugin, () => { // eslint-disable-next-line no-param-reassign - compilation.emitAsset('copied.js', new RawSource('Text'.repeat(100)), { + compilation.emitAsset("copied.js", new RawSource("Text".repeat(100)), { copied: true, }); }); diff --git a/test/helpers/ModifyExistingAsset.js b/test/helpers/ModifyExistingAsset.js index 702fb18..d17339c 100644 --- a/test/helpers/ModifyExistingAsset.js +++ b/test/helpers/ModifyExistingAsset.js @@ -1,9 +1,9 @@ -import webpack from 'webpack'; +import webpack from "webpack"; // webpack 5 exposes the sources property to ensure the right version of webpack-sources is used const { ConcatSource } = // eslint-disable-next-line global-require - webpack.sources || require('webpack-sources'); + webpack.sources || require("webpack-sources"); export default class ExistingCommentsFile { constructor(options = {}) { @@ -18,7 +18,7 @@ export default class ExistingCommentsFile { // eslint-disable-next-line no-param-reassign compilation.assets[this.options.name] = new ConcatSource( `function changed() {} ${ - this.options.comment ? '/*! CHANGED */' : '' + this.options.comment ? "/*! CHANGED */" : "" }`, compilation.assets[this.options.name] ); diff --git a/test/helpers/execute.js b/test/helpers/execute.js index 866001a..7e1a94e 100644 --- a/test/helpers/execute.js +++ b/test/helpers/execute.js @@ -1,14 +1,14 @@ -import Module from 'module'; -import path from 'path'; +import Module from "module"; +import path from "path"; const parentModule = module; export default (code) => { - const resource = 'test.js'; + const resource = "test.js"; const module = new Module(resource, parentModule); // eslint-disable-next-line no-underscore-dangle module.paths = Module._nodeModulePaths( - path.resolve(__dirname, '../fixtures') + path.resolve(__dirname, "../fixtures") ); module.filename = resource; diff --git a/test/helpers/getAssetsNameAndSize.js b/test/helpers/getAssetsNameAndSize.js index f3089f9..271bfb5 100644 --- a/test/helpers/getAssetsNameAndSize.js +++ b/test/helpers/getAssetsNameAndSize.js @@ -1,6 +1,6 @@ -import zlib from 'zlib'; +import zlib from "zlib"; -import { readAsset } from './index'; +import { readAsset } from "./index"; export default (stats, compiler) => { const { assets, assetsInfo } = stats.compilation; diff --git a/test/helpers/getCacheDirectory.js b/test/helpers/getCacheDirectory.js index b8394fa..4f1b59b 100644 --- a/test/helpers/getCacheDirectory.js +++ b/test/helpers/getCacheDirectory.js @@ -1,9 +1,9 @@ -import os from 'os'; +import os from "os"; -import findCacheDir from 'find-cache-dir'; +import findCacheDir from "find-cache-dir"; function getCacheDirectory() { - return findCacheDir({ name: 'compression-webpack-plugin' }) || os.tmpdir(); + return findCacheDir({ name: "compression-webpack-plugin" }) || os.tmpdir(); } export default getCacheDirectory; diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index c9696aa..60dab92 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -1,18 +1,18 @@ -import path from 'path'; +import path from "path"; -import webpack from 'webpack'; -import { createFsFromVolume, Volume } from 'memfs'; +import webpack from "webpack"; +import { createFsFromVolume, Volume } from "memfs"; export default function getCompiler(fixture, loaderOptions = {}, config = {}) { const fullConfig = { - mode: 'development', + mode: "development", devtool: config.devtool || false, - context: path.resolve(__dirname, '../fixtures'), - entry: path.resolve(__dirname, '../fixtures', fixture), + context: path.resolve(__dirname, "../fixtures"), + entry: path.resolve(__dirname, "../fixtures", fixture), output: { - path: path.resolve(__dirname, '../outputs'), - filename: '[name].[chunkhash].js', - chunkFilename: '[id].[name].[chunkhash].js', + path: path.resolve(__dirname, "../outputs"), + filename: "[name].[chunkhash].js", + chunkFilename: "[id].[name].[chunkhash].js", }, module: { rules: [ @@ -20,7 +20,7 @@ export default function getCompiler(fixture, loaderOptions = {}, config = {}) { test: /\.(png|jpg|gif|svg|txt)$/i, rules: [ { - loader: 'file-loader', + loader: "file-loader", options: loaderOptions || {}, }, ], @@ -44,4 +44,4 @@ export default function getCompiler(fixture, loaderOptions = {}, config = {}) { return compiler; } -getCompiler.isWebpack4 = () => webpack.version[0] === '4'; +getCompiler.isWebpack4 = () => webpack.version[0] === "4"; diff --git a/test/helpers/getErrors.js b/test/helpers/getErrors.js index 085bae5..a2f052f 100644 --- a/test/helpers/getErrors.js +++ b/test/helpers/getErrors.js @@ -1,4 +1,4 @@ -import normalizeErrors from './normalizeErrors'; +import normalizeErrors from "./normalizeErrors"; export default (stats) => { return normalizeErrors(stats.compilation.errors).sort(); diff --git a/test/helpers/getWarnings.js b/test/helpers/getWarnings.js index 9e09c82..5f17349 100644 --- a/test/helpers/getWarnings.js +++ b/test/helpers/getWarnings.js @@ -1,4 +1,4 @@ -import normalizeErrors from './normalizeErrors'; +import normalizeErrors from "./normalizeErrors"; export default (stats) => { return normalizeErrors(stats.compilation.warnings).sort(); diff --git a/test/helpers/index.js b/test/helpers/index.js index 5ee1dff..643f334 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -1,15 +1,15 @@ -import compile from './compile'; -import CopyPluginWithAssetInfo from './CopyPluginWithAssetInfo'; -import execute from './execute'; -import getAssetsNameAndSize from './getAssetsNameAndSize'; -import getCompiler from './getCompiler'; -import getErrors from './getErrors'; -import getWarnings from './getWarnings'; -import ModifyExistingAsset from './ModifyExistingAsset'; -import normalizeErrors from './normalizeErrors'; -import readAsset from './readAsset'; -import readsAssets from './readAssets'; -import removeCache from './removeCache'; +import compile from "./compile"; +import CopyPluginWithAssetInfo from "./CopyPluginWithAssetInfo"; +import execute from "./execute"; +import getAssetsNameAndSize from "./getAssetsNameAndSize"; +import getCompiler from "./getCompiler"; +import getErrors from "./getErrors"; +import getWarnings from "./getWarnings"; +import ModifyExistingAsset from "./ModifyExistingAsset"; +import normalizeErrors from "./normalizeErrors"; +import readAsset from "./readAsset"; +import readsAssets from "./readAssets"; +import removeCache from "./removeCache"; export { compile, diff --git a/test/helpers/loader-with-child-compilation.js b/test/helpers/loader-with-child-compilation.js index 77539cc..ac44834 100644 --- a/test/helpers/loader-with-child-compilation.js +++ b/test/helpers/loader-with-child-compilation.js @@ -1,4 +1,4 @@ -import CopyPluginWithAssetInfo from './CopyPluginWithAssetInfo'; +import CopyPluginWithAssetInfo from "./CopyPluginWithAssetInfo"; export default function loader() { const callback = this.async(); @@ -15,6 +15,6 @@ export default function loader() { return callback(error); } - return callback(null, 'export default 1'); + return callback(null, "export default 1"); }); } diff --git a/test/helpers/normalizeErrors.js b/test/helpers/normalizeErrors.js index c6d0f16..f1c380e 100644 --- a/test/helpers/normalizeErrors.js +++ b/test/helpers/normalizeErrors.js @@ -1,19 +1,19 @@ function removeCWD(str) { - const isWin = process.platform === 'win32'; + const isWin = process.platform === "win32"; let cwd = process.cwd(); if (isWin) { // eslint-disable-next-line no-param-reassign - str = str.replace(/\\/g, '/'); + str = str.replace(/\\/g, "/"); // eslint-disable-next-line no-param-reassign - cwd = cwd.replace(/\\/g, '/'); + cwd = cwd.replace(/\\/g, "/"); } - return str.replace(new RegExp(cwd, 'g'), ''); + return str.replace(new RegExp(cwd, "g"), ""); } export default (errors) => { return errors.map((error) => - removeCWD(error.toString().split('\n').slice(0, 2).join('\n')) + removeCWD(error.toString().split("\n").slice(0, 2).join("\n")) ); }; diff --git a/test/helpers/readAsset.js b/test/helpers/readAsset.js index 6647f5d..259df5b 100644 --- a/test/helpers/readAsset.js +++ b/test/helpers/readAsset.js @@ -1,13 +1,13 @@ -import path from 'path'; +import path from "path"; export default (asset, compiler, stats) => { const usedFs = compiler.outputFileSystem; const outputPath = stats.compilation.outputOptions.path; - let data = ''; + let data = ""; let targetFile = asset; - const queryStringIdx = targetFile.indexOf('?'); + const queryStringIdx = targetFile.indexOf("?"); if (queryStringIdx >= 0) { targetFile = targetFile.substr(0, queryStringIdx); diff --git a/test/helpers/readAssets.js b/test/helpers/readAssets.js index a2fb783..15b9dca 100644 --- a/test/helpers/readAssets.js +++ b/test/helpers/readAssets.js @@ -1,4 +1,4 @@ -import readAsset from './readAsset'; +import readAsset from "./readAsset"; export default function readAssets(compiler, stats) { const assets = {}; diff --git a/test/helpers/removeCache.js b/test/helpers/removeCache.js index 05c2f81..001d04d 100644 --- a/test/helpers/removeCache.js +++ b/test/helpers/removeCache.js @@ -1,6 +1,6 @@ -import cacache from 'cacache'; +import cacache from "cacache"; -import getCacheDirectory from './getCacheDirectory'; +import getCacheDirectory from "./getCacheDirectory"; async function removeCache(cacheDirectory) { const cacheDir = cacheDirectory || getCacheDirectory(); diff --git a/test/helpers/snapshotResolver.js b/test/helpers/snapshotResolver.js index 742ee5b..4303e7e 100644 --- a/test/helpers/snapshotResolver.js +++ b/test/helpers/snapshotResolver.js @@ -1,28 +1,28 @@ -const path = require('path'); +const path = require("path"); -const webpack = require('webpack'); +const webpack = require("webpack"); // eslint-disable-next-line global-require const [webpackVersion] = webpack.version; const snapshotExtension = `.snap.webpack${webpackVersion}`; // eslint-disable-next-line no-console -console.log('Current webpack version:', webpackVersion); +console.log("Current webpack version:", webpackVersion); module.exports = { resolveSnapshotPath: (testPath) => path.join( path.dirname(testPath), - '__snapshots__', + "__snapshots__", `${path.basename(testPath)}${snapshotExtension}` ), resolveTestPath: (snapshotPath) => snapshotPath - .replace(`${path.sep}__snapshots__`, '') + .replace(`${path.sep}__snapshots__`, "") .slice(0, -snapshotExtension.length), testPathForConsistencyCheck: path.join( - 'consistency_check', - '__tests__', - 'example.test.js' + "consistency_check", + "__tests__", + "example.test.js" ), }; diff --git a/test/include-option.test.js b/test/include-option.test.js index a70a6bf..d0cfa52 100644 --- a/test/include-option.test.js +++ b/test/include-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,20 +7,20 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"include" option', () => { let compiler; beforeEach(() => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); @@ -28,7 +28,7 @@ describe('"include" option', () => { return removeCache(); }); - it('matches snapshot for a single `include` value ({RegExp})', async () => { + it("matches snapshot for a single `include` value ({RegExp})", async () => { new CompressionPlugin({ include: /\.js(\?.*)?$/i, minRatio: 1, @@ -36,12 +36,12 @@ describe('"include" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for multiple `include` values ({Array})', async () => { + it("matches snapshot for multiple `include` values ({Array})", async () => { new CompressionPlugin({ include: [/\.js(\?.*)?$/i, /\.svg(\?.*)?$/i], minRatio: 1, @@ -49,8 +49,8 @@ describe('"include" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/minRatio-option.test.js b/test/minRatio-option.test.js index 19456f4..4c812c4 100644 --- a/test/minRatio-option.test.js +++ b/test/minRatio-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,38 +7,38 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"minRatio" option', () => { let compiler; beforeEach(() => { - compiler = getCompiler('./entry.js'); + compiler = getCompiler("./entry.js"); return removeCache(); }); - it('matches snapshot for `0` value ({Number})', async () => { + it("matches snapshot for `0` value ({Number})", async () => { new CompressionPlugin({ minRatio: 0, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for `1` value ({Number})', async () => { + it("matches snapshot for `1` value ({Number})", async () => { new CompressionPlugin({ minRatio: 1, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/test-option.test.js b/test/test-option.test.js index 0ebc581..4107466 100644 --- a/test/test-option.test.js +++ b/test/test-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,20 +7,20 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"test" option', () => { let compiler; beforeEach(() => { compiler = getCompiler( - './entry.js', + "./entry.js", {}, { output: { path: `${__dirname}/dist`, - filename: '[name].js?var=[hash]', - chunkFilename: '[id].[name].js?ver=[hash]', + filename: "[name].js?var=[hash]", + chunkFilename: "[id].[name].js?ver=[hash]", }, } ); @@ -28,19 +28,19 @@ describe('"test" option', () => { return removeCache(); }); - it('matches snapshot with empty `test` value', async () => { + it("matches snapshot with empty `test` value", async () => { new CompressionPlugin({ minRatio: 1, }).apply(compiler); const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for a single `test` value ({RegExp})', async () => { + it("matches snapshot for a single `test` value ({RegExp})", async () => { new CompressionPlugin({ test: /\.(png|jpg|gif)$/i, minRatio: 1, @@ -48,12 +48,12 @@ describe('"test" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for multiple `test` values ({Array})', async () => { + it("matches snapshot for multiple `test` values ({Array})", async () => { new CompressionPlugin({ test: [/\.(png|jpg|gif)$/i, /\.svg/i], minRatio: 1, @@ -61,12 +61,12 @@ describe('"test" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work when no asset to compress ', async () => { + it("should work when no asset to compress ", async () => { new CompressionPlugin({ test: /\.(unknown)$/i, minRatio: 1, @@ -74,8 +74,8 @@ describe('"test" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/threshold-option.test.js b/test/threshold-option.test.js index 8489d96..56a83a6 100644 --- a/test/threshold-option.test.js +++ b/test/threshold-option.test.js @@ -1,4 +1,4 @@ -import CompressionPlugin from '../src/index'; +import CompressionPlugin from "../src/index"; import { compile, @@ -7,18 +7,18 @@ import { getErrors, getWarnings, removeCache, -} from './helpers/index'; +} from "./helpers/index"; describe('"threshold" option', () => { let compiler; beforeEach(() => { - compiler = getCompiler('./entry.js'); + compiler = getCompiler("./entry.js"); return removeCache(); }); - it('matches snapshot for `0` value ({Number})', async () => { + it("matches snapshot for `0` value ({Number})", async () => { new CompressionPlugin({ minRatio: 1, threshold: 0, @@ -26,12 +26,12 @@ describe('"threshold" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('matches snapshot for `8192` value ({Number})', async () => { + it("matches snapshot for `8192` value ({Number})", async () => { new CompressionPlugin({ minRatio: 1, threshold: 8192, @@ -39,13 +39,13 @@ describe('"threshold" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should compress all assets including assets with "0" bytes original size', async () => { - compiler = getCompiler('./empty.js'); + compiler = getCompiler("./empty.js"); new CompressionPlugin({ minRatio: Infinity, @@ -54,13 +54,13 @@ describe('"threshold" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should compress all assets excluding assets with "0" bytes original size', async () => { - compiler = getCompiler('./empty.js'); + compiler = getCompiler("./empty.js"); new CompressionPlugin({ minRatio: Number.MAX_SAFE_INTEGER, @@ -69,8 +69,8 @@ describe('"threshold" option', () => { const stats = await compile(compiler); - expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 9edbe4b..64f1303 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -1,8 +1,8 @@ -import CompressionPlugin from '../src'; +import CompressionPlugin from "../src"; -import { removeCache } from './helpers'; +import { removeCache } from "./helpers"; -describe('validate options', () => { +describe("validate options", () => { beforeEach(() => { return removeCache(); }); @@ -11,74 +11,74 @@ describe('validate options', () => { test: { success: [ /foo/, - 'foo', + "foo", [/foo/], [/foo/, /bar/], - ['foo', 'bar'], - [/foo/, 'bar'], + ["foo", "bar"], + [/foo/, "bar"], ], - failure: [true, [true], [/foo/, 'foo', true]], + failure: [true, [true], [/foo/, "foo", true]], }, include: { success: [ /foo/, - 'foo', + "foo", [/foo/], [/foo/, /bar/], - ['foo', 'bar'], - [/foo/, 'bar'], + ["foo", "bar"], + [/foo/, "bar"], ], - failure: [true, [true], [/foo/, 'foo', true]], + failure: [true, [true], [/foo/, "foo", true]], }, exclude: { success: [ /foo/, - 'foo', + "foo", [/foo/], [/foo/, /bar/], - ['foo', 'bar'], - [/foo/, 'bar'], + ["foo", "bar"], + [/foo/, "bar"], ], - failure: [true, [true], [/foo/, 'foo', true]], + failure: [true, [true], [/foo/, "foo", true]], }, filename: { - success: ['[path].gz[query]', () => {}], + success: ["[path].gz[query]", () => {}], failure: [true], }, algorithm: { - success: ['gzip', () => {}], + success: ["gzip", () => {}], failure: [true], }, compressionOptions: { success: [{ level: 1 }, { unknown: 1 }], - failure: ['1024'], + failure: ["1024"], }, threshold: { success: [1024], - failure: ['1024'], + failure: ["1024"], }, minRatio: { success: [0.8], - failure: ['0.8'], + failure: ["0.8"], }, cache: { - success: [true, '/path/to/cache'], + success: [true, "/path/to/cache"], failure: [() => {}], }, deleteOriginalAssets: { - success: [true, false, 'keep-source-map'], - failure: ['true', 'unknown'], + success: [true, false, "keep-source-map"], + failure: ["true", "unknown"], }, unknown: { success: [], - failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + failure: [1, true, false, "test", /test/, [], {}, { foo: "bar" }], }, }; function stringifyValue(value) { if ( Array.isArray(value) || - (value && typeof value === 'object' && value.constructor === Object) + (value && typeof value === "object" && value.constructor === Object) ) { return JSON.stringify(value); } @@ -88,7 +88,7 @@ describe('validate options', () => { async function createTestCase(key, value, type) { it(`should ${ - type === 'success' ? 'successfully validate' : 'throw an error on' + type === "success" ? "successfully validate" : "throw an error on" } the "${key}" option with "${stringifyValue(value)}" value`, async () => { let error; @@ -96,15 +96,15 @@ describe('validate options', () => { // eslint-disable-next-line no-new new CompressionPlugin({ [key]: value }); } catch (errorFromPlugin) { - if (errorFromPlugin.name !== 'ValidationError') { + if (errorFromPlugin.name !== "ValidationError") { throw errorFromPlugin; } error = errorFromPlugin; } finally { - if (type === 'success') { + if (type === "success") { expect(error).toBeUndefined(); - } else if (type === 'failure') { + } else if (type === "failure") { expect(() => { throw error; }).toThrowErrorMatchingSnapshot();