Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Commit dcc0625

Browse files
committed
add tests
add integration tests based on extract-text-webpack-plugin tests
1 parent dc931d4 commit dcc0625

File tree

12 files changed

+213
-38
lines changed

12 files changed

+213
-38
lines changed

.babelrc

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
{
2-
"presets": [
3-
[
4-
"env",
5-
{
6-
"modules": false
7-
}
8-
]
9-
],
10-
"plugins": [
11-
"external-helpers",
12-
"syntax-object-rest-spread",
13-
"transform-object-rest-spread"
14-
]
15-
16-
// {
17-
// "presets": ["es2015-rollup"],
18-
// "plugins": ["syntax-object-rest-spread", "transform-object-rest-spread"]
19-
// }
2+
"env": {
3+
"test": {
4+
"presets": ["env"],
5+
"plugins": ["syntax-object-rest-spread", "transform-object-rest-spread"]
6+
},
7+
"development": {
8+
"presets": [
9+
[
10+
"env",
11+
{
12+
"targets": {
13+
"browsers": ["last 2 versions"]
14+
},
15+
"modules": false
16+
}
17+
]
18+
],
19+
"plugins": [
20+
"external-helpers",
21+
"syntax-object-rest-spread",
22+
"transform-object-rest-spread"
23+
]
24+
}
25+
}
2026
}

.eslintrc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
2-
"extends": "eslint:recommended",
3-
"parserOptions": {
4-
"ecmaVersion": 6,
5-
"sourceType": "module"
6-
},
7-
"env": {
8-
"browser": true,
9-
"commonjs": true,
10-
"node": true,
11-
"es6": true
12-
}
13-
}
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module"
6+
},
7+
"env": {
8+
"browser": true,
9+
"commonjs": true,
10+
"node": true,
11+
"es6": true
12+
},
13+
"parser": "babel-eslint"
14+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/__tests__/js
2+
13
# Logs
24
logs
35
*.log

__tests__/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"jest": true
4+
}
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Webpack Integration Tests simple 1`] = `
4+
".hello {
5+
color: red;
6+
}
7+
8+
.whitelisted {
9+
color: green;
10+
}
11+
12+
md\\\\:w-2\\\\/3 {
13+
color: red;
14+
}
15+
"
16+
`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.hello {
2+
color: red;
3+
}
4+
5+
.whitelisted {
6+
color: green;
7+
}
8+
9+
md\:w-2\/3 {
10+
color: red;
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
3+
<head>
4+
<title>Purgecss webpack test</title>
5+
</head>
6+
7+
<body>
8+
<div class="md:w-2/3"></div>
9+
<div class="hello"></div>
10+
<div></div>
11+
</body>
12+
13+
</html>

__tests__/cases/simple/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './../style.css'

__tests__/cases/simple/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.hello {
2+
color: red;
3+
}
4+
5+
.unused {
6+
color: blue;
7+
}
8+
9+
.whitelisted {
10+
color: green;
11+
}
12+
13+
md\:w-2\/3 {
14+
color: red;
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const path = require('path')
2+
const glob = require('glob')
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
4+
const PurgecssPlugin = require('../../../src/').default
5+
6+
class CustomExtractor {
7+
static extract(content) {
8+
return content.match(/[A-z0-9-:/]+/g)
9+
}
10+
}
11+
12+
const PATHS = {
13+
src: path.join(__dirname, 'src')
14+
}
15+
16+
module.exports = {
17+
entry: './src/index.js',
18+
// output: {
19+
// filename: 'bundle.js',
20+
// path: path.join(__dirname, 'dist')
21+
// },
22+
module: {
23+
rules: [
24+
{
25+
test: /\.css$/,
26+
use: ExtractTextPlugin.extract({
27+
fallback: 'style-loader',
28+
use: 'css-loader?sourceMap'
29+
})
30+
}
31+
]
32+
},
33+
plugins: [
34+
new ExtractTextPlugin('style.css'),
35+
new PurgecssPlugin({
36+
paths: glob.sync(`${PATHS.src}/*`),
37+
whitelist: ['whitelisted'],
38+
extractors: [
39+
{
40+
extractor: CustomExtractor,
41+
extensions: ['html', 'js']
42+
}
43+
]
44+
})
45+
]
46+
}

0 commit comments

Comments
 (0)