Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Jest, unit tests, webpack integration tests, test helpers * update README Co-authored-by: Scott Norvell <scottlnorvell@gmail.com> Co-authored-by: Doug Schrashun <thejazzface@gmail.com>
- Loading branch information
Showing
33 changed files
with
449 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
a { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
body { | ||
margin: 0; | ||
color: red; | ||
} | ||
p { | ||
margin: 1000px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
body { | ||
color: red; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
p { | ||
padding: 500px; | ||
padding: 1000px; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
a { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
p { | ||
color: green; | ||
} |
1 change: 1 addition & 0 deletions
1
test/cases/duplicate-css-exists-without-plugin/expected/file.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body{color:red}a{color:blue}body{color:red}p{color:green} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('./a.css'); | ||
require('./b.css'); |
23 changes: 23 additions & 0 deletions
23
test/cases/duplicate-css-exists-without-plugin/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
a { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
body { | ||
margin: 0; | ||
color: red; | ||
} | ||
p { | ||
margin: 1000px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
body { | ||
color: red; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
p { | ||
padding: 500px; | ||
padding: 1000px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
body { | ||
color: red; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
p { | ||
padding: 500px; | ||
padding: 1000px; | ||
} |
1 change: 1 addition & 0 deletions
1
test/cases/only-assetNameRegExp-processed/expected/optimize.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a{color:blue}body{margin:0;color:red}p{margin:1000px} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('./a_optimize-me.css'); | ||
require('./b_optimize-me.css'); | ||
require('./c_as-is.css'); |
40 changes: 40 additions & 0 deletions
40
test/cases/only-assetNameRegExp-processed/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
a { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
color: red; | ||
} | ||
p { | ||
color: green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a{color:blue}body{color:red}p{color:green} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('./a.css'); | ||
require('./b.css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
html{display:none} |
Oops, something went wrong.