diff --git a/.babelrc b/.babelrc index 13e9085..0e27ec7 100644 --- a/.babelrc +++ b/.babelrc @@ -1,11 +1,12 @@ { "presets": [ [ "@babel/preset-env", { + "corejs": 3, "targets": { - "node": "8" + "node": "8.0.0" }, "loose": true, - "useBuiltIns": "entry" + "useBuiltIns": "usage" } ] ] } diff --git a/.gitignore b/.gitignore index df633a9..78aa933 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ yarn.lock .eslintcache lib/**.js -test/_out +test/**/_out diff --git a/.travis.yml b/.travis.yml index e8291bf..a53586b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ node_js: - "13" - "node" +before_script: npm run test-prepare script: npm test branches: diff --git a/package.json b/package.json index f9263e0..4fc8d9d 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ }, "scripts": { "lint": "eslint --cache .", - "test": "npm run build && mocha", + "test": "npm run build && mocha \"./test/*/*.spec.js\"", + "test-prepare": "cd test/webpack2 && npm install && cd ../webpack4 && npm install && cd ../webpack5 && npm install", "build": "babel src --out-dir lib", "prepublish": "npm run build" }, @@ -55,14 +56,12 @@ "@babel/core": "^7.7.5", "@babel/preset-env": "^7.7.6", "babel-eslint": "^10.0.0", - "css-loader": "^0.28.5", + "core-js": "^3.10.0", "eslint": "^6.7.2", "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.7.0", - "extract-text-webpack-plugin": "^2.1.0", "mocha": "^6.2.2", "pre-commit": "^1.2.2", - "rimraf": "^3.0.0", - "webpack": "^2.3.3" + "rimraf": "^3.0.0" } } diff --git a/test/integrations/source-map-with-import/a.css b/test/integrations/source-map-with-import/a.css deleted file mode 100644 index 1560ef2..0000000 --- a/test/integrations/source-map-with-import/a.css +++ /dev/null @@ -1,2 +0,0 @@ -@import url('./import.css'); -.a { color: white; } diff --git a/test/integrations.js b/test/lib/integrations.js similarity index 72% rename from test/integrations.js rename to test/lib/integrations.js index 3942cbd..092e067 100644 --- a/test/integrations.js +++ b/test/lib/integrations.js @@ -2,19 +2,36 @@ const fs = require('fs'); const join = require('path').join; const rimraf = require('rimraf'); const assert = require('assert'); -const webpack = require('webpack'); -const getWebpackConfig = require('./webpack.config.js'); const root = join(__dirname, 'integrations'); -const output = join(__dirname, '_out'); -describe('Integrations with webpack 2', function() { +function runIntegrations(basePath, version) { this.timeout(5000); - const cases = fs.readdirSync(root); + const output = join(basePath, '_out'); rimraf.sync(output); + const nodeVersions = process.version.split('.'); + const nodeMajorVersion = parseInt(nodeVersions[0].substring(1), 10); + const nodeMinorVersion = parseInt(nodeVersions[1], 10); + + const isEnvCorrect = !( + (version === '4' && nodeMajorVersion === 8 && nodeMinorVersion === 0) || + (version === '5' && nodeMajorVersion < 10) + ); + + if (!isEnvCorrect) { + it('webpack ' + version + ' unsuppported with node ' + process.version, function() { + assert.ok(true); + }); + return; + } + + const cases = fs.readdirSync(root); + const webpack = require(join(basePath, 'node_modules', 'webpack')); + const getWebpackConfig = require(join(basePath, 'webpack.config.js')); + cases.forEach(function(testCase) { it('with ' + testCase + ' test', function() { return new Promise(function(resolve, reject) { @@ -23,6 +40,7 @@ describe('Integrations with webpack 2', function() { const configFile = join(testDirectory, 'webpack.config.js'); var options = getWebpackConfig({ + basePath: basePath, outputDirectory: outputDirectory, testDirectory: testDirectory }); @@ -39,7 +57,7 @@ describe('Integrations with webpack 2', function() { if (err) return reject(err); if (stats.hasErrors()) return reject(new Error(stats.toString())); - const expectedCssExt = 'expected.css'; + const expectedCssExt = 'expected-v' + version + '.css'; fs.readdir(testDirectory, function(err, files) { if (err) return reject(err); @@ -59,7 +77,7 @@ describe('Integrations with webpack 2', function() { .replace(/\n$/g, '') .replace(/%%unit-hash%%/g, stats.hash); - assert.equal(actual, expected, + assert.strictEqual(actual, expected, 'Output ' + testCase + ' — ' + name + ' file isn\'t equals ' + actualName ); }); @@ -70,4 +88,6 @@ describe('Integrations with webpack 2', function() { }); }); }); -}); +} + +module.exports = runIntegrations; diff --git a/test/integrations/css-modules/expected.css b/test/lib/integrations/css-modules/expected-v2.css similarity index 100% rename from test/integrations/css-modules/expected.css rename to test/lib/integrations/css-modules/expected-v2.css diff --git a/test/integrations/plugin-output-postfix/min.expected.css b/test/lib/integrations/css-modules/expected-v4.css similarity index 100% rename from test/integrations/plugin-output-postfix/min.expected.css rename to test/lib/integrations/css-modules/expected-v4.css diff --git a/test/lib/integrations/css-modules/expected-v5.css b/test/lib/integrations/css-modules/expected-v5.css new file mode 100644 index 0000000..becbb57 --- /dev/null +++ b/test/lib/integrations/css-modules/expected-v5.css @@ -0,0 +1 @@ +.c .d,.local-a.c .d,.local-c .local-d{color:#fff} diff --git a/test/integrations/css-modules/index.css b/test/lib/integrations/css-modules/index.css similarity index 100% rename from test/integrations/css-modules/index.css rename to test/lib/integrations/css-modules/index.css diff --git a/test/integrations/css-modules/index.js b/test/lib/integrations/css-modules/index.js similarity index 100% rename from test/integrations/css-modules/index.js rename to test/lib/integrations/css-modules/index.js diff --git a/test/integrations/simple/webpack.config.js b/test/lib/integrations/css-modules/webpack.config.js similarity index 53% rename from test/integrations/simple/webpack.config.js rename to test/lib/integrations/css-modules/webpack.config.js index 860c86b..18d15a7 100644 --- a/test/integrations/simple/webpack.config.js +++ b/test/lib/integrations/css-modules/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { plugins: [ diff --git a/test/integrations/plugin-output-postfix/expected.css b/test/lib/integrations/plugin-output-postfix/expected-v2.css similarity index 100% rename from test/integrations/plugin-output-postfix/expected.css rename to test/lib/integrations/plugin-output-postfix/expected-v2.css diff --git a/test/lib/integrations/plugin-output-postfix/expected-v4.css b/test/lib/integrations/plugin-output-postfix/expected-v4.css new file mode 100644 index 0000000..60577c6 --- /dev/null +++ b/test/lib/integrations/plugin-output-postfix/expected-v4.css @@ -0,0 +1,4 @@ +.local-a.c .d { color: #fff; } +.c .d { color: white; } +.local-c .local-d { color: #ffffff; } + diff --git a/test/lib/integrations/plugin-output-postfix/expected-v5.css b/test/lib/integrations/plugin-output-postfix/expected-v5.css new file mode 100644 index 0000000..60577c6 --- /dev/null +++ b/test/lib/integrations/plugin-output-postfix/expected-v5.css @@ -0,0 +1,4 @@ +.local-a.c .d { color: #fff; } +.c .d { color: white; } +.local-c .local-d { color: #ffffff; } + diff --git a/test/integrations/plugin-output-postfix/index.css b/test/lib/integrations/plugin-output-postfix/index.css similarity index 100% rename from test/integrations/plugin-output-postfix/index.css rename to test/lib/integrations/plugin-output-postfix/index.css diff --git a/test/integrations/plugin-output-postfix/index.js b/test/lib/integrations/plugin-output-postfix/index.js similarity index 100% rename from test/integrations/plugin-output-postfix/index.js rename to test/lib/integrations/plugin-output-postfix/index.js diff --git a/test/lib/integrations/plugin-output-postfix/min.expected.css b/test/lib/integrations/plugin-output-postfix/min.expected.css new file mode 100644 index 0000000..becbb57 --- /dev/null +++ b/test/lib/integrations/plugin-output-postfix/min.expected.css @@ -0,0 +1 @@ +.c .d,.local-a.c .d,.local-c .local-d{color:#fff} diff --git a/test/integrations/plugin-output-postfix/webpack.config.js b/test/lib/integrations/plugin-output-postfix/webpack.config.js similarity index 65% rename from test/integrations/plugin-output-postfix/webpack.config.js rename to test/lib/integrations/plugin-output-postfix/webpack.config.js index cd1c7f6..584b1c4 100644 --- a/test/integrations/plugin-output-postfix/webpack.config.js +++ b/test/lib/integrations/plugin-output-postfix/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { plugins: [ diff --git a/test/integrations/simple/a.css b/test/lib/integrations/simple/a.css similarity index 100% rename from test/integrations/simple/a.css rename to test/lib/integrations/simple/a.css diff --git a/test/integrations/simple/b.css b/test/lib/integrations/simple/b.css similarity index 100% rename from test/integrations/simple/b.css rename to test/lib/integrations/simple/b.css diff --git a/test/integrations/simple/c.css b/test/lib/integrations/simple/c.css similarity index 100% rename from test/integrations/simple/c.css rename to test/lib/integrations/simple/c.css diff --git a/test/integrations/simple/expected.css b/test/lib/integrations/simple/expected-v2.css similarity index 100% rename from test/integrations/simple/expected.css rename to test/lib/integrations/simple/expected-v2.css diff --git a/test/integrations/source-map-false/expected.css b/test/lib/integrations/simple/expected-v4.css similarity index 100% rename from test/integrations/source-map-false/expected.css rename to test/lib/integrations/simple/expected-v4.css diff --git a/test/lib/integrations/simple/expected-v5.css b/test/lib/integrations/simple/expected-v5.css new file mode 100644 index 0000000..b9ed130 --- /dev/null +++ b/test/lib/integrations/simple/expected-v5.css @@ -0,0 +1 @@ +.local-a,.local-b,.local-c{color:#fff} diff --git a/test/integrations/simple/index.js b/test/lib/integrations/simple/index.js similarity index 100% rename from test/integrations/simple/index.js rename to test/lib/integrations/simple/index.js diff --git a/test/integrations/css-modules/webpack.config.js b/test/lib/integrations/simple/webpack.config.js similarity index 53% rename from test/integrations/css-modules/webpack.config.js rename to test/lib/integrations/simple/webpack.config.js index 860c86b..18d15a7 100644 --- a/test/integrations/css-modules/webpack.config.js +++ b/test/lib/integrations/simple/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { plugins: [ diff --git a/test/integrations/source-map-false/a.css b/test/lib/integrations/source-map-false/a.css similarity index 100% rename from test/integrations/source-map-false/a.css rename to test/lib/integrations/source-map-false/a.css diff --git a/test/integrations/source-map-false/b.css b/test/lib/integrations/source-map-false/b.css similarity index 100% rename from test/integrations/source-map-false/b.css rename to test/lib/integrations/source-map-false/b.css diff --git a/test/integrations/source-map-false/c.css b/test/lib/integrations/source-map-false/c.css similarity index 100% rename from test/integrations/source-map-false/c.css rename to test/lib/integrations/source-map-false/c.css diff --git a/test/lib/integrations/source-map-false/expected-v2.css b/test/lib/integrations/source-map-false/expected-v2.css new file mode 100644 index 0000000..b9ed130 --- /dev/null +++ b/test/lib/integrations/source-map-false/expected-v2.css @@ -0,0 +1 @@ +.local-a,.local-b,.local-c{color:#fff} diff --git a/test/lib/integrations/source-map-false/expected-v4.css b/test/lib/integrations/source-map-false/expected-v4.css new file mode 100644 index 0000000..b9ed130 --- /dev/null +++ b/test/lib/integrations/source-map-false/expected-v4.css @@ -0,0 +1 @@ +.local-a,.local-b,.local-c{color:#fff} diff --git a/test/lib/integrations/source-map-false/expected-v5.css b/test/lib/integrations/source-map-false/expected-v5.css new file mode 100644 index 0000000..b9ed130 --- /dev/null +++ b/test/lib/integrations/source-map-false/expected-v5.css @@ -0,0 +1 @@ +.local-a,.local-b,.local-c{color:#fff} diff --git a/test/integrations/source-map-false/index.js b/test/lib/integrations/source-map-false/index.js similarity index 100% rename from test/integrations/source-map-false/index.js rename to test/lib/integrations/source-map-false/index.js diff --git a/test/integrations/source-map-false/webpack.config.js b/test/lib/integrations/source-map-false/webpack.config.js similarity index 58% rename from test/integrations/source-map-false/webpack.config.js rename to test/lib/integrations/source-map-false/webpack.config.js index efb0894..3586685 100644 --- a/test/integrations/source-map-false/webpack.config.js +++ b/test/lib/integrations/source-map-false/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: false, diff --git a/test/integrations/source-map-filename/expected.css b/test/lib/integrations/source-map-filename/expected-v2.css similarity index 100% rename from test/integrations/source-map-filename/expected.css rename to test/lib/integrations/source-map-filename/expected-v2.css diff --git a/test/lib/integrations/source-map-filename/expected-v4.css b/test/lib/integrations/source-map-filename/expected-v4.css new file mode 100644 index 0000000..5055a3d --- /dev/null +++ b/test/lib/integrations/source-map-filename/expected-v4.css @@ -0,0 +1,2 @@ +.local-a.c .d{color:#fff} +/*# sourceMappingURL=prefix-test.css-0-%%unit-hash%%.map*/ diff --git a/test/lib/integrations/source-map-filename/expected-v5.css b/test/lib/integrations/source-map-filename/expected-v5.css new file mode 100644 index 0000000..5055a3d --- /dev/null +++ b/test/lib/integrations/source-map-filename/expected-v5.css @@ -0,0 +1,2 @@ +.local-a.c .d{color:#fff} +/*# sourceMappingURL=prefix-test.css-0-%%unit-hash%%.map*/ diff --git a/test/integrations/source-map-filename/index.css b/test/lib/integrations/source-map-filename/index.css similarity index 100% rename from test/integrations/source-map-filename/index.css rename to test/lib/integrations/source-map-filename/index.css diff --git a/test/integrations/source-map-filename/index.js b/test/lib/integrations/source-map-filename/index.js similarity index 100% rename from test/integrations/source-map-filename/index.js rename to test/lib/integrations/source-map-filename/index.js diff --git a/test/integrations/source-map-filename/webpack.config.js b/test/lib/integrations/source-map-filename/webpack.config.js similarity index 73% rename from test/integrations/source-map-filename/webpack.config.js rename to test/lib/integrations/source-map-filename/webpack.config.js index 7be7184..6711bfc 100644 --- a/test/integrations/source-map-filename/webpack.config.js +++ b/test/lib/integrations/source-map-filename/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: 'source-map', diff --git a/test/integrations/source-map-hidden/expected.css b/test/lib/integrations/source-map-hidden/expected-v2.css similarity index 100% rename from test/integrations/source-map-hidden/expected.css rename to test/lib/integrations/source-map-hidden/expected-v2.css diff --git a/test/lib/integrations/source-map-hidden/expected-v4.css b/test/lib/integrations/source-map-hidden/expected-v4.css new file mode 100644 index 0000000..6654547 --- /dev/null +++ b/test/lib/integrations/source-map-hidden/expected-v4.css @@ -0,0 +1 @@ +.local-a.c .d{color:#fff} diff --git a/test/lib/integrations/source-map-hidden/expected-v5.css b/test/lib/integrations/source-map-hidden/expected-v5.css new file mode 100644 index 0000000..6654547 --- /dev/null +++ b/test/lib/integrations/source-map-hidden/expected-v5.css @@ -0,0 +1 @@ +.local-a.c .d{color:#fff} diff --git a/test/integrations/source-map-hidden/index.css b/test/lib/integrations/source-map-hidden/index.css similarity index 100% rename from test/integrations/source-map-hidden/index.css rename to test/lib/integrations/source-map-hidden/index.css diff --git a/test/integrations/source-map-hidden/index.js b/test/lib/integrations/source-map-hidden/index.js similarity index 100% rename from test/integrations/source-map-hidden/index.js rename to test/lib/integrations/source-map-hidden/index.js diff --git a/test/integrations/source-map-hidden/webpack.config.js b/test/lib/integrations/source-map-hidden/webpack.config.js similarity index 62% rename from test/integrations/source-map-hidden/webpack.config.js rename to test/lib/integrations/source-map-hidden/webpack.config.js index 63c33de..640e0ab 100644 --- a/test/integrations/source-map-hidden/webpack.config.js +++ b/test/lib/integrations/source-map-hidden/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: 'hidden-source-map', diff --git a/test/integrations/source-map-inline/expected.css b/test/lib/integrations/source-map-inline/expected-v2.css similarity index 100% rename from test/integrations/source-map-inline/expected.css rename to test/lib/integrations/source-map-inline/expected-v2.css diff --git a/test/lib/integrations/source-map-inline/expected-v4.css b/test/lib/integrations/source-map-inline/expected-v4.css new file mode 100644 index 0000000..982b4d7 --- /dev/null +++ b/test/lib/integrations/source-map-inline/expected-v4.css @@ -0,0 +1,2 @@ +.local-a.c .d{color:#fff} +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbmRleC5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsYSxDQUFtQixVIiwiZmlsZSI6InRlc3QuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiLmE6Z2xvYmFsKC5jIC5kKSB7IGNvbG9yOiAjZmZmOyB9XG4iXSwic291cmNlUm9vdCI6IiJ9*/ diff --git a/test/lib/integrations/source-map-inline/expected-v5.css b/test/lib/integrations/source-map-inline/expected-v5.css new file mode 100644 index 0000000..982b4d7 --- /dev/null +++ b/test/lib/integrations/source-map-inline/expected-v5.css @@ -0,0 +1,2 @@ +.local-a.c .d{color:#fff} +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbmRleC5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsYSxDQUFtQixVIiwiZmlsZSI6InRlc3QuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiLmE6Z2xvYmFsKC5jIC5kKSB7IGNvbG9yOiAjZmZmOyB9XG4iXSwic291cmNlUm9vdCI6IiJ9*/ diff --git a/test/integrations/source-map-inline/index.css b/test/lib/integrations/source-map-inline/index.css similarity index 100% rename from test/integrations/source-map-inline/index.css rename to test/lib/integrations/source-map-inline/index.css diff --git a/test/integrations/source-map-inline/index.js b/test/lib/integrations/source-map-inline/index.js similarity index 100% rename from test/integrations/source-map-inline/index.js rename to test/lib/integrations/source-map-inline/index.js diff --git a/test/integrations/source-map-inline/webpack.config.js b/test/lib/integrations/source-map-inline/webpack.config.js similarity index 62% rename from test/integrations/source-map-inline/webpack.config.js rename to test/lib/integrations/source-map-inline/webpack.config.js index 296ec52..3b3bb63 100644 --- a/test/integrations/source-map-inline/webpack.config.js +++ b/test/lib/integrations/source-map-inline/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: 'inline-source-map', diff --git a/test/lib/integrations/source-map-with-import/a.css b/test/lib/integrations/source-map-with-import/a.css new file mode 100644 index 0000000..6942bf0 --- /dev/null +++ b/test/lib/integrations/source-map-with-import/a.css @@ -0,0 +1,2 @@ +@import url('import.css'); +.a { color: white; } diff --git a/test/integrations/source-map-with-import/b.css b/test/lib/integrations/source-map-with-import/b.css similarity index 100% rename from test/integrations/source-map-with-import/b.css rename to test/lib/integrations/source-map-with-import/b.css diff --git a/test/integrations/source-map-with-import/c.css b/test/lib/integrations/source-map-with-import/c.css similarity index 100% rename from test/integrations/source-map-with-import/c.css rename to test/lib/integrations/source-map-with-import/c.css diff --git a/test/integrations/source-map-with-import/expected.css b/test/lib/integrations/source-map-with-import/expected-v2.css similarity index 63% rename from test/integrations/source-map-with-import/expected.css rename to test/lib/integrations/source-map-with-import/expected-v2.css index 31585df..86656ca 100644 --- a/test/integrations/source-map-with-import/expected.css +++ b/test/lib/integrations/source-map-with-import/expected-v2.css @@ -1,2 +1,2 @@ .local-import-align{text-align:center}.local-a,.local-b,.local-c,.local-import-color{color:#fff} -/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbXBvcnQuY3NzIiwid2VicGFjazovLy8uL2EuY3NzIiwid2VicGFjazovLy8uL2IuY3NzIiwid2VicGFjazovLy8uL2MuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG1CLENBQ0ksaUIsQ0NBSixRLENDREEsUSxDQ0FBLFEsQ0hJQSxtQixDQUNJLFUiLCJmaWxlIjoidGVzdC5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuaW1wb3J0LWFsaWduIHtcbiAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG59XG5cbi5pbXBvcnQtY29sb3Ige1xuICAgIGNvbG9yOiAjZmZmO1xufVxuXG5cblxuLy8gV0VCUEFDSyBGT09URVIgLy9cbi8vIC4vaW1wb3J0LmNzcyIsIkBpbXBvcnQgdXJsKCcuL2ltcG9ydC5jc3MnKTtcbi5hIHsgY29sb3I6IHdoaXRlOyB9XG5cblxuXG4vLyBXRUJQQUNLIEZPT1RFUiAvL1xuLy8gLi9hLmNzcyIsIi5iIHsgY29sb3I6ICNmZmY7IH1cblxuXG4vLyBXRUJQQUNLIEZPT1RFUiAvL1xuLy8gLi9iLmNzcyIsIi5jIHsgY29sb3I6ICNmZmZmZmY7IH1cblxuXG4vLyBXRUJQQUNLIEZPT1RFUiAvL1xuLy8gLi9jLmNzcyJdLCJzb3VyY2VSb290IjoiIn0=*/ +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbXBvcnQuY3NzIiwid2VicGFjazovLy8uL2EuY3NzIiwid2VicGFjazovLy8uL2IuY3NzIiwid2VicGFjazovLy8uL2MuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG1CLENBQ0ksaUIsQ0NBSixRLENDREEsUSxDQ0FBLFEsQ0hJQSxtQixDQUNJLFUiLCJmaWxlIjoidGVzdC5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuaW1wb3J0LWFsaWduIHtcbiAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG59XG5cbi5pbXBvcnQtY29sb3Ige1xuICAgIGNvbG9yOiAjZmZmO1xufVxuXG5cblxuLy8gV0VCUEFDSyBGT09URVIgLy9cbi8vIC4vaW1wb3J0LmNzcyIsIkBpbXBvcnQgdXJsKCdpbXBvcnQuY3NzJyk7XG4uYSB7IGNvbG9yOiB3aGl0ZTsgfVxuXG5cblxuLy8gV0VCUEFDSyBGT09URVIgLy9cbi8vIC4vYS5jc3MiLCIuYiB7IGNvbG9yOiAjZmZmOyB9XG5cblxuLy8gV0VCUEFDSyBGT09URVIgLy9cbi8vIC4vYi5jc3MiLCIuYyB7IGNvbG9yOiAjZmZmZmZmOyB9XG5cblxuLy8gV0VCUEFDSyBGT09URVIgLy9cbi8vIC4vYy5jc3MiXSwic291cmNlUm9vdCI6IiJ9*/ diff --git a/test/lib/integrations/source-map-with-import/expected-v4.css b/test/lib/integrations/source-map-with-import/expected-v4.css new file mode 100644 index 0000000..a1ef9b5 --- /dev/null +++ b/test/lib/integrations/source-map-with-import/expected-v4.css @@ -0,0 +1,2 @@ +.local-import-align{text-align:center}.local-a,.local-b,.local-c,.local-import-color{color:#fff} +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbXBvcnQuY3NzIiwid2VicGFjazovLy8uL2EuY3NzIiwid2VicGFjazovLy8uL2IuY3NzIiwid2VicGFjazovLy8uL2MuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG1CLENBQ0ksaUIsQ0NBSixRLENDREEsUSxDQ0FBLFEsQ0hJQSxtQixDQUNJLFUiLCJmaWxlIjoidGVzdC5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuaW1wb3J0LWFsaWduIHtcbiAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG59XG5cbi5pbXBvcnQtY29sb3Ige1xuICAgIGNvbG9yOiAjZmZmO1xufVxuIiwiQGltcG9ydCB1cmwoJ2ltcG9ydC5jc3MnKTtcbi5hIHsgY29sb3I6IHdoaXRlOyB9XG4iLCIuYiB7IGNvbG9yOiAjZmZmOyB9IiwiLmMgeyBjb2xvcjogI2ZmZmZmZjsgfSJdLCJzb3VyY2VSb290IjoiIn0=*/ diff --git a/test/lib/integrations/source-map-with-import/expected-v5.css b/test/lib/integrations/source-map-with-import/expected-v5.css new file mode 100644 index 0000000..a1ef9b5 --- /dev/null +++ b/test/lib/integrations/source-map-with-import/expected-v5.css @@ -0,0 +1,2 @@ +.local-import-align{text-align:center}.local-a,.local-b,.local-c,.local-import-color{color:#fff} +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9pbXBvcnQuY3NzIiwid2VicGFjazovLy8uL2EuY3NzIiwid2VicGFjazovLy8uL2IuY3NzIiwid2VicGFjazovLy8uL2MuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG1CLENBQ0ksaUIsQ0NBSixRLENDREEsUSxDQ0FBLFEsQ0hJQSxtQixDQUNJLFUiLCJmaWxlIjoidGVzdC5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuaW1wb3J0LWFsaWduIHtcbiAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG59XG5cbi5pbXBvcnQtY29sb3Ige1xuICAgIGNvbG9yOiAjZmZmO1xufVxuIiwiQGltcG9ydCB1cmwoJ2ltcG9ydC5jc3MnKTtcbi5hIHsgY29sb3I6IHdoaXRlOyB9XG4iLCIuYiB7IGNvbG9yOiAjZmZmOyB9IiwiLmMgeyBjb2xvcjogI2ZmZmZmZjsgfSJdLCJzb3VyY2VSb290IjoiIn0=*/ diff --git a/test/integrations/source-map-with-import/import.css b/test/lib/integrations/source-map-with-import/import.css similarity index 100% rename from test/integrations/source-map-with-import/import.css rename to test/lib/integrations/source-map-with-import/import.css diff --git a/test/integrations/source-map-with-import/index.js b/test/lib/integrations/source-map-with-import/index.js similarity index 100% rename from test/integrations/source-map-with-import/index.js rename to test/lib/integrations/source-map-with-import/index.js diff --git a/test/integrations/source-map-with-import/webpack.config.js b/test/lib/integrations/source-map-with-import/webpack.config.js similarity index 62% rename from test/integrations/source-map-with-import/webpack.config.js rename to test/lib/integrations/source-map-with-import/webpack.config.js index 296ec52..3b3bb63 100644 --- a/test/integrations/source-map-with-import/webpack.config.js +++ b/test/lib/integrations/source-map-with-import/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: 'inline-source-map', diff --git a/test/integrations/source-map/a.css b/test/lib/integrations/source-map/a.css similarity index 100% rename from test/integrations/source-map/a.css rename to test/lib/integrations/source-map/a.css diff --git a/test/integrations/source-map/b.css b/test/lib/integrations/source-map/b.css similarity index 100% rename from test/integrations/source-map/b.css rename to test/lib/integrations/source-map/b.css diff --git a/test/integrations/source-map/c.css b/test/lib/integrations/source-map/c.css similarity index 100% rename from test/integrations/source-map/c.css rename to test/lib/integrations/source-map/c.css diff --git a/test/integrations/source-map/expected.css b/test/lib/integrations/source-map/expected-v2.css similarity index 100% rename from test/integrations/source-map/expected.css rename to test/lib/integrations/source-map/expected-v2.css diff --git a/test/lib/integrations/source-map/expected-v4.css b/test/lib/integrations/source-map/expected-v4.css new file mode 100644 index 0000000..40331e3 --- /dev/null +++ b/test/lib/integrations/source-map/expected-v4.css @@ -0,0 +1,2 @@ +.local-a,.local-b,.local-c{color:#fff} +/*# sourceMappingURL=test.css.map*/ diff --git a/test/lib/integrations/source-map/expected-v5.css b/test/lib/integrations/source-map/expected-v5.css new file mode 100644 index 0000000..40331e3 --- /dev/null +++ b/test/lib/integrations/source-map/expected-v5.css @@ -0,0 +1,2 @@ +.local-a,.local-b,.local-c{color:#fff} +/*# sourceMappingURL=test.css.map*/ diff --git a/test/integrations/source-map/index.js b/test/lib/integrations/source-map/index.js similarity index 100% rename from test/integrations/source-map/index.js rename to test/lib/integrations/source-map/index.js diff --git a/test/integrations/source-map/webpack.config.js b/test/lib/integrations/source-map/webpack.config.js similarity index 60% rename from test/integrations/source-map/webpack.config.js rename to test/lib/integrations/source-map/webpack.config.js index 0e8ff99..1abc03d 100644 --- a/test/integrations/source-map/webpack.config.js +++ b/test/lib/integrations/source-map/webpack.config.js @@ -1,4 +1,4 @@ -const CssoWebpackPlugin = require('../../../lib').default; +const CssoWebpackPlugin = require('../../../../lib/index').default; module.exports = { devtool: 'source-map', diff --git a/test/filter.js b/test/unit/filter.spec.js similarity index 58% rename from test/filter.js rename to test/unit/filter.spec.js index 45eacef..0fb81d9 100644 --- a/test/filter.js +++ b/test/unit/filter.spec.js @@ -1,15 +1,15 @@ const assert = require('assert'); -const CssoWebpackPlugin = require('../lib').default; +const CssoWebpackPlugin = require('../../lib/index').default; describe('Constructor', function() { function testDefaultOptions(plugin) { - assert.deepEqual(plugin.options, {}, 'default options inited'); + assert.deepStrictEqual(plugin.options, {}, 'default options inited'); } function testDefaultFilter(plugin) { - assert.equal(plugin.filter('files.css'), true, 'files.css should be true'); - assert.equal(plugin.filter('files.js'), false, 'files.js should be false'); - assert.equal(plugin.filter('/.css/file'), false, '/.css/file should be false'); + assert.strictEqual(plugin.filter('files.css'), true, 'files.css should be true'); + assert.strictEqual(plugin.filter('files.js'), false, 'files.js should be false'); + assert.strictEqual(plugin.filter('/.css/file'), false, '/.css/file should be false'); } it('default', function() { @@ -21,8 +21,8 @@ describe('Constructor', function() { it('with options', function() { const options = { test: 1 }; const plugin = new CssoWebpackPlugin(options); - assert.deepEqual(plugin.options, { test: 1 }, 'single argument with options'); - assert.deepEqual(options, { test: 1 }, 'single argument with options immutable'); + assert.deepStrictEqual(plugin.options, { test: 1 }, 'single argument with options'); + assert.deepStrictEqual(options, { test: 1 }, 'single argument with options immutable'); testDefaultFilter(plugin); }); @@ -30,9 +30,9 @@ describe('Constructor', function() { const plugin = new CssoWebpackPlugin(/^text/gi); testDefaultOptions(plugin); - assert.equal(plugin.filter('text-file.pcss'), true, 'text-file.pcss should be true'); - assert.equal(plugin.filter('files.js'), false, 'files.js should be false'); - assert.equal(plugin.filter('/.css/text'), false, '/.css/text should be false'); + assert.strictEqual(plugin.filter('text-file.pcss'), true, 'text-file.pcss should be true'); + assert.strictEqual(plugin.filter('files.js'), false, 'files.js should be false'); + assert.strictEqual(plugin.filter('/.css/text'), false, '/.css/text should be false'); assert.doesNotThrow( function() { new CssoWebpackPlugin({}, /^text/gi); }, @@ -45,10 +45,10 @@ describe('Constructor', function() { const oneArgPlugin = new CssoWebpackPlugin(filter); testDefaultOptions(oneArgPlugin); - assert.equal(oneArgPlugin.filter, filter, 'single `filter` should be set to this.filter'); + assert.strictEqual(oneArgPlugin.filter, filter, 'single `filter` should be set to this.filter'); const twoArgPlugin = new CssoWebpackPlugin({}, filter); - assert.equal(twoArgPlugin.filter, filter, 'second argument `filter` should be set to this.filter'); + assert.strictEqual(twoArgPlugin.filter, filter, 'second argument `filter` should be set to this.filter'); }); it('unexpected type for filter', function() { diff --git a/test/webpack2/integrations.spec.js b/test/webpack2/integrations.spec.js new file mode 100644 index 0000000..65f5a31 --- /dev/null +++ b/test/webpack2/integrations.spec.js @@ -0,0 +1,5 @@ +const runIntegrations = require('../lib/integrations.js'); + +describe('Integrations with webpack 2', function() { + runIntegrations.call(this, __dirname, '2'); +}); diff --git a/test/webpack2/package.json b/test/webpack2/package.json new file mode 100644 index 0000000..bd03124 --- /dev/null +++ b/test/webpack2/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "css-loader": "^0.28.11", + "extract-text-webpack-plugin": "^2.1.0", + "webpack": "^2.7.0" + } +} diff --git a/test/webpack.config.js b/test/webpack2/webpack.config.js similarity index 82% rename from test/webpack.config.js rename to test/webpack2/webpack.config.js index c67519c..2b094f8 100644 --- a/test/webpack.config.js +++ b/test/webpack2/webpack.config.js @@ -1,5 +1,5 @@ -const DefinePlugin = require('webpack').DefinePlugin; -const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const DefinePlugin = require('./node_modules/webpack').DefinePlugin; +const ExtractTextPlugin = require('./node_modules/extract-text-webpack-plugin'); const styleExtractPlugin = new ExtractTextPlugin({ filename: '[name].css', @@ -24,7 +24,7 @@ module.exports = function (options) { test: /\.css$/, use: ExtractTextPlugin.extract({ use: { - loader: 'css-loader', + loader: options.basePath + '/node_modules/css-loader', options: { modules: true, localIdentName: 'local-[local]', diff --git a/test/webpack4/integrations.spec.js b/test/webpack4/integrations.spec.js new file mode 100644 index 0000000..d97de0c --- /dev/null +++ b/test/webpack4/integrations.spec.js @@ -0,0 +1,5 @@ +const runIntegrations = require('../lib/integrations.js'); + +describe('Integrations with webpack 4', function() { + runIntegrations.call(this, __dirname, '4'); +}); diff --git a/test/webpack4/package.json b/test/webpack4/package.json new file mode 100644 index 0000000..1f692dc --- /dev/null +++ b/test/webpack4/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "css-loader": "^5.2.0", + "mini-css-extract-plugin": "^1.4.0", + "webpack": "^4.46.0" + } +} diff --git a/test/webpack4/webpack.config.js b/test/webpack4/webpack.config.js new file mode 100644 index 0000000..898640c --- /dev/null +++ b/test/webpack4/webpack.config.js @@ -0,0 +1,47 @@ +const DefinePlugin = require('webpack').DefinePlugin; +const ExtractTextPlugin = require('mini-css-extract-plugin'); + +const styleExtractPlugin = new ExtractTextPlugin({ + filename: '[name].css', +}); + +module.exports = function (options) { + return { + mode: 'none', + entry: { + test: './index.js' + }, + cache: false, + performance: false, + context: options.testDirectory, + output: { + filename: '[name].js', + path: options.outputDirectory, + }, + module: { + rules: [ + { + test: /\.css$/, + use: [ + ExtractTextPlugin.loader, + { + loader: options.basePath + '/node_modules/css-loader', + options: { + modules: { + localIdentName: 'local-[local]', + }, + sourceMap: true + } + }, + ], + }, + ], + }, + plugins: [ + new DefinePlugin({ + 'process.env.NODE_ENV': '"production"', + }), + styleExtractPlugin, + ], + }; +}; diff --git a/test/webpack5/integrations.spec.js b/test/webpack5/integrations.spec.js new file mode 100644 index 0000000..ea034bd --- /dev/null +++ b/test/webpack5/integrations.spec.js @@ -0,0 +1,5 @@ +const runIntegrations = require('../lib/integrations.js'); + +describe('Integrations with webpack 5', function() { + runIntegrations.call(this, __dirname, '5'); +}); diff --git a/test/webpack5/package.json b/test/webpack5/package.json new file mode 100644 index 0000000..8f5cb31 --- /dev/null +++ b/test/webpack5/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "css-loader": "^5.2.0", + "mini-css-extract-plugin": "^1.4.0", + "webpack": "^5.28.0" + } +} diff --git a/test/webpack5/webpack.config.js b/test/webpack5/webpack.config.js new file mode 100644 index 0000000..d42ce09 --- /dev/null +++ b/test/webpack5/webpack.config.js @@ -0,0 +1,47 @@ +const DefinePlugin = require('webpack').DefinePlugin; +const ExtractTextPlugin = require('mini-css-extract-plugin'); + +const styleExtractPlugin = new ExtractTextPlugin({ + filename: '[name].css', +}); + +module.exports = function (options, basePath) { + return { + mode: 'none', + entry: { + test: './index.js' + }, + cache: false, + performance: false, + context: options.testDirectory, + output: { + filename: '[name].js', + path: options.outputDirectory, + }, + module: { + rules: [ + { + test: /\.css$/, + use: [ + ExtractTextPlugin.loader, + { + loader: options.basePath + '/node_modules/css-loader', + options: { + modules: { + localIdentName: 'local-[local]', + }, + sourceMap: true + } + }, + ], + }, + ], + }, + plugins: [ + new DefinePlugin({ + 'process.env.NODE_ENV': '"production"', + }), + styleExtractPlugin, + ], + }; +};