From ac9d1e0b6e4872c3273999092edbec65ea618b6e Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Sat, 1 Aug 2020 16:55:34 +0300 Subject: [PATCH] refactor: rename plugin to css-minimizer-webpack-plugin --- README.md | 80 ++++++++-------- src/Webpack4Cache.js | 4 +- src/Webpack5Cache.js | 2 +- src/index.js | 54 +++++------ src/minify.js | 12 ++- src/options.json | 8 +- ...gin.test.js => CssMinimizerPlugin.test.js} | 68 +++++++------- .../CssMinimizerPlugin.test.js.snap.webpack4 | 82 ++++++++++++++++ .../CssMinimizerPlugin.test.js.snap.webpack5 | 82 ++++++++++++++++ .../CssnanoPlugin.test.js.snap.webpack4 | 56 +++++------ ...imizerOptions-option.test.js.snap.webpack4 | 22 +++++ ...imizerOptions-option.test.js.snap.webpack5 | 22 +++++ ...ssnanoOptions-option.test.js.snap.webpack4 | 14 +-- .../sourceMap-option.test.js.snap.webpack4 | 4 +- .../sourceMap-option.test.js.snap.webpack5 | 4 +- .../validate-options.test.js.snap.webpack4 | 34 +++---- .../validate-options.test.js.snap.webpack5 | 34 +++---- ...arningsFilter-option.test.js.snap.webpack4 | 4 +- ...arningsFilter-option.test.js.snap.webpack5 | 4 +- .../worker.test.js.snap.webpack4 | 2 +- .../worker.test.js.snap.webpack5 | 2 +- test/cache-option.test.js | 16 ++-- ....js => cssMinimizerOptions-option.test.js} | 40 ++++---- test/exclude-option.test.js | 10 +- .../discardComments.css | 0 .../discardEmpty.css | 0 .../mergeRules.css | 0 test/helpers/getCacheDirectory.js | 2 +- test/include-option.test.js | 10 +- test/parallel-option.test.js | 18 ++-- test/sourceMap-option.test.js | 16 ++-- test/test-option.test.js | 8 +- test/validate-options.test.js | 94 +++++++++---------- test/warningsFilter-option.test.js | 4 +- test/worker.test.js | 8 +- 35 files changed, 519 insertions(+), 301 deletions(-) rename test/{CssnanoPlugin.test.js => CssMinimizerPlugin.test.js} (81%) create mode 100644 test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 create mode 100644 test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 create mode 100644 test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack4 create mode 100644 test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack5 rename test/{cssnanoOptions-option.test.js => cssMinimizerOptions-option.test.js} (81%) rename test/fixtures/{cssnanooptions => minimizerOptions}/discardComments.css (100%) rename test/fixtures/{cssnanooptions => minimizerOptions}/discardEmpty.css (100%) rename test/fixtures/{cssnanooptions => minimizerOptions}/mergeRules.css (100%) diff --git a/README.md b/README.md index 6ac5a48..3138088 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [![chat][chat]][chat-url] [![size][size]][size-url] -# cssnano-webpack-plugin +# css-minimizer-webpack-plugin This plugin uses [cssnano](https://cssnano.co) to optimize and minify your CSS. @@ -24,10 +24,10 @@ Works with Webpack 4+. ## Getting Started -To begin, you'll need to install `cssnano-webpack-plugin`: +To begin, you'll need to install `css-minimizer-webpack-plugin`: ```console -$ npm install cssnano-webpack-plugin --save-dev +$ npm install css-minimizer-webpack-plugin --save-dev ``` Then add the plugin to your `webpack` configuration. For example: @@ -35,7 +35,7 @@ Then add the plugin to your `webpack` configuration. For example: **webpack.config.js** ```js -const CssnanoPlugin = require('cssnano-webpack-plugin'); +const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); module.exports = { module: { @@ -48,7 +48,7 @@ module.exports = { }, optimization: { minimize: true, - minimizer: [new CssnanoPlugin()], + minimizer: [new CssMinimizerPlugin()], }, }; ``` @@ -69,7 +69,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ test: /\.foo\.css$/i, }), ], @@ -91,7 +91,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ include: /\/includes/, }), ], @@ -113,7 +113,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ exclude: /\/excludes/, }), ], @@ -129,7 +129,7 @@ Type: `Boolean|String` Default: `true` Enable file caching. -Default path to cache directory: `node_modules/.cache/cssnano-webpack-plugin`. +Default path to cache directory: `node_modules/.cache/css-minimizer-webpack-plugin`. > ℹ️ If you use your own `minify` function please read the `minify` section for cache invalidation correctly. @@ -144,7 +144,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ cache: true, }), ], @@ -163,7 +163,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ cache: 'path/to/cache', }), ], @@ -184,9 +184,9 @@ Default cache keys: ```js ({ - cssnano: require('cssnano/package.json').version, // cssnano version - 'cssnano-webpack-plugin': require('../package.json').version, // plugin version - 'cssnano-webpack-plugin-options': this.options, // plugin options + cssMinimizer: require('cssnano/package.json').version, // cssnano version + 'css-minimizer-webpack-plugin': require('../package.json').version, // plugin version + 'css-minimizer-webpack-plugin-options': this.options, // plugin options path: compiler.outputPath ? `${compiler.outputPath}/${file}` : file, // asset path hash: crypto.createHash('md4').update(input).digest('hex'), // source file hash }); @@ -199,7 +199,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ cache: true, cacheKeys: (defaultCacheKeys, file) => { defaultCacheKeys.myCacheKey = 'myCacheKeyValue'; @@ -233,7 +233,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ parallel: true, }), ], @@ -252,7 +252,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ parallel: 4, }), ], @@ -289,7 +289,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }), ], @@ -315,10 +315,10 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ minify: (data) => { const postcss = require('postcss'); - const { input, postcssOptions, cssnanoOptions } = data; + const { input, postcssOptions, minimizerOptions } = data; const plugin = postcss.plugin( 'custom-plugin', @@ -344,7 +344,7 @@ module.exports = { }; ``` -### `cssnanoOptions` +### `minimizerOptions` Type: `Object` Default: `{ preset: 'default' }` @@ -356,8 +356,8 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: [ 'default', { @@ -376,7 +376,7 @@ module.exports = { Type: `Function<(warning, file, source) -> Boolean>` Default: `() => true` -Allow to filter [cssnano](https://github.com/cssnano/cssnano) warnings. +Allow to filter css-minimizer warnings (By default [cssnano](https://github.com/cssnano/cssnano)). Return `true` to keep the warning, a falsy value (`false`/`null`/`undefined`) otherwise. > ⚠️ The `source` argument will contain `undefined` if you don't use source maps. @@ -388,7 +388,7 @@ module.exports = { optimization: { minimize: true, minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ warningsFilter: (warning, file, source) => { if (/Dropping unreachable code/i.test(warning)) { return true; @@ -417,7 +417,7 @@ module.exports = { Don't forget to enable `sourceMap` options for all loaders. ```js -const CssnanoPlugin = require('cssnano-webpack-plugin'); +const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); module.exports = { module: { @@ -434,7 +434,7 @@ module.exports = { }, optimization: { minimizer: [ - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }), ], @@ -450,8 +450,8 @@ Remove all comments (including comments starting with `/*!`). module.exports = { optimization: { minimizer: [ - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: [ 'default', { @@ -475,17 +475,17 @@ Please take a moment to read our contributing guidelines if you haven't yet done [MIT](./LICENSE) -[npm]: https://img.shields.io/npm/v/cssnano-webpack-plugin.svg -[npm-url]: https://npmjs.com/package/cssnano-webpack-plugin -[node]: https://img.shields.io/node/v/cssnano-webpack-plugin.svg +[npm]: https://img.shields.io/npm/v/css-minimizer-webpack-plugin.svg +[npm-url]: https://npmjs.com/package/css-minimizer-webpack-plugin +[node]: https://img.shields.io/node/v/css-minimizer-webpack-plugin.svg [node-url]: https://nodejs.org -[deps]: https://david-dm.org/webpack-contrib/cssnano-webpack-plugin.svg -[deps-url]: https://david-dm.org/webpack-contrib/cssnano-webpack-plugin -[tests]: https://github.com/webpack-contrib/cssnano-webpack-plugin/workflows/cssnano-webpack-plugin/badge.svg -[tests-url]: https://github.com/webpack-contrib/cssnano-webpack-plugin/actions -[cover]: https://codecov.io/gh/webpack-contrib/cssnano-webpack-plugin/branch/master/graph/badge.svg -[cover-url]: https://codecov.io/gh/webpack-contrib/cssnano-webpack-plugin +[deps]: https://david-dm.org/webpack-contrib/css-minimizer-webpack-plugin.svg +[deps-url]: https://david-dm.org/webpack-contrib/css-minimizer-webpack-plugin +[tests]: https://github.com/webpack-contrib/css-minimizer-webpack-plugin/workflows/css-minimizer-webpack-plugin/badge.svg +[tests-url]: https://github.com/webpack-contrib/css-minimizer-webpack-plugin/actions +[cover]: https://codecov.io/gh/webpack-contrib/css-minimizer-webpack-plugin/branch/master/graph/badge.svg +[cover-url]: https://codecov.io/gh/webpack-contrib/css-minimizer-webpack-plugin [chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg [chat-url]: https://gitter.im/webpack/webpack -[size]: https://packagephobia.now.sh/badge?p=cssnano-webpack-plugin -[size-url]: https://packagephobia.now.sh/result?p=cssnano-webpack-plugin +[size]: https://packagephobia.now.sh/badge?p=css-minimizer-webpack-plugin +[size-url]: https://packagephobia.now.sh/result?p=css-minimizer-webpack-plugin diff --git a/src/Webpack4Cache.js b/src/Webpack4Cache.js index 8313c9e..3384f80 100644 --- a/src/Webpack4Cache.js +++ b/src/Webpack4Cache.js @@ -13,7 +13,9 @@ export default class Webpack4Cache { } static getCacheDirectory() { - return findCacheDir({ name: 'cssnano-webpack-plugin' }) || os.tmpdir(); + return ( + findCacheDir({ name: 'css-minimizer-webpack-plugin' }) || os.tmpdir() + ); } isEnabled() { diff --git a/src/Webpack5Cache.js b/src/Webpack5Cache.js index 941e0fd..6f49e2d 100644 --- a/src/Webpack5Cache.js +++ b/src/Webpack5Cache.js @@ -30,7 +30,7 @@ export default class Cache { const digest = hash.digest(hashDigest); const cacheKeys = digest.substr(0, hashDigestLength); - return `${this.compilation.compilerPath}/CssnanoWebpackPlugin/${cacheKeys}/${task.file}`; + return `${this.compilation.compilerPath}/CssMinimizerWebpackPlugin/${cacheKeys}/${task.file}`; } get(task) { diff --git a/src/index.js b/src/index.js index 08b6b53..972fe1f 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ import { } from 'webpack'; import validateOptions from 'schema-utils'; import serialize from 'serialize-javascript'; -import cssnanoPackageJson from 'cssnano/package.json'; +import CssMinimizerPackageJson from 'cssnano/package.json'; import pLimit from 'p-limit'; import Worker from 'jest-worker'; @@ -21,16 +21,16 @@ import { minify as minifyFn } from './minify'; const warningRegex = /\s.+:+([0-9]+):+([0-9]+)/; -class CssnanoPlugin { +class CssMinimizerPlugin { constructor(options = {}) { validateOptions(schema, options, { - name: 'Cssnano Plugin', + name: 'Css Minimizer Plugin', baseDataPath: 'options', }); const { minify, - cssnanoOptions = { + minimizerOptions = { preset: 'default', }, test = /\.css(\?.*)?$/i, @@ -53,7 +53,7 @@ class CssnanoPlugin { include, exclude, minify, - cssnanoOptions, + minimizerOptions, }; if (this.options.sourceMap === true) { @@ -84,7 +84,7 @@ class CssnanoPlugin { if (original && original.source && requestShortener) { return new Error( - `${file} from Cssnano Webpack Plugin\n${ + `${file} from Css Minimizer Webpack Plugin\n${ error.message } [${requestShortener.shorten(original.source)}:${original.line},${ original.column @@ -97,7 +97,7 @@ class CssnanoPlugin { } return new Error( - `${file} from Cssnano \n${error.message} [${file}:${error.line},${ + `${file} from Css Minimizer \n${error.message} [${file}:${error.line},${ error.column }]${ error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : '' @@ -106,10 +106,10 @@ class CssnanoPlugin { } if (error.stack) { - return new Error(`${file} from Cssnano\n${error.stack}`); + return new Error(`${file} from Css Minimizer\n${error.stack}`); } - return new Error(`${file} from Cssnano\n${error.message}`); + return new Error(`${file} from Css Minimizer\n${error.message}`); } static buildWarning( @@ -154,7 +154,7 @@ class CssnanoPlugin { return null; } - return `Cssnano Plugin: ${warningMessage} ${locationMessage}`; + return `Css Minimizer Plugin: ${warningMessage} ${locationMessage}`; } static isWebpack4() { @@ -184,7 +184,7 @@ class CssnanoPlugin { input = source; if (map) { - if (CssnanoPlugin.isSourceMap(map)) { + if (CssMinimizerPlugin.isSourceMap(map)) { inputSourceMap = map; } else { inputSourceMap = map; @@ -211,7 +211,7 @@ class CssnanoPlugin { if ( (error || (warnings && warnings.length > 0)) && inputSourceMap && - CssnanoPlugin.isSourceMap(inputSourceMap) + CssMinimizerPlugin.isSourceMap(inputSourceMap) ) { sourceMap = new SourceMapConsumer(inputSourceMap); } @@ -220,7 +220,7 @@ class CssnanoPlugin { // Error case: add errors, and go to next file if (error) { compilation.errors.push( - CssnanoPlugin.buildError( + CssMinimizerPlugin.buildError( error, file, sourceMap, @@ -253,7 +253,7 @@ class CssnanoPlugin { // Handling warnings if (warnings && warnings.length > 0) { warnings.forEach((warning) => { - const builtWarning = CssnanoPlugin.buildWarning( + const builtWarning = CssMinimizerPlugin.buildWarning( warning, file, sourceMap, @@ -273,12 +273,12 @@ class CssnanoPlugin { input, inputSourceMap, map: this.options.sourceMap, - cssnanoOptions: this.options.cssnanoOptions, + minimizerOptions: this.options.minimizerOptions, minify: this.options.minify, callback, }; - if (CssnanoPlugin.isWebpack4()) { + if (CssMinimizerPlugin.isWebpack4()) { const { outputOptions: { hashSalt, hashDigest, hashDigestLength, hashFunction }, } = compilation; @@ -294,10 +294,10 @@ class CssnanoPlugin { if (this.options.cache) { const defaultCacheKeys = { - cssnano: cssnanoPackageJson.version, + cssMinimizer: CssMinimizerPackageJson.version, // eslint-disable-next-line global-require - 'cssnano-webpack-plugin': require('../package.json').version, - 'cssnano-webpack-plugin-options': this.options, + 'css-minimizer-webpack-plugin': require('../package.json').version, + 'css-minimizer-webpack-plugin-options': this.options, nodeVersion: process.version, filename: file, contentHash: digest.substr(0, hashDigestLength), @@ -310,10 +310,10 @@ class CssnanoPlugin { task.assetSource = assetSource; task.cacheKeys = { - cssnano: cssnanoPackageJson.version, + cssMinimizer: CssMinimizerPackageJson.version, // eslint-disable-next-line global-require - 'cssnano-webpack-plugin': require('../package.json').version, - 'cssnano-webpack-plugin-options': this.options, + 'css-minimizer-webpack-plugin': require('../package.json').version, + 'css-minimizer-webpack-plugin-options': this.options, }; } @@ -322,7 +322,7 @@ class CssnanoPlugin { // eslint-disable-next-line class-methods-use-this async runTasks(assetNames, getTaskForAsset, cache) { - const availableNumberOfCores = CssnanoPlugin.getAvailableNumberOfCores( + const availableNumberOfCores = CssMinimizerPlugin.getAvailableNumberOfCores( this.options.parallel ); @@ -444,7 +444,7 @@ class CssnanoPlugin { const optimizeFn = async (compilation, chunksOrAssets) => { const assetNames = Object.keys( - CssnanoPlugin.isWebpack4() ? compilation.assets : chunksOrAssets + CssMinimizerPlugin.isWebpack4() ? compilation.assets : chunksOrAssets ).filter((file) => matchObject(file)); if (assetNames.length === 0) { @@ -457,7 +457,7 @@ class CssnanoPlugin { compilation ); - const CacheEngine = CssnanoPlugin.isWebpack4() + const CacheEngine = CssMinimizerPlugin.isWebpack4() ? // eslint-disable-next-line global-require require('./Webpack4Cache').default : // eslint-disable-next-line global-require @@ -480,7 +480,7 @@ class CssnanoPlugin { }); } - if (CssnanoPlugin.isWebpack4()) { + if (CssMinimizerPlugin.isWebpack4()) { compilation.hooks.optimizeChunkAssets.tapPromise( plugin, optimizeFn.bind(this, compilation) @@ -495,4 +495,4 @@ class CssnanoPlugin { } } -export default CssnanoPlugin; +export default CssMinimizerPlugin; diff --git a/src/minify.js b/src/minify.js index 9e3da32..79144e1 100644 --- a/src/minify.js +++ b/src/minify.js @@ -1,4 +1,4 @@ -const cssnano = require('cssnano'); +const cssMinimizer = require('cssnano'); /* * We bring to the line here, because when passing result from the worker, @@ -12,7 +12,7 @@ const minify = async (options) => { const { file, input, - cssnanoOptions, + minimizerOptions, map, inputSourceMap, minify: minifyFn, @@ -22,7 +22,7 @@ const minify = async (options) => { if (minifyFn) { const result = await minifyFn( - { input, postcssOptions, cssnanoOptions }, + { input, postcssOptions, minimizerOptions }, inputSourceMap ); @@ -38,7 +38,11 @@ const minify = async (options) => { postcssOptions.map = { prev: inputSourceMap, ...map }; } - const result = await cssnano.process(input, postcssOptions, cssnanoOptions); + const result = await cssMinimizer.process( + input, + postcssOptions, + minimizerOptions + ); return { css: result.css, diff --git a/src/options.json b/src/options.json index 7216f60..5a451bb 100644 --- a/src/options.json +++ b/src/options.json @@ -33,7 +33,7 @@ ] } }, - "title": "CssnanoWebpackPluginOptions", + "title": "CssMinimizerWebpackPluginOptions", "type": "object", "properties": { "test": { @@ -73,8 +73,8 @@ } ] }, - "cssnanoOptions": { - "description": "Options for `cssnanoOptions`.", + "minimizerOptions": { + "description": "Options for `cssMinimizerOptions`.", "additionalProperties": true, "type": "object" }, @@ -105,7 +105,7 @@ ] }, "warningsFilter": { - "description": "Allow to filter `cssnano` warnings.", + "description": "Allow to filter `css minimizer` warnings.", "instanceof": "Function" }, "minify": { diff --git a/test/CssnanoPlugin.test.js b/test/CssMinimizerPlugin.test.js similarity index 81% rename from test/CssnanoPlugin.test.js rename to test/CssMinimizerPlugin.test.js index d1f48a4..fc81c39 100644 --- a/test/CssnanoPlugin.test.js +++ b/test/CssMinimizerPlugin.test.js @@ -5,7 +5,7 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import CopyPlugin from 'copy-webpack-plugin'; import RequestShortener from 'webpack/lib/RequestShortener'; -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { getCompiler, @@ -20,7 +20,7 @@ import { jest.setTimeout(30000); -describe('CssnanoPlugin', () => { +describe('CssMinimizerPlugin', () => { const rawSourceMap = { version: 3, file: 'test.css', @@ -57,8 +57,8 @@ describe('CssnanoPlugin', () => { entry: `${__dirname}/fixtures/test/foo.css`, }, }); - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: ['default', { discardEmpty: false }], }, }).apply(compiler); @@ -97,7 +97,7 @@ describe('CssnanoPlugin', () => { }, }); - new CssnanoPlugin({ + new CssMinimizerPlugin({ parallel: true, minify: () => { // eslint-disable-next-line no-console @@ -122,24 +122,28 @@ describe('CssnanoPlugin', () => { }); it('isSourceMap method', () => { - expect(CssnanoPlugin.isSourceMap(null)).toBe(false); - expect(CssnanoPlugin.isSourceMap()).toBe(false); - expect(CssnanoPlugin.isSourceMap({})).toBe(false); - expect(CssnanoPlugin.isSourceMap([])).toBe(false); - expect(CssnanoPlugin.isSourceMap('foo')).toBe(false); - expect(CssnanoPlugin.isSourceMap({ version: 3 })).toBe(false); - expect(CssnanoPlugin.isSourceMap({ sources: '' })).toBe(false); - expect(CssnanoPlugin.isSourceMap({ mappings: [] })).toBe(false); - expect(CssnanoPlugin.isSourceMap({ version: 3, sources: '' })).toBe(false); - expect(CssnanoPlugin.isSourceMap({ version: 3, mappings: [] })).toBe(false); - expect(CssnanoPlugin.isSourceMap({ sources: '', mappings: [] })).toBe( + expect(CssMinimizerPlugin.isSourceMap(null)).toBe(false); + expect(CssMinimizerPlugin.isSourceMap()).toBe(false); + expect(CssMinimizerPlugin.isSourceMap({})).toBe(false); + expect(CssMinimizerPlugin.isSourceMap([])).toBe(false); + expect(CssMinimizerPlugin.isSourceMap('foo')).toBe(false); + expect(CssMinimizerPlugin.isSourceMap({ version: 3 })).toBe(false); + expect(CssMinimizerPlugin.isSourceMap({ sources: '' })).toBe(false); + expect(CssMinimizerPlugin.isSourceMap({ mappings: [] })).toBe(false); + expect(CssMinimizerPlugin.isSourceMap({ version: 3, sources: '' })).toBe( + false + ); + expect(CssMinimizerPlugin.isSourceMap({ version: 3, mappings: [] })).toBe( + false + ); + expect(CssMinimizerPlugin.isSourceMap({ sources: '', mappings: [] })).toBe( false ); expect( - CssnanoPlugin.isSourceMap({ version: 3, sources: '', mappings: [] }) + CssMinimizerPlugin.isSourceMap({ version: 3, sources: '', mappings: [] }) ).toBe(false); - expect(CssnanoPlugin.isSourceMap(rawSourceMap)).toBe(true); - expect(CssnanoPlugin.isSourceMap(emptyRawSourceMap)).toBe(true); + expect(CssMinimizerPlugin.isSourceMap(rawSourceMap)).toBe(true); + expect(CssMinimizerPlugin.isSourceMap(emptyRawSourceMap)).toBe(true); }); it('buildError method', () => { @@ -147,7 +151,7 @@ describe('CssnanoPlugin', () => { error.stack = null; - expect(CssnanoPlugin.buildError(error, 'test.css')).toMatchSnapshot(); + expect(CssMinimizerPlugin.buildError(error, 'test.css')).toMatchSnapshot(); const errorWithLineAndCol = new Error('Message'); @@ -156,7 +160,7 @@ describe('CssnanoPlugin', () => { errorWithLineAndCol.column = 1; expect( - CssnanoPlugin.buildError( + CssMinimizerPlugin.buildError( errorWithLineAndCol, 'test.css', new SourceMapConsumer(rawSourceMap) @@ -170,7 +174,7 @@ describe('CssnanoPlugin', () => { otherErrorWithLineAndCol.column = 1; expect( - CssnanoPlugin.buildError( + CssMinimizerPlugin.buildError( otherErrorWithLineAndCol, 'test.css', new SourceMapConsumer(rawSourceMap), @@ -183,26 +187,26 @@ describe('CssnanoPlugin', () => { errorWithStack.stack = 'Stack'; expect( - CssnanoPlugin.buildError(errorWithStack, 'test.css') + CssMinimizerPlugin.buildError(errorWithStack, 'test.css') ).toMatchSnapshot(); }); it('buildWarning method', () => { expect( - CssnanoPlugin.buildWarning('Warning test.css:1:1') + CssMinimizerPlugin.buildWarning('Warning test.css:1:1') ).toMatchSnapshot(); expect( - CssnanoPlugin.buildWarning('Warning test.css:1:1', 'test.css') + CssMinimizerPlugin.buildWarning('Warning test.css:1:1', 'test.css') ).toMatchSnapshot(); expect( - CssnanoPlugin.buildWarning( + CssMinimizerPlugin.buildWarning( 'Warning test.css:1:1', 'test.css', new SourceMapConsumer(rawSourceMap) ) ).toMatchSnapshot(); expect( - CssnanoPlugin.buildWarning( + CssMinimizerPlugin.buildWarning( 'Warning test.css:1:1', 'test.css', new SourceMapConsumer(rawSourceMap), @@ -210,7 +214,7 @@ describe('CssnanoPlugin', () => { ) ).toMatchSnapshot(); expect( - CssnanoPlugin.buildWarning( + CssMinimizerPlugin.buildWarning( 'Warning test.css:1:1', 'test.css', new SourceMapConsumer(rawSourceMap), @@ -219,7 +223,7 @@ describe('CssnanoPlugin', () => { ) ).toMatchSnapshot(); expect( - CssnanoPlugin.buildWarning( + CssMinimizerPlugin.buildWarning( 'Warning test.css:1:1', 'test.css', new SourceMapConsumer(rawSourceMap), @@ -250,7 +254,7 @@ describe('CssnanoPlugin', () => { ], }); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(getErrors(stats)).toMatchSnapshot('error'); @@ -265,7 +269,7 @@ describe('CssnanoPlugin', () => { }, }); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, minify: (data) => { // eslint-disable-next-line global-require @@ -319,7 +323,7 @@ describe('CssnanoPlugin', () => { }; const compiler = getCompiler(config); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }).apply(compiler); diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 new file mode 100644 index 0000000..1eb3526 --- /dev/null +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 @@ -0,0 +1,82 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CssMinimizerPlugin buildError method 1`] = ` +[Error: test.css from Css Minimizer +Message] +`; + +exports[`CssMinimizerPlugin buildError method 2`] = ` +[Error: test.css from Css Minimizer +Message [test.css:1,1]] +`; + +exports[`CssMinimizerPlugin buildError method 3`] = ` +[Error: test.css from Css Minimizer Webpack Plugin +Message [http://example.com/www/js/one.css:1,1][test.css:1,1]] +`; + +exports[`CssMinimizerPlugin buildError method 4`] = ` +[Error: test.css from Css Minimizer +Stack] +`; + +exports[`CssMinimizerPlugin buildWarning method 1`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 2`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 3`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 4`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; + +exports[`CssMinimizerPlugin buildWarning method 5`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; + +exports[`CssMinimizerPlugin buildWarning method 6`] = `null`; + +exports[`CssMinimizerPlugin should build error: error 1`] = ` +Array [ + "Error: error.css from Css Minimizer +/error.css:1:1: Unknown word [error.css:1,1]", +] +`; + +exports[`CssMinimizerPlugin should build error: warning 1`] = `Array []`; + +exports[`CssMinimizerPlugin should build warning: error 1`] = `Array []`; + +exports[`CssMinimizerPlugin should build warning: warning 1`] = ` +Array [ + "Css Minimizer Plugin: warning-plugin: /foo.css:2:5: Warning ", +] +`; + +exports[`CssMinimizerPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`; + +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; + +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` +"body{color:red}a{color:#00f} +/*# sourceMappingURL=entry.css.map?v=test*/" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` +Object { + "one.css": ".minify {};", + "two.css": ".minify {};", +} +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 new file mode 100644 index 0000000..1eb3526 --- /dev/null +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 @@ -0,0 +1,82 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CssMinimizerPlugin buildError method 1`] = ` +[Error: test.css from Css Minimizer +Message] +`; + +exports[`CssMinimizerPlugin buildError method 2`] = ` +[Error: test.css from Css Minimizer +Message [test.css:1,1]] +`; + +exports[`CssMinimizerPlugin buildError method 3`] = ` +[Error: test.css from Css Minimizer Webpack Plugin +Message [http://example.com/www/js/one.css:1,1][test.css:1,1]] +`; + +exports[`CssMinimizerPlugin buildError method 4`] = ` +[Error: test.css from Css Minimizer +Stack] +`; + +exports[`CssMinimizerPlugin buildWarning method 1`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 2`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 3`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; + +exports[`CssMinimizerPlugin buildWarning method 4`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; + +exports[`CssMinimizerPlugin buildWarning method 5`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; + +exports[`CssMinimizerPlugin buildWarning method 6`] = `null`; + +exports[`CssMinimizerPlugin should build error: error 1`] = ` +Array [ + "Error: error.css from Css Minimizer +/error.css:1:1: Unknown word [error.css:1,1]", +] +`; + +exports[`CssMinimizerPlugin should build error: warning 1`] = `Array []`; + +exports[`CssMinimizerPlugin should build warning: error 1`] = `Array []`; + +exports[`CssMinimizerPlugin should build warning: warning 1`] = ` +Array [ + "Css Minimizer Plugin: warning-plugin: /foo.css:2:5: Warning ", +] +`; + +exports[`CssMinimizerPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`; + +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; + +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` +"body{color:red}a{color:#00f} +/*# sourceMappingURL=entry.css.map?v=test*/" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` +Object { + "one.css": ".minify {};", + "two.css": ".minify {};", +} +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/CssnanoPlugin.test.js.snap.webpack4 b/test/__snapshots__/CssnanoPlugin.test.js.snap.webpack4 index b969155..1eb3526 100644 --- a/test/__snapshots__/CssnanoPlugin.test.js.snap.webpack4 +++ b/test/__snapshots__/CssnanoPlugin.test.js.snap.webpack4 @@ -1,82 +1,82 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`CssnanoPlugin buildError method 1`] = ` -[Error: test.css from Cssnano +exports[`CssMinimizerPlugin buildError method 1`] = ` +[Error: test.css from Css Minimizer Message] `; -exports[`CssnanoPlugin buildError method 2`] = ` -[Error: test.css from Cssnano +exports[`CssMinimizerPlugin buildError method 2`] = ` +[Error: test.css from Css Minimizer Message [test.css:1,1]] `; -exports[`CssnanoPlugin buildError method 3`] = ` -[Error: test.css from Cssnano Webpack Plugin +exports[`CssMinimizerPlugin buildError method 3`] = ` +[Error: test.css from Css Minimizer Webpack Plugin Message [http://example.com/www/js/one.css:1,1][test.css:1,1]] `; -exports[`CssnanoPlugin buildError method 4`] = ` -[Error: test.css from Cssnano +exports[`CssMinimizerPlugin buildError method 4`] = ` +[Error: test.css from Css Minimizer Stack] `; -exports[`CssnanoPlugin buildWarning method 1`] = `"Cssnano Plugin: Warning test.css:1:1 "`; +exports[`CssMinimizerPlugin buildWarning method 1`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; -exports[`CssnanoPlugin buildWarning method 2`] = `"Cssnano Plugin: Warning test.css:1:1 "`; +exports[`CssMinimizerPlugin buildWarning method 2`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; -exports[`CssnanoPlugin buildWarning method 3`] = `"Cssnano Plugin: Warning test.css:1:1 "`; +exports[`CssMinimizerPlugin buildWarning method 3`] = `"Css Minimizer Plugin: Warning test.css:1:1 "`; -exports[`CssnanoPlugin buildWarning method 4`] = `"Cssnano Plugin: Warning http://example.com/www/js/one.css:1:1"`; +exports[`CssMinimizerPlugin buildWarning method 4`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; -exports[`CssnanoPlugin buildWarning method 5`] = `"Cssnano Plugin: Warning http://example.com/www/js/one.css:1:1"`; +exports[`CssMinimizerPlugin buildWarning method 5`] = `"Css Minimizer Plugin: Warning http://example.com/www/js/one.css:1:1"`; -exports[`CssnanoPlugin buildWarning method 6`] = `null`; +exports[`CssMinimizerPlugin buildWarning method 6`] = `null`; -exports[`CssnanoPlugin should build error: error 1`] = ` +exports[`CssMinimizerPlugin should build error: error 1`] = ` Array [ - "Error: error.css from Cssnano + "Error: error.css from Css Minimizer /error.css:1:1: Unknown word [error.css:1,1]", ] `; -exports[`CssnanoPlugin should build error: warning 1`] = `Array []`; +exports[`CssMinimizerPlugin should build error: warning 1`] = `Array []`; -exports[`CssnanoPlugin should build warning: error 1`] = `Array []`; +exports[`CssMinimizerPlugin should build warning: error 1`] = `Array []`; -exports[`CssnanoPlugin should build warning: warning 1`] = ` +exports[`CssMinimizerPlugin should build warning: warning 1`] = ` Array [ - "Cssnano Plugin: warning-plugin: /foo.css:2:5: Warning ", + "Css Minimizer Plugin: warning-plugin: /foo.css:2:5: Warning ", ] `; -exports[`CssnanoPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`; +exports[`CssMinimizerPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`; -exports[`CssnanoPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`CssnanoPlugin should work with assets using querystring: entry.css?v=test 1`] = ` +exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` "body{color:red}a{color:#00f} /*# sourceMappingURL=entry.css.map?v=test*/" `; -exports[`CssnanoPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` Object { "one.css": ".minify {};", "two.css": ".minify {};", } `; -exports[`CssnanoPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; -exports[`CssnanoPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` "stderr stderr " `; -exports[`CssnanoPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` "stdout stdout " `; -exports[`CssnanoPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; +exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack4 b/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack4 new file mode 100644 index 0000000..aca8daf --- /dev/null +++ b/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack4 @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (disable): entry.css 1`] = ` +"body{ + /* this is a comment */ + /*! this is a comment with exclamation mark */color:red}" +`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (enable [default]): entry.css 1`] = ` +"body{ + /*! this is a comment with exclamation mark */color:red}" +`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (enable, with "removeAll" option): entry.css 1`] = `"body{color:red}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardEmpty" option (disable): entry.css 1`] = `"body{color:red}a{}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardEmpty" option (enable [default]): entry.css 1`] = `"body{color:red}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "mergeRules" option (disable): entry.css 1`] = `"body{color:red}body{font-weight:700}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "mergeRules" option (enable [default]): entry.css 1`] = `"body{color:red;font-weight:700}"`; diff --git a/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack5 b/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack5 new file mode 100644 index 0000000..aca8daf --- /dev/null +++ b/test/__snapshots__/cssMinimizerOptions-option.test.js.snap.webpack5 @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (disable): entry.css 1`] = ` +"body{ + /* this is a comment */ + /*! this is a comment with exclamation mark */color:red}" +`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (enable [default]): entry.css 1`] = ` +"body{ + /*! this is a comment with exclamation mark */color:red}" +`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardComments" option (enable, with "removeAll" option): entry.css 1`] = `"body{color:red}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardEmpty" option (disable): entry.css 1`] = `"body{color:red}a{}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "discardEmpty" option (enable [default]): entry.css 1`] = `"body{color:red}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "mergeRules" option (disable): entry.css 1`] = `"body{color:red}body{font-weight:700}"`; + +exports[`when applied with "minimizerOptions" option matches snapshot for "mergeRules" option (enable [default]): entry.css 1`] = `"body{color:red;font-weight:700}"`; diff --git a/test/__snapshots__/cssnanoOptions-option.test.js.snap.webpack4 b/test/__snapshots__/cssnanoOptions-option.test.js.snap.webpack4 index 1442488..e7ced03 100644 --- a/test/__snapshots__/cssnanoOptions-option.test.js.snap.webpack4 +++ b/test/__snapshots__/cssnanoOptions-option.test.js.snap.webpack4 @@ -1,22 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with "cssnanoOptions" option matches snapshot for "discardComments" option (disable): entry.css 1`] = ` +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "discardComments" option (disable): entry.css 1`] = ` "body{ /* this is a comment */ /*! this is a comment with exclamation mark */color:red}" `; -exports[`when applied with "cssnanoOptions" option matches snapshot for "discardComments" option (enable [default]): entry.css 1`] = ` +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "discardComments" option (enable [default]): entry.css 1`] = ` "body{ /*! this is a comment with exclamation mark */color:red}" `; -exports[`when applied with "cssnanoOptions" option matches snapshot for "discardComments" option (enable, with "removeAll" option): entry.css 1`] = `"body{color:red}"`; +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "discardComments" option (enable, with "removeAll" option): entry.css 1`] = `"body{color:red}"`; -exports[`when applied with "cssnanoOptions" option matches snapshot for "discardEmpty" option (disable): entry.css 1`] = `"body{color:red}a{}"`; +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "discardEmpty" option (disable): entry.css 1`] = `"body{color:red}a{}"`; -exports[`when applied with "cssnanoOptions" option matches snapshot for "discardEmpty" option (enable [default]): entry.css 1`] = `"body{color:red}"`; +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "discardEmpty" option (enable [default]): entry.css 1`] = `"body{color:red}"`; -exports[`when applied with "cssnanoOptions" option matches snapshot for "mergeRules" option (disable): entry.css 1`] = `"body{color:red}body{font-weight:700}"`; +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "mergeRules" option (disable): entry.css 1`] = `"body{color:red}body{font-weight:700}"`; -exports[`when applied with "cssnanoOptions" option matches snapshot for "mergeRules" option (enable [default]): entry.css 1`] = `"body{color:red;font-weight:700}"`; +exports[`when applied with "cssMinimizerOptions" option matches snapshot for "mergeRules" option (enable [default]): entry.css 1`] = `"body{color:red;font-weight:700}"`; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 index 0e60fcc..79beb3e 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 @@ -52,10 +52,10 @@ exports[`when applied with "sourceMap" option matches snapshot when using Source exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: error 1`] = ` Array [ - "Error: broken-source-map.css from Cssnano + "Error: broken-source-map.css from Css Minimizer Error: \\"version\\" is a required argument.", "ModuleBuildError: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): -Error: broken-source-map.css from Cssnano", +Error: broken-source-map.css from Css Minimizer", ] `; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 index 0e60fcc..79beb3e 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 @@ -52,10 +52,10 @@ exports[`when applied with "sourceMap" option matches snapshot when using Source exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: error 1`] = ` Array [ - "Error: broken-source-map.css from Cssnano + "Error: broken-source-map.css from Css Minimizer Error: \\"version\\" is a required argument.", "ModuleBuildError: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): -Error: broken-source-map.css from Cssnano", +Error: broken-source-map.css from Css Minimizer", ] `; diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index fd64362..23c43f1 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`validation 1`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.test should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -17,7 +17,7 @@ exports[`validation 1`] = ` `; exports[`validation 2`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.test should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -31,7 +31,7 @@ exports[`validation 2`] = ` `; exports[`validation 3`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.include should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -47,7 +47,7 @@ exports[`validation 3`] = ` `; exports[`validation 4`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.include should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -61,7 +61,7 @@ exports[`validation 4`] = ` `; exports[`validation 5`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.exclude should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -77,7 +77,7 @@ exports[`validation 5`] = ` `; exports[`validation 6`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.exclude should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -91,7 +91,7 @@ exports[`validation 6`] = ` `; exports[`validation 7`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.sourceMap should be one of these: object { … } | boolean -> Enables/Disables generation of source maps. @@ -103,14 +103,14 @@ exports[`validation 7`] = ` `; exports[`validation 8`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. - - options.cssnanoOptions should be an object: +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. + - options.minimizerOptions should be an object: object { … } - -> Options for \`cssnanoOptions\`." + -> Options for \`cssMinimizerOptions\`." `; exports[`validation 9`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.cache should be one of these: boolean | string -> Enable file caching. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache. @@ -120,13 +120,13 @@ exports[`validation 9`] = ` `; exports[`validation 10`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.cacheKeys should be an instance of function. -> Allows you to override default cache keys. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache." `; exports[`validation 11`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.parallel should be one of these: boolean | integer -> Use multi-process parallel running to improve the build speed. @@ -136,7 +136,7 @@ exports[`validation 11`] = ` `; exports[`validation 12`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.parallel should be one of these: boolean | integer -> Use multi-process parallel running to improve the build speed. @@ -146,13 +146,13 @@ exports[`validation 12`] = ` `; exports[`validation 13`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.minify should be an instance of function. -> Allows you to override default minify function." `; exports[`validation 14`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { test?, include?, exclude?, sourceMap?, cssnanoOptions?, cache?, cacheKeys?, parallel?, warningsFilter?, minify? }" + object { test?, include?, exclude?, sourceMap?, minimizerOptions?, cache?, cacheKeys?, parallel?, warningsFilter?, minify? }" `; diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index fd64362..23c43f1 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`validation 1`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.test should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -17,7 +17,7 @@ exports[`validation 1`] = ` `; exports[`validation 2`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.test should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -31,7 +31,7 @@ exports[`validation 2`] = ` `; exports[`validation 3`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.include should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -47,7 +47,7 @@ exports[`validation 3`] = ` `; exports[`validation 4`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.include should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -61,7 +61,7 @@ exports[`validation 4`] = ` `; exports[`validation 5`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.exclude should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -77,7 +77,7 @@ exports[`validation 5`] = ` `; exports[`validation 6`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.exclude should be one of these: [RegExp | non-empty string, ...] | RegExp | non-empty string -> Filtering rules. @@ -91,7 +91,7 @@ exports[`validation 6`] = ` `; exports[`validation 7`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.sourceMap should be one of these: object { … } | boolean -> Enables/Disables generation of source maps. @@ -103,14 +103,14 @@ exports[`validation 7`] = ` `; exports[`validation 8`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. - - options.cssnanoOptions should be an object: +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. + - options.minimizerOptions should be an object: object { … } - -> Options for \`cssnanoOptions\`." + -> Options for \`cssMinimizerOptions\`." `; exports[`validation 9`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.cache should be one of these: boolean | string -> Enable file caching. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache. @@ -120,13 +120,13 @@ exports[`validation 9`] = ` `; exports[`validation 10`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.cacheKeys should be an instance of function. -> Allows you to override default cache keys. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache." `; exports[`validation 11`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.parallel should be one of these: boolean | integer -> Use multi-process parallel running to improve the build speed. @@ -136,7 +136,7 @@ exports[`validation 11`] = ` `; exports[`validation 12`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.parallel should be one of these: boolean | integer -> Use multi-process parallel running to improve the build speed. @@ -146,13 +146,13 @@ exports[`validation 12`] = ` `; exports[`validation 13`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options.minify should be an instance of function. -> Allows you to override default minify function." `; exports[`validation 14`] = ` -"Invalid options object. Cssnano Plugin has been initialized using an options object that does not match the API schema. +"Invalid options object. Css Minimizer Plugin has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { test?, include?, exclude?, sourceMap?, cssnanoOptions?, cache?, cacheKeys?, parallel?, warningsFilter?, minify? }" + object { test?, include?, exclude?, sourceMap?, minimizerOptions?, cache?, cacheKeys?, parallel?, warningsFilter?, minify? }" `; diff --git a/test/__snapshots__/warningsFilter-option.test.js.snap.webpack4 b/test/__snapshots__/warningsFilter-option.test.js.snap.webpack4 index 73263fc..f3d62fb 100644 --- a/test/__snapshots__/warningsFilter-option.test.js.snap.webpack4 +++ b/test/__snapshots__/warningsFilter-option.test.js.snap.webpack4 @@ -36,7 +36,7 @@ exports[`warningsFilter option should match snapshot for a "function" value: err exports[`warningsFilter option should match snapshot for a "function" value: warnings 1`] = ` Array [ - "Cssnano Plugin: warning-plugin: Warning from bar1.css ", - "Cssnano Plugin: warning-plugin: Warning from bar2.css ", + "Css Minimizer Plugin: warning-plugin: Warning from bar1.css ", + "Css Minimizer Plugin: warning-plugin: Warning from bar2.css ", ] `; diff --git a/test/__snapshots__/warningsFilter-option.test.js.snap.webpack5 b/test/__snapshots__/warningsFilter-option.test.js.snap.webpack5 index 73263fc..f3d62fb 100644 --- a/test/__snapshots__/warningsFilter-option.test.js.snap.webpack5 +++ b/test/__snapshots__/warningsFilter-option.test.js.snap.webpack5 @@ -36,7 +36,7 @@ exports[`warningsFilter option should match snapshot for a "function" value: err exports[`warningsFilter option should match snapshot for a "function" value: warnings 1`] = ` Array [ - "Cssnano Plugin: warning-plugin: Warning from bar1.css ", - "Cssnano Plugin: warning-plugin: Warning from bar2.css ", + "Css Minimizer Plugin: warning-plugin: Warning from bar1.css ", + "Css Minimizer Plugin: warning-plugin: Warning from bar2.css ", ] `; diff --git a/test/__snapshots__/worker.test.js.snap.webpack4 b/test/__snapshots__/worker.test.js.snap.webpack4 index 254cd8d..4d31720 100644 --- a/test/__snapshots__/worker.test.js.snap.webpack4 +++ b/test/__snapshots__/worker.test.js.snap.webpack4 @@ -8,7 +8,7 @@ Array [ exports[`worker should emit minimizer error: error 1`] = ` Array [ - "cssnano error", + "css minimizer error", ] `; diff --git a/test/__snapshots__/worker.test.js.snap.webpack5 b/test/__snapshots__/worker.test.js.snap.webpack5 index 254cd8d..4d31720 100644 --- a/test/__snapshots__/worker.test.js.snap.webpack5 +++ b/test/__snapshots__/worker.test.js.snap.webpack5 @@ -8,7 +8,7 @@ Array [ exports[`worker should emit minimizer error: error 1`] = ` Array [ - "cssnano error", + "css minimizer error", ] `; diff --git a/test/cache-option.test.js b/test/cache-option.test.js index 17d45c4..b90c630 100644 --- a/test/cache-option.test.js +++ b/test/cache-option.test.js @@ -2,7 +2,7 @@ import cacache from 'cacache'; import findCacheDir from 'find-cache-dir'; import Webpack4Cache from '../src/Webpack4Cache'; -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { compile, @@ -71,7 +71,7 @@ if (getCompiler.isWebpack4()) { .spyOn(Webpack4Cache, 'getCacheDirectory') .mockImplementation(() => uniqueCacheDirectory); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); const stats = await compile(compiler); @@ -112,7 +112,7 @@ if (getCompiler.isWebpack4()) { const cacacheGetSpy = jest.spyOn(cacache, 'get'); const cacachePutSpy = jest.spyOn(cacache, 'put'); - new CssnanoPlugin({ cache: false }).apply(compiler); + new CssMinimizerPlugin({ cache: false }).apply(compiler); const stats = await compile(compiler); @@ -138,7 +138,7 @@ if (getCompiler.isWebpack4()) { return uniqueOtherDirectory; }); - new CssnanoPlugin({ cache: true }).apply(compiler); + new CssMinimizerPlugin({ cache: true }).apply(compiler); const stats = await compile(compiler); @@ -179,7 +179,7 @@ if (getCompiler.isWebpack4()) { const cacacheGetSpy = jest.spyOn(cacache, 'get'); const cacachePutSpy = jest.spyOn(cacache, 'put'); - new CssnanoPlugin({ cache: otherCacheDir }).apply(compiler); + new CssMinimizerPlugin({ cache: otherCacheDir }).apply(compiler); const stats = await compile(compiler); @@ -219,7 +219,7 @@ if (getCompiler.isWebpack4()) { const cacacheGetSpy = jest.spyOn(cacache, 'get'); const cacachePutSpy = jest.spyOn(cacache, 'put'); - new CssnanoPlugin({ + new CssMinimizerPlugin({ cache: otherOtherCacheDir, cacheKeys: (defaultCacheKeys, file) => { // eslint-disable-next-line no-param-reassign @@ -275,7 +275,7 @@ if (getCompiler.isWebpack4()) { return otherOtherOtherCacheDir; }); - new CssnanoPlugin({ cache: true }).apply(compiler); + new CssMinimizerPlugin({ cache: true }).apply(compiler); const stats = await compile(compiler); @@ -304,7 +304,7 @@ if (getCompiler.isWebpack4()) { }, }); - new CssnanoPlugin({ cache: true }).apply(compiler); + new CssMinimizerPlugin({ cache: true }).apply(compiler); const newStats = await compile(compiler); diff --git a/test/cssnanoOptions-option.test.js b/test/cssMinimizerOptions-option.test.js similarity index 81% rename from test/cssnanoOptions-option.test.js rename to test/cssMinimizerOptions-option.test.js index 8300c7c..c2b3cd9 100644 --- a/test/cssnanoOptions-option.test.js +++ b/test/cssMinimizerOptions-option.test.js @@ -1,10 +1,10 @@ -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { getCompiler, compile, readAsset, removeCache } from './helpers'; jest.setTimeout(30000); -describe('when applied with "cssnanoOptions" option', () => { +describe('when applied with "minimizerOptions" option', () => { beforeEach(() => Promise.all([removeCache()])); afterEach(() => Promise.all([removeCache()])); @@ -12,10 +12,10 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "discardComments" option (enable [default])', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/discardComments.css`, + entry: `${__dirname}/fixtures/minimizerOptions/discardComments.css`, }, }); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(stats.compilation.errors).toEqual([]); @@ -32,11 +32,11 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "discardComments" option (disable)', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/discardComments.css`, + entry: `${__dirname}/fixtures/minimizerOptions/discardComments.css`, }, }); - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: ['default', { discardComments: false }], }, }).apply(compiler); @@ -56,11 +56,11 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "discardComments" option (enable, with "removeAll" option)', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/discardComments.css`, + entry: `${__dirname}/fixtures/minimizerOptions/discardComments.css`, }, }); - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: ['default', { discardComments: { removeAll: true } }], }, }).apply(compiler); @@ -80,10 +80,10 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "mergeRules" option (enable [default])', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/mergeRules.css`, + entry: `${__dirname}/fixtures/minimizerOptions/mergeRules.css`, }, }); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(stats.compilation.errors).toEqual([]); @@ -100,11 +100,11 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "mergeRules" option (disable)', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/mergeRules.css`, + entry: `${__dirname}/fixtures/minimizerOptions/mergeRules.css`, }, }); - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: ['default', { mergeRules: false }], }, }).apply(compiler); @@ -124,10 +124,10 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "discardEmpty" option (enable [default])', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/discardEmpty.css`, + entry: `${__dirname}/fixtures/minimizerOptions/discardEmpty.css`, }, }); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(stats.compilation.errors).toEqual([]); @@ -144,11 +144,11 @@ describe('when applied with "cssnanoOptions" option', () => { it('matches snapshot for "discardEmpty" option (disable)', () => { const compiler = getCompiler({ entry: { - entry: `${__dirname}/fixtures/cssnanooptions/discardEmpty.css`, + entry: `${__dirname}/fixtures/minimizerOptions/discardEmpty.css`, }, }); - new CssnanoPlugin({ - cssnanoOptions: { + new CssMinimizerPlugin({ + minimizerOptions: { preset: ['default', { discardEmpty: false }], }, }).apply(compiler); diff --git a/test/exclude-option.test.js b/test/exclude-option.test.js index 7fc8a98..76cdb10 100644 --- a/test/exclude-option.test.js +++ b/test/exclude-option.test.js @@ -1,4 +1,4 @@ -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { compile, @@ -27,7 +27,7 @@ describe('exclude option', () => { afterEach(() => Promise.all([removeCache()])); it('should match snapshot for a single RegExp value excluded1', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ exclude: /excluded1/i, }).apply(compiler); @@ -39,7 +39,7 @@ describe('exclude option', () => { }); it('should match snapshot for a single String value excluded1', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ exclude: 'excluded1', }).apply(compiler); @@ -51,7 +51,7 @@ describe('exclude option', () => { }); it('should match snapshot for multiple RegExp values excluded1 and excluded2', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ exclude: [/excluded1/i, /excluded2/i], }).apply(compiler); @@ -63,7 +63,7 @@ describe('exclude option', () => { }); it('should match snapshot for multiple String values excluded1 and excluded2', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ exclude: ['excluded1', 'excluded2'], }).apply(compiler); diff --git a/test/fixtures/cssnanooptions/discardComments.css b/test/fixtures/minimizerOptions/discardComments.css similarity index 100% rename from test/fixtures/cssnanooptions/discardComments.css rename to test/fixtures/minimizerOptions/discardComments.css diff --git a/test/fixtures/cssnanooptions/discardEmpty.css b/test/fixtures/minimizerOptions/discardEmpty.css similarity index 100% rename from test/fixtures/cssnanooptions/discardEmpty.css rename to test/fixtures/minimizerOptions/discardEmpty.css diff --git a/test/fixtures/cssnanooptions/mergeRules.css b/test/fixtures/minimizerOptions/mergeRules.css similarity index 100% rename from test/fixtures/cssnanooptions/mergeRules.css rename to test/fixtures/minimizerOptions/mergeRules.css diff --git a/test/helpers/getCacheDirectory.js b/test/helpers/getCacheDirectory.js index fc04188..35e673f 100644 --- a/test/helpers/getCacheDirectory.js +++ b/test/helpers/getCacheDirectory.js @@ -3,7 +3,7 @@ import os from 'os'; import findCacheDir from 'find-cache-dir'; function getCacheDirectory() { - return findCacheDir({ name: 'cssnano-webpack-plugin' }) || os.tmpdir(); + return findCacheDir({ name: 'css-minimizer-webpack-plugin' }) || os.tmpdir(); } export default getCacheDirectory; diff --git a/test/include-option.test.js b/test/include-option.test.js index c762476..590cab3 100644 --- a/test/include-option.test.js +++ b/test/include-option.test.js @@ -1,4 +1,4 @@ -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { compile, @@ -27,7 +27,7 @@ describe('include option', () => { afterEach(() => Promise.all([removeCache()])); it('should match snapshot for a single RegExp value included1', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ include: /included1/i, }).apply(compiler); @@ -39,7 +39,7 @@ describe('include option', () => { }); it('should match snapshot for a single String value included1', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ include: 'included1', }).apply(compiler); @@ -51,7 +51,7 @@ describe('include option', () => { }); it('should match snapshot for multiple RegExp values included1 and included2', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ include: [/included1/i, /included2/i], }).apply(compiler); @@ -63,7 +63,7 @@ describe('include option', () => { }); it('should match snapshot for multiple String values included1 and included2', async () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ include: ['included1', 'included2'], }).apply(compiler); diff --git a/test/parallel-option.test.js b/test/parallel-option.test.js index ca9984b..47b216b 100644 --- a/test/parallel-option.test.js +++ b/test/parallel-option.test.js @@ -2,7 +2,7 @@ import os from 'os'; import Worker from 'jest-worker'; -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { compile, @@ -67,7 +67,7 @@ describe('parallel option', () => { afterEach(() => Promise.all([removeCache()])); it('should match snapshot when a value is not specify', async () => { - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); const stats = await compile(compiler); @@ -86,7 +86,7 @@ describe('parallel option', () => { }); it('should match snapshot for the "false" value', async () => { - new CssnanoPlugin({ parallel: false }).apply(compiler); + new CssMinimizerPlugin({ parallel: false }).apply(compiler); const stats = await compile(compiler); @@ -98,7 +98,7 @@ describe('parallel option', () => { }); it('should match snapshot for the "true" value', async () => { - new CssnanoPlugin({ parallel: true }).apply(compiler); + new CssMinimizerPlugin({ parallel: true }).apply(compiler); const stats = await compile(compiler); @@ -117,7 +117,7 @@ describe('parallel option', () => { }); it('should match snapshot for the "2" value', async () => { - new CssnanoPlugin({ parallel: 2 }).apply(compiler); + new CssMinimizerPlugin({ parallel: 2 }).apply(compiler); const stats = await compile(compiler); @@ -140,7 +140,7 @@ describe('parallel option', () => { entry: `${__dirname}/fixtures/entry.js`, }); - new CssnanoPlugin({ parallel: true }).apply(compiler); + new CssMinimizerPlugin({ parallel: true }).apply(compiler); const stats = await compile(compiler); @@ -167,7 +167,7 @@ describe('parallel option', () => { compiler = getCompiler({ entry: entries }); - new CssnanoPlugin({ parallel: true }).apply(compiler); + new CssMinimizerPlugin({ parallel: true }).apply(compiler); const stats = await compile(compiler); @@ -194,7 +194,7 @@ describe('parallel option', () => { compiler = getCompiler({ entry: entries }); - new CssnanoPlugin({ parallel: true }).apply(compiler); + new CssMinimizerPlugin({ parallel: true }).apply(compiler); const stats = await compile(compiler); @@ -232,7 +232,7 @@ describe('parallel option', () => { }, }); - new CssnanoPlugin({ parallel: true }).apply(compiler); + new CssMinimizerPlugin({ parallel: true }).apply(compiler); const stats = await compile(compiler); diff --git a/test/sourceMap-option.test.js b/test/sourceMap-option.test.js index a06529b..db63a38 100644 --- a/test/sourceMap-option.test.js +++ b/test/sourceMap-option.test.js @@ -1,7 +1,7 @@ import webpack from 'webpack'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { getCompiler, @@ -44,7 +44,7 @@ describe('when applied with "sourceMap" option', () => { it('matches snapshot for "false" value, without previous sourcemap', () => { const compiler = getCompiler(baseConfig); - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(stats.compilation.errors).toEqual([]); @@ -60,7 +60,7 @@ describe('when applied with "sourceMap" option', () => { it('matches snapshot for "true" value, without previous sourcemap', () => { const compiler = getCompiler(baseConfig); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }).apply(compiler); @@ -100,7 +100,7 @@ describe('when applied with "sourceMap" option', () => { }); const compiler = getCompiler(config); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: false, }).apply(compiler); @@ -133,7 +133,7 @@ describe('when applied with "sourceMap" option', () => { }); const compiler = getCompiler(config); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }).apply(compiler); @@ -158,7 +158,7 @@ describe('when applied with "sourceMap" option', () => { it('matches snapshot for "inline" value', () => { const compiler = getCompiler(baseConfig); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: { inline: true }, }).apply(compiler); @@ -209,7 +209,7 @@ describe('when applied with "sourceMap" option', () => { }); const compiler = getCompiler(config); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }).apply(compiler); @@ -280,7 +280,7 @@ describe('when applied with "sourceMap" option', () => { }); const compiler = getCompiler(config); - new CssnanoPlugin({ + new CssMinimizerPlugin({ sourceMap: true, }).apply(compiler); diff --git a/test/test-option.test.js b/test/test-option.test.js index 2a647fd..bfb56b6 100644 --- a/test/test-option.test.js +++ b/test/test-option.test.js @@ -1,4 +1,4 @@ -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { getCompiler, compile, readAsset, removeCache } from './helpers'; @@ -22,7 +22,7 @@ describe('when applied with "test" option', () => { afterEach(() => Promise.all([removeCache()])); it('matches snapshot with empty value', () => { - new CssnanoPlugin().apply(compiler); + new CssMinimizerPlugin().apply(compiler); return compile(compiler).then((stats) => { expect(stats.compilation.errors).toEqual([]); @@ -37,7 +37,7 @@ describe('when applied with "test" option', () => { }); it('matches snapshot for a single "test" value (RegExp)', () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ test: /bar.*\.css$/, }).apply(compiler); @@ -54,7 +54,7 @@ describe('when applied with "test" option', () => { }); it('matches snapshot for multiple "test" value (RegExp)', () => { - new CssnanoPlugin({ + new CssMinimizerPlugin({ test: [/bar1.*\.css$/, /bar2.*\.css$/], }).apply(compiler); diff --git a/test/validate-options.test.js b/test/validate-options.test.js index f88dbf8..3077669 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -1,187 +1,187 @@ -import CssnanoWebpackPlugin from '../src'; +import CssMinimizerPlugin from '../src'; it('validation', () => { /* eslint-disable no-new */ expect(() => { - new CssnanoWebpackPlugin({ test: /foo/ }); + new CssMinimizerPlugin({ test: /foo/ }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: 'foo' }); + new CssMinimizerPlugin({ test: 'foo' }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: [/foo/] }); + new CssMinimizerPlugin({ test: [/foo/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: [/foo/, /bar/] }); + new CssMinimizerPlugin({ test: [/foo/, /bar/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: ['foo', 'bar'] }); + new CssMinimizerPlugin({ test: ['foo', 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: [/foo/, 'bar'] }); + new CssMinimizerPlugin({ test: [/foo/, 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ test: true }); + new CssMinimizerPlugin({ test: true }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ test: [true] }); + new CssMinimizerPlugin({ test: [true] }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ include: /foo/ }); + new CssMinimizerPlugin({ include: /foo/ }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: 'foo' }); + new CssMinimizerPlugin({ include: 'foo' }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: [/foo/] }); + new CssMinimizerPlugin({ include: [/foo/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: [/foo/, /bar/] }); + new CssMinimizerPlugin({ include: [/foo/, /bar/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: ['foo', 'bar'] }); + new CssMinimizerPlugin({ include: ['foo', 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: [/foo/, 'bar'] }); + new CssMinimizerPlugin({ include: [/foo/, 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ include: true }); + new CssMinimizerPlugin({ include: true }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ include: [true] }); + new CssMinimizerPlugin({ include: [true] }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ exclude: /foo/ }); + new CssMinimizerPlugin({ exclude: /foo/ }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: 'foo' }); + new CssMinimizerPlugin({ exclude: 'foo' }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: [/foo/] }); + new CssMinimizerPlugin({ exclude: [/foo/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: [/foo/, /bar/] }); + new CssMinimizerPlugin({ exclude: [/foo/, /bar/] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: ['foo', 'bar'] }); + new CssMinimizerPlugin({ exclude: ['foo', 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: [/foo/, 'bar'] }); + new CssMinimizerPlugin({ exclude: [/foo/, 'bar'] }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ exclude: true }); + new CssMinimizerPlugin({ exclude: true }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ exclude: [true] }); + new CssMinimizerPlugin({ exclude: [true] }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ sourceMap: true }); + new CssMinimizerPlugin({ sourceMap: true }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ sourceMap: false }); + new CssMinimizerPlugin({ sourceMap: false }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ sourceMap: { inline: true } }); + new CssMinimizerPlugin({ sourceMap: { inline: true } }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ sourceMap: 'true' }); + new CssMinimizerPlugin({ sourceMap: 'true' }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ cssnanoOptions: {} }); + new CssMinimizerPlugin({ minimizerOptions: {} }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cssnanoOptions: null }); + new CssMinimizerPlugin({ minimizerOptions: null }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ - cssnanoOptions: { colormin: true }, + new CssMinimizerPlugin({ + minimizerOptions: { colormin: true }, }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cache: true }); + new CssMinimizerPlugin({ cache: true }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cache: false }); + new CssMinimizerPlugin({ cache: false }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cache: 'path/to/cache/directory' }); + new CssMinimizerPlugin({ cache: 'path/to/cache/directory' }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cache: {} }); + new CssMinimizerPlugin({ cache: {} }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ cacheKeys() {} }); + new CssMinimizerPlugin({ cacheKeys() {} }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ cacheKeys: 'test' }); + new CssMinimizerPlugin({ cacheKeys: 'test' }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ parallel: true }); + new CssMinimizerPlugin({ parallel: true }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ parallel: false }); + new CssMinimizerPlugin({ parallel: false }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ parallel: 2 }); + new CssMinimizerPlugin({ parallel: 2 }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ parallel: '2' }); + new CssMinimizerPlugin({ parallel: '2' }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ parallel: {} }); + new CssMinimizerPlugin({ parallel: {} }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ minify() {} }); + new CssMinimizerPlugin({ minify() {} }); }).not.toThrow(); expect(() => { - new CssnanoWebpackPlugin({ minify: true }); + new CssMinimizerPlugin({ minify: true }); }).toThrowErrorMatchingSnapshot(); expect(() => { - new CssnanoWebpackPlugin({ unknown: true }); + new CssMinimizerPlugin({ unknown: true }); }).toThrowErrorMatchingSnapshot(); /* eslint-enable no-new */ }); diff --git a/test/warningsFilter-option.test.js b/test/warningsFilter-option.test.js index 950e86a..624f7e5 100644 --- a/test/warningsFilter-option.test.js +++ b/test/warningsFilter-option.test.js @@ -1,6 +1,6 @@ import postcss from 'postcss'; -import CssnanoPlugin from '../src/index'; +import CssMinimizerPlugin from '../src/index'; import { compile, @@ -31,7 +31,7 @@ describe('warningsFilter option', () => { }, }); - new CssnanoPlugin({ + new CssMinimizerPlugin({ parallel: false, minify: (data) => { return postcss([plugin]) diff --git a/test/worker.test.js b/test/worker.test.js index 9364f43..09f995e 100644 --- a/test/worker.test.js +++ b/test/worker.test.js @@ -17,7 +17,7 @@ describe('worker', () => { file: 'x', sourcesContent: ['.foo{color:red;}', '.bar{color:coral;}'], }, - cssnanoOptions: { discardComments: false }, + minimizerOptions: { discardComments: false }, }; const { css, map } = await transform(serialize(options)); @@ -29,7 +29,7 @@ describe('worker', () => { const options = { file: 'entry.css', input: '.foo{color:red;}\n.bar{color:coral;}', - cssnanoOptions: { discardComments: false }, + minimizerOptions: { discardComments: false }, inputSourceMap: { version: 3, sources: ['foo.css', 'bar.css'], @@ -49,7 +49,7 @@ describe('worker', () => { const options = { file: 'entry.css', input: '.foo{color:red;}\n.bar{color:coral;}', - cssnanoOptions: { discardComments: false }, + minimizerOptions: { discardComments: false }, minify: () => { return { css: '.minify {};' }; }, @@ -82,7 +82,7 @@ describe('worker', () => { file: 'entry.css', input: false, minify: () => { - return { error: new Error('cssnano error') }; + return { error: new Error('css minimizer error') }; }, };