From 921125143fe9d5f4d6bb339e7b007e11b3bbe789 Mon Sep 17 00:00:00 2001 From: Scott Norvell Date: Thu, 1 Feb 2018 08:59:41 -0500 Subject: [PATCH] Add tests * add Jest, unit tests, webpack integration tests, test helpers * update README Co-authored-by: Scott Norvell Co-authored-by: Doug Schrashun --- .babelrc | 25 ++++++ .gitignore | 16 ++++ README.md | 4 +- package.json | 24 +++++- .../webpack-integration.test.js.snap | 22 +++++ .../a_optimize-me.css | 6 ++ .../b_optimize-me.css | 7 ++ test/cases/assetNameRegExp-no-source/c.css | 9 ++ .../expected/file.css | 1 + test/cases/assetNameRegExp-no-source/index.js | 10 +++ .../webpack.config.js | 26 ++++++ .../duplicate-css-exists-without-plugin/a.css | 6 ++ .../duplicate-css-exists-without-plugin/b.css | 6 ++ .../expected/file.css | 1 + .../index.js | 2 + .../webpack.config.js | 23 ++++++ .../a_optimize-me.css | 6 ++ .../b_optimize-me.css | 7 ++ .../c_as-is.css | 9 ++ .../expected/as_is.css | 9 ++ .../expected/optimize.css | 1 + .../only-assetNameRegExp-processed/index.js | 3 + .../webpack.config.js | 40 +++++++++ test/cases/removes-duplicate-css/a.css | 6 ++ test/cases/removes-duplicate-css/b.css | 6 ++ .../removes-duplicate-css/expected/file.css | 1 + test/cases/removes-duplicate-css/index.js | 2 + .../removes-duplicate-css/webpack.config.js | 24 ++++++ test/plugin.test.js | 26 ++++++ test/util/default.css | 1 + test/util/helpers.js | 40 +++++++++ test/util/index.js | 1 + test/webpack-integration.test.js | 82 +++++++++++++++++++ 33 files changed, 449 insertions(+), 3 deletions(-) create mode 100644 .babelrc create mode 100644 test/__snapshots__/webpack-integration.test.js.snap create mode 100644 test/cases/assetNameRegExp-no-source/a_optimize-me.css create mode 100644 test/cases/assetNameRegExp-no-source/b_optimize-me.css create mode 100644 test/cases/assetNameRegExp-no-source/c.css create mode 100644 test/cases/assetNameRegExp-no-source/expected/file.css create mode 100644 test/cases/assetNameRegExp-no-source/index.js create mode 100644 test/cases/assetNameRegExp-no-source/webpack.config.js create mode 100644 test/cases/duplicate-css-exists-without-plugin/a.css create mode 100644 test/cases/duplicate-css-exists-without-plugin/b.css create mode 100644 test/cases/duplicate-css-exists-without-plugin/expected/file.css create mode 100644 test/cases/duplicate-css-exists-without-plugin/index.js create mode 100644 test/cases/duplicate-css-exists-without-plugin/webpack.config.js create mode 100644 test/cases/only-assetNameRegExp-processed/a_optimize-me.css create mode 100644 test/cases/only-assetNameRegExp-processed/b_optimize-me.css create mode 100644 test/cases/only-assetNameRegExp-processed/c_as-is.css create mode 100644 test/cases/only-assetNameRegExp-processed/expected/as_is.css create mode 100644 test/cases/only-assetNameRegExp-processed/expected/optimize.css create mode 100644 test/cases/only-assetNameRegExp-processed/index.js create mode 100644 test/cases/only-assetNameRegExp-processed/webpack.config.js create mode 100644 test/cases/removes-duplicate-css/a.css create mode 100644 test/cases/removes-duplicate-css/b.css create mode 100644 test/cases/removes-duplicate-css/expected/file.css create mode 100644 test/cases/removes-duplicate-css/index.js create mode 100644 test/cases/removes-duplicate-css/webpack.config.js create mode 100644 test/plugin.test.js create mode 100644 test/util/default.css create mode 100644 test/util/helpers.js create mode 100644 test/util/index.js create mode 100644 test/webpack-integration.test.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..bd4aa18 --- /dev/null +++ b/.babelrc @@ -0,0 +1,25 @@ +{ + "presets": [ + [ + "env", + { + "useBuiltIns": true, + "targets": { + "node": "current" + }, + "exclude": [ + "transform-async-to-generator", + "transform-regenerator" + ] + } + ] + ], + "plugins": [ + [ + "transform-object-rest-spread", + { + "useBuiltIns": true + } + ] + ] +} diff --git a/.gitignore b/.gitignore index 8b5aec4..8c58456 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,18 @@ node_modules jsconfig.json +.DS_Store +npm-debug.log +/test/js + +logs +*.log +npm-debug.log* +.eslintcache +/dist +/local +/reports +Thumbs.db +.idea +.vscode +*.sublime-project +*.sublime-workspace diff --git a/README.md b/README.md index 1195b22..1e84dc6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ npm install --save-dev optimize-css-assets-webpack-plugin ## Configuration: The plugin can receive the following options (all of them are optional): -* assetNameRegExp: A regular expression that indicates the names of the assets that should be optimized \ minimized, defaults to `/\.css$/g` +* assetNameRegExp: A regular expression that indicates the names of the assets that should be optimized \ minimized. The regular expression provided is run against the filenames of the files exported by the ExtractTextPlugin instances in your configuration, not the filenames of your source CSS files. Defaults to `/\.css$/g` * cssProcessor: The CSS processor used to optimize \ minimize the CSS, defaults to [cssnano](http://github.com/ben-eb/cssnano). This should be a function that follows cssnano.process interface (receives a CSS and options parameters and returns a Promise). * cssProcessorOptions: The options passed to the cssProcessor, defaults to `{}` * canPrint: A boolean indicating if the plugin can print messages to the console, defaults to `true` @@ -33,7 +33,7 @@ The plugin can receive the following options (all of them are optional): var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); module.exports = { module: { - loaders: [ + rules: [ { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') diff --git a/package.json b/package.json index c7deed9..7f27f00 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,16 @@ "last-call-webpack-plugin": "^3.0.0" }, "main": "src/index.js", + "scripts": { + "test": "jest", + "test:watch": "jest --watch" + }, + "jest": { + "watchPathIgnorePatterns": [ + "/test/js/*.*" + ], + "testEnvironment": "node" + }, "homepage": "http://github.com/NMFR/optimize-css-assets-webpack-plugin", "repository": { "type": "git", @@ -22,5 +32,17 @@ "duplicate", "extract-text-webpack-plugin" ], - "license": "MIT" + "license": "MIT", + "devDependencies": { + "babel-core": "^6.26.0", + "babel-jest": "^22.1.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-polyfill": "^6.26.0", + "babel-preset-env": "^1.6.1", + "css-loader": "^0.28.9", + "extract-text-webpack-plugin": "next", + "jest": "^22.1.4", + "style-loader": "^0.20.1", + "webpack": "^4.0.0" + } } diff --git a/test/__snapshots__/webpack-integration.test.js.snap b/test/__snapshots__/webpack-integration.test.js.snap new file mode 100644 index 0000000..b3b3b51 --- /dev/null +++ b/test/__snapshots__/webpack-integration.test.js.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Webpack Integration Tests assetNameRegExp-no-source 1`] = `"body{color:red}a{color:blue}body{margin:0;color:red}p{margin:1000px}body{color:red;padding:0;margin:0}p{padding:500px;padding:1000px}"`; + +exports[`Webpack Integration Tests duplicate-css-exists-without-plugin 1`] = `"body{color:red}a{color:blue}body{color:red}p{color:green}"`; + +exports[`Webpack Integration Tests only-assetNameRegExp-processed 1`] = ` +"body { + color: red; + padding: 0; + margin: 0; +} +p { + padding: 500px; + padding: 1000px; +} +" +`; + +exports[`Webpack Integration Tests only-assetNameRegExp-processed 2`] = `"a{color:blue}body{margin:0;color:red}p{margin:1000px}"`; + +exports[`Webpack Integration Tests removes-duplicate-css 1`] = `"a{color:blue}body{color:red}p{color:green}"`; diff --git a/test/cases/assetNameRegExp-no-source/a_optimize-me.css b/test/cases/assetNameRegExp-no-source/a_optimize-me.css new file mode 100644 index 0000000..8e7ce09 --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/a_optimize-me.css @@ -0,0 +1,6 @@ +body { + color: red; +} +a { + color: blue; +} diff --git a/test/cases/assetNameRegExp-no-source/b_optimize-me.css b/test/cases/assetNameRegExp-no-source/b_optimize-me.css new file mode 100644 index 0000000..e2dbd7e --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/b_optimize-me.css @@ -0,0 +1,7 @@ +body { + margin: 0; + color: red; +} +p { + margin: 1000px; +} diff --git a/test/cases/assetNameRegExp-no-source/c.css b/test/cases/assetNameRegExp-no-source/c.css new file mode 100644 index 0000000..a26aba2 --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/c.css @@ -0,0 +1,9 @@ +body { + color: red; + padding: 0; + margin: 0; +} +p { + padding: 500px; + padding: 1000px; +} diff --git a/test/cases/assetNameRegExp-no-source/expected/file.css b/test/cases/assetNameRegExp-no-source/expected/file.css new file mode 100644 index 0000000..5d659bf --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/expected/file.css @@ -0,0 +1 @@ +body{color:red}a{color:blue}body{margin:0;color:red}p{margin:1000px}body{color:red;padding:0;margin:0}p{padding:500px;padding:1000px} \ No newline at end of file diff --git a/test/cases/assetNameRegExp-no-source/index.js b/test/cases/assetNameRegExp-no-source/index.js new file mode 100644 index 0000000..3d11b7f --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/index.js @@ -0,0 +1,10 @@ +/* + + This test is here to confirm that assetNameRegExp option will apply + only to the names of the files exported byt ExtractTextPlugin + +*/ + +require('./a_optimize-me.css'); +require('./b_optimize-me.css'); +require('./c.css'); diff --git a/test/cases/assetNameRegExp-no-source/webpack.config.js b/test/cases/assetNameRegExp-no-source/webpack.config.js new file mode 100644 index 0000000..69d62ed --- /dev/null +++ b/test/cases/assetNameRegExp-no-source/webpack.config.js @@ -0,0 +1,26 @@ +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import OptimizeCssAssetsPlugin from '../../../src/'; + +module.exports = { + entry: './index', + module: { + rules: [ + { + test: /\.css$/, + use: ExtractTextPlugin.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: true } + } + }) + }, + ], + }, + plugins: [ + new ExtractTextPlugin('file.css'), + new OptimizeCssAssetsPlugin({ + assetNameRegExp: /optimize-me\.css/g + }) + ], +}; diff --git a/test/cases/duplicate-css-exists-without-plugin/a.css b/test/cases/duplicate-css-exists-without-plugin/a.css new file mode 100644 index 0000000..8e7ce09 --- /dev/null +++ b/test/cases/duplicate-css-exists-without-plugin/a.css @@ -0,0 +1,6 @@ +body { + color: red; +} +a { + color: blue; +} diff --git a/test/cases/duplicate-css-exists-without-plugin/b.css b/test/cases/duplicate-css-exists-without-plugin/b.css new file mode 100644 index 0000000..a286d3e --- /dev/null +++ b/test/cases/duplicate-css-exists-without-plugin/b.css @@ -0,0 +1,6 @@ +body { + color: red; +} +p { + color: green; +} diff --git a/test/cases/duplicate-css-exists-without-plugin/expected/file.css b/test/cases/duplicate-css-exists-without-plugin/expected/file.css new file mode 100644 index 0000000..060a716 --- /dev/null +++ b/test/cases/duplicate-css-exists-without-plugin/expected/file.css @@ -0,0 +1 @@ +body{color:red}a{color:blue}body{color:red}p{color:green} \ No newline at end of file diff --git a/test/cases/duplicate-css-exists-without-plugin/index.js b/test/cases/duplicate-css-exists-without-plugin/index.js new file mode 100644 index 0000000..a2a7578 --- /dev/null +++ b/test/cases/duplicate-css-exists-without-plugin/index.js @@ -0,0 +1,2 @@ +require('./a.css'); +require('./b.css'); diff --git a/test/cases/duplicate-css-exists-without-plugin/webpack.config.js b/test/cases/duplicate-css-exists-without-plugin/webpack.config.js new file mode 100644 index 0000000..c1b29d4 --- /dev/null +++ b/test/cases/duplicate-css-exists-without-plugin/webpack.config.js @@ -0,0 +1,23 @@ +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import OptimizeCssAssetsPlugin from '../../../src/'; + +module.exports = { + entry: './index', + module: { + rules: [ + { + test: /\.css$/, + use: ExtractTextPlugin.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: true } + } + }) + }, + ], + }, + plugins: [ + new ExtractTextPlugin('file.css') + ], +}; diff --git a/test/cases/only-assetNameRegExp-processed/a_optimize-me.css b/test/cases/only-assetNameRegExp-processed/a_optimize-me.css new file mode 100644 index 0000000..8e7ce09 --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/a_optimize-me.css @@ -0,0 +1,6 @@ +body { + color: red; +} +a { + color: blue; +} diff --git a/test/cases/only-assetNameRegExp-processed/b_optimize-me.css b/test/cases/only-assetNameRegExp-processed/b_optimize-me.css new file mode 100644 index 0000000..e2dbd7e --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/b_optimize-me.css @@ -0,0 +1,7 @@ +body { + margin: 0; + color: red; +} +p { + margin: 1000px; +} diff --git a/test/cases/only-assetNameRegExp-processed/c_as-is.css b/test/cases/only-assetNameRegExp-processed/c_as-is.css new file mode 100644 index 0000000..a26aba2 --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/c_as-is.css @@ -0,0 +1,9 @@ +body { + color: red; + padding: 0; + margin: 0; +} +p { + padding: 500px; + padding: 1000px; +} diff --git a/test/cases/only-assetNameRegExp-processed/expected/as_is.css b/test/cases/only-assetNameRegExp-processed/expected/as_is.css new file mode 100644 index 0000000..a26aba2 --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/expected/as_is.css @@ -0,0 +1,9 @@ +body { + color: red; + padding: 0; + margin: 0; +} +p { + padding: 500px; + padding: 1000px; +} diff --git a/test/cases/only-assetNameRegExp-processed/expected/optimize.css b/test/cases/only-assetNameRegExp-processed/expected/optimize.css new file mode 100644 index 0000000..3f7a2e9 --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/expected/optimize.css @@ -0,0 +1 @@ +a{color:blue}body{margin:0;color:red}p{margin:1000px} \ No newline at end of file diff --git a/test/cases/only-assetNameRegExp-processed/index.js b/test/cases/only-assetNameRegExp-processed/index.js new file mode 100644 index 0000000..d889e4c --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/index.js @@ -0,0 +1,3 @@ +require('./a_optimize-me.css'); +require('./b_optimize-me.css'); +require('./c_as-is.css'); diff --git a/test/cases/only-assetNameRegExp-processed/webpack.config.js b/test/cases/only-assetNameRegExp-processed/webpack.config.js new file mode 100644 index 0000000..38701c3 --- /dev/null +++ b/test/cases/only-assetNameRegExp-processed/webpack.config.js @@ -0,0 +1,40 @@ +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import OptimizeCssAssetsPlugin from '../../../src/'; + +const notToProcess = new ExtractTextPlugin('as_is.css'); +const toProcess = new ExtractTextPlugin('optimize.css'); + +module.exports = { + entry: './index', + module: { + rules: [ + { + test: /as-is\.css$/, + use: notToProcess.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: false } + } + }) + }, + { + test: /optimize-me\.css$/, + use: toProcess.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: false } + } + }) + } + ], + }, + plugins: [ + notToProcess, + toProcess, + new OptimizeCssAssetsPlugin({ + assetNameRegExp: /optimize\.css/g + }) + ], +}; diff --git a/test/cases/removes-duplicate-css/a.css b/test/cases/removes-duplicate-css/a.css new file mode 100644 index 0000000..8e7ce09 --- /dev/null +++ b/test/cases/removes-duplicate-css/a.css @@ -0,0 +1,6 @@ +body { + color: red; +} +a { + color: blue; +} diff --git a/test/cases/removes-duplicate-css/b.css b/test/cases/removes-duplicate-css/b.css new file mode 100644 index 0000000..a286d3e --- /dev/null +++ b/test/cases/removes-duplicate-css/b.css @@ -0,0 +1,6 @@ +body { + color: red; +} +p { + color: green; +} diff --git a/test/cases/removes-duplicate-css/expected/file.css b/test/cases/removes-duplicate-css/expected/file.css new file mode 100644 index 0000000..9f0b4d5 --- /dev/null +++ b/test/cases/removes-duplicate-css/expected/file.css @@ -0,0 +1 @@ +a{color:blue}body{color:red}p{color:green} \ No newline at end of file diff --git a/test/cases/removes-duplicate-css/index.js b/test/cases/removes-duplicate-css/index.js new file mode 100644 index 0000000..a2a7578 --- /dev/null +++ b/test/cases/removes-duplicate-css/index.js @@ -0,0 +1,2 @@ +require('./a.css'); +require('./b.css'); diff --git a/test/cases/removes-duplicate-css/webpack.config.js b/test/cases/removes-duplicate-css/webpack.config.js new file mode 100644 index 0000000..bc01d74 --- /dev/null +++ b/test/cases/removes-duplicate-css/webpack.config.js @@ -0,0 +1,24 @@ +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import OptimizeCssAssetsPlugin from '../../../src/'; + +module.exports = { + entry: './index', + module: { + rules: [ + { + test: /\.css$/, + use: ExtractTextPlugin.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: true } + } + }) + }, + ], + }, + plugins: [ + new ExtractTextPlugin('file.css'), + new OptimizeCssAssetsPlugin() + ], +}; diff --git a/test/plugin.test.js b/test/plugin.test.js new file mode 100644 index 0000000..1284ba6 --- /dev/null +++ b/test/plugin.test.js @@ -0,0 +1,26 @@ +import OptimizeCssAssetsPlugin from '../src/'; + +describe('plugin test', () => { + it('does not throw when called', () => { + expect(() => { + new OptimizeCssAssetsPlugin(); + }).not.toThrow(); + }); + + it('can override default parameters', () => { + const assetNameRegExp = /\.optimize\.css$/ + const cssProcessor = {}; + const cssProcessorOptions = { discardComments: { removeAll: true } }; + const canPrint = false; + const plugin = new OptimizeCssAssetsPlugin({ + assetNameRegExp, + cssProcessor, + cssProcessorOptions, + canPrint + }); + expect(plugin.options.assetNameRegExp).toEqual(assetNameRegExp); + expect(plugin.options.cssProcessor).toEqual(cssProcessor); + expect(plugin.options.cssProcessorOptions).toEqual(cssProcessorOptions); + expect(plugin.options.canPrint).toEqual(canPrint); + }); +}); diff --git a/test/util/default.css b/test/util/default.css new file mode 100644 index 0000000..b1c34c2 --- /dev/null +++ b/test/util/default.css @@ -0,0 +1 @@ +html{display:none} \ No newline at end of file diff --git a/test/util/helpers.js b/test/util/helpers.js new file mode 100644 index 0000000..4dc5e74 --- /dev/null +++ b/test/util/helpers.js @@ -0,0 +1,40 @@ +import fs from 'fs'; +import path from 'path'; +import ExtractTextPlugin from 'extract-text-webpack-plugin'; + +export function readFileOrEmpty(path) { + try { + return fs.readFileSync(path, 'utf-8'); + } catch (e) { + return ''; + } +} + +export const defaultConfig = { + entry: './index', + module: { + rules: [ + { + test: /\.css$/, + use: ExtractTextPlugin.extract({ + fallback: { loader: 'style-loader' }, + use: { + loader: 'css-loader', + options: { minimize: true } + } + }) + }, + ], + }, + plugins: [], + context: __dirname, + output: { + filename: 'destination.js', + path: path.resolve(__dirname, '../', 'js', 'default-exports') + } +}; + +export function checkForWebpackErrors({err, stats, done}) { + if (err) return done(err); + if (stats.hasErrors()) return done(new Error(stats.toString())); +} diff --git a/test/util/index.js b/test/util/index.js new file mode 100644 index 0000000..060068b --- /dev/null +++ b/test/util/index.js @@ -0,0 +1 @@ +require('./default.css'); diff --git a/test/webpack-integration.test.js b/test/webpack-integration.test.js new file mode 100644 index 0000000..424a74c --- /dev/null +++ b/test/webpack-integration.test.js @@ -0,0 +1,82 @@ +/* eslint-disable import/no-dynamic-require, global-require */ +import fs from 'fs'; +import path from 'path'; +import webpack from 'webpack'; +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import OptimizeCssAssetsPlugin from '../src/'; +import { readFileOrEmpty, defaultConfig, checkForWebpackErrors } from './util/helpers'; + +const cases = process.env.CASES ? process.env.CASES.split(',') : fs.readdirSync(path.join(__dirname, 'cases')); + +describe('Webpack Integration Tests', () => { + cases.forEach((testCase) => { + if (/^_skip_/.test(testCase)) return; + it(testCase, (done) => { + const testDirectory = path.join(__dirname, 'cases', testCase); + const outputDirectory = path.join(__dirname, 'js', testCase); + const expectedDirectory = path.join(testDirectory, 'expected'); + + const configFile = path.join(testDirectory, 'webpack.config.js'); + const config = Object.assign( + fs.existsSync(configFile) ? require(configFile) : { entry: { test: './index.js' } }, + { + context: testDirectory, + output: { + filename: '[name].js', + path: outputDirectory + } + } + ); + + webpack(config, (err, stats) => { + checkForWebpackErrors({ err, stats, done }); + fs.readdirSync(expectedDirectory).forEach((file) => { + const expectedFile = readFileOrEmpty(path.join(expectedDirectory, file)); + const actualFile = readFileOrEmpty(path.join(outputDirectory, file)); + expect(actualFile).toEqual(expectedFile); + expect(actualFile).toMatchSnapshot(); + }); + done(); + }); + }); + }); + + it('calls cssProcessor with correct arguments', (done) => { + const destination = 'destination.css'; + const expectedCss = readFileOrEmpty(__dirname + '/util/default.css'); + const cssProcessorOptions = { discardComments: { removeAll: true } }; + const cssProcessor = { + process: (actualCss, options) => { + expect(options).toEqual(expect.objectContaining(cssProcessorOptions)); + expect(actualCss).toEqual(expectedCss); + return Promise.resolve({ css: actualCss }); + } + }; + const plugin = new OptimizeCssAssetsPlugin({ cssProcessor, cssProcessorOptions }); + const config = Object.assign(defaultConfig, {plugins: [plugin, new ExtractTextPlugin(destination)]}); + + webpack(config, (err, stats) => { + checkForWebpackErrors({ err, stats, done }); + done(); + }); + }); + + it('writes processed css to destination', (done) => { + const destination = 'destination.css'; + const expectedCss = '.inifinity-pool{overflow:hidden;}'; + const fakeCssProcessor = { + process: jest.fn().mockReturnValue(Promise.resolve({ css: expectedCss })) + }; + const plugin = new OptimizeCssAssetsPlugin({ cssProcessor: fakeCssProcessor }); + const config = Object.assign(defaultConfig, {plugins: [plugin, new ExtractTextPlugin(destination)]}); + + webpack(config, (err, stats) => { + checkForWebpackErrors({ err, stats, done }); + const actualCss = readFileOrEmpty(__dirname + '/js/default-exports/destination.css'); + + expect(fakeCssProcessor.process).toHaveBeenCalled(); + expect(actualCss).toEqual(expectedCss); + done(); + }); + }); +});