Skip to content

Commit 108d871

Browse files
test: more
1 parent b4d3bcc commit 108d871

14 files changed

+443
-193
lines changed

src/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Module from 'module';
44
import { cosmiconfig } from 'cosmiconfig';
55

66
const parentModule = module;
7-
const moduleName = 'postcss';
87

98
const stat = (inputFileSystem, filePath) =>
109
new Promise((resolve, reject) => {
@@ -60,7 +59,7 @@ async function loadConfig(config, context, configPath, loaderContext) {
6059
throw new Error(`No PostCSS Config found in: ${searchPath}`);
6160
}
6261

63-
const explorer = cosmiconfig(moduleName);
62+
const explorer = cosmiconfig('postcss');
6463

6564
let result;
6665

@@ -192,6 +191,7 @@ function getPostcssOptions(loaderContext, config, postcssOptions = {}) {
192191

193192
// No need them for processOptions
194193
delete processOptionsFromConfig.plugins;
194+
delete processOptionsFromConfig.file;
195195

196196
const processOptionsFromOptions = { ...normalizedPostcssOptions };
197197

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path');
2+
3+
module.exports = () => ({
4+
from: path.resolve(__dirname, '../../sss/style.sss'),
5+
to: path.resolve(__dirname, '../../sss/style.css'),
6+
parser: 'sugarss',
7+
map: {
8+
inline: true,
9+
annotation: true,
10+
},
11+
plugins: [
12+
['postcss-short', { prefix: 'x' }]
13+
]
14+
});

test/fixtures/css/plugins.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module.exports = {
22
plugins: {
3-
'postcss-import': {},
4-
'postcss-nested': { preserveEmpty: true },
53
'postcss-short': { prefix: 'x' },
64
}
75
};

test/helpers/getCompiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
1818
module: {
1919
rules: [
2020
{
21-
test: /\.css$/i,
21+
test: /\.(css|sss)$/i,
2222
use: [
2323
{
2424
loader: require.resolve('./testLoader'),
+83-122
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Config Options should emit error when invalid config : errors 1`] = `
3+
exports[`"config" option should throw an error on the invalid config: errors 1`] = `
44
Array [
55
"ModuleBuildError: Module build failed (from \`replaced original path\`):
66
Error: invalid postcss config",
77
]
88
`;
99

10-
exports[`Config Options should emit error when invalid config : warnings 1`] = `Array []`;
10+
exports[`"config" option should throw an error on the invalid config: warnings 1`] = `Array []`;
1111

12-
exports[`Config Options should emit error when unresolved config : errors 1`] = `
12+
exports[`"config" option should throw an error on the unresolved config: errors 1`] = `
1313
Array [
1414
"ModuleBuildError: Module build failed (from \`replaced original path\`):
1515
Error: No PostCSS Config found in: /test/fixtures/config-scope/css/unresolve.js",
1616
]
1717
`;
1818

19-
exports[`Config Options should emit error when unresolved config : warnings 1`] = `Array []`;
19+
exports[`"config" option should throw an error on the unresolved config: warnings 1`] = `Array []`;
2020

21-
exports[`Config Options should work "config" and "postcssOptions" options: css 1`] = `
21+
exports[`"config" option should work "string" value (relative path): css 1`] = `
2222
"a { color: rgba(0, 0, 0, 1.0) }
2323
24-
[dir=ltr] .foo { float: right;
25-
}
26-
27-
[dir=rtl] .foo {
28-
float: left;
24+
.foo {
25+
float: right;
2926
}
3027
"
3128
`;
3229

33-
exports[`Config Options should work "config" and "postcssOptions" options: errors 1`] = `Array []`;
30+
exports[`"config" option should work "string" value (relative path): errors 1`] = `Array []`;
3431

35-
exports[`Config Options should work "config" and "postcssOptions" options: warnings 1`] = `Array []`;
32+
exports[`"config" option should work "string" value (relative path): warnings 1`] = `Array []`;
3633

37-
exports[`Config Options should work Config - "string" with path directory: css 1`] = `
34+
exports[`"config" option should work Config - Context - {Object}: css 1`] = `
3835
"a { color: rgba(0, 0, 0, 1.0) }
3936
4037
.foo {
@@ -43,24 +40,28 @@ exports[`Config Options should work Config - "string" with path directory: css 1
4340
"
4441
`;
4542

46-
exports[`Config Options should work Config - "string" with path directory: errors 1`] = `Array []`;
43+
exports[`"config" option should work Config - Context - {Object}: errors 1`] = `Array []`;
4744

48-
exports[`Config Options should work Config - "string" with path directory: warnings 1`] = `Array []`;
45+
exports[`"config" option should work Config - Context - {Object}: warnings 1`] = `Array []`;
4946

50-
exports[`Config Options should work Config - "string" with relative path: css 1`] = `
51-
"a { color: rgba(0, 0, 0, 1.0) }
47+
exports[`"config" option should work Config - Path - {String}: css 1`] = `
48+
"a { color: black }
5249
5350
.foo {
5451
float: right;
5552
}
5653
"
5754
`;
5855

59-
exports[`Config Options should work Config - "string" with relative path: errors 1`] = `Array []`;
56+
exports[`"config" option should work Config - Path - {String}: errors 1`] = `Array []`;
57+
58+
exports[`"config" option should work Config - Path - {String}: warnings 1`] = `Array []`;
59+
60+
exports[`"config" option should work Config – Context – Loader {Object}: errors 1`] = `Array []`;
6061

61-
exports[`Config Options should work Config - "string" with relative path: warnings 1`] = `Array []`;
62+
exports[`"config" option should work Config – Context – Loader {Object}: warnings 1`] = `Array []`;
6263

63-
exports[`Config Options should work Config - "string": css 1`] = `
64+
exports[`"config" option should work with "Object" value: css 1`] = `
6465
"a { color: rgba(0, 0, 0, 1.0) }
6566
6667
.foo {
@@ -69,76 +70,82 @@ exports[`Config Options should work Config - "string": css 1`] = `
6970
"
7071
`;
7172

72-
exports[`Config Options should work Config - "string": errors 1`] = `Array []`;
73+
exports[`"config" option should work with "Object" value: errors 1`] = `Array []`;
7374

74-
exports[`Config Options should work Config - "string": warnings 1`] = `Array []`;
75+
exports[`"config" option should work with "Object" value: warnings 1`] = `Array []`;
7576

76-
exports[`Config Options should work Config - {Object}: css 1`] = `
77-
"a { color: rgba(0, 0, 0, 1.0) }
77+
exports[`"config" option should work with "false" value: css 1`] = `
78+
"a { color: black }
7879
7980
.foo {
8081
float: right;
8182
}
8283
"
8384
`;
8485

85-
exports[`Config Options should work Config - {Object}: errors 1`] = `Array []`;
86+
exports[`"config" option should work with "false" value: errors 1`] = `Array []`;
8687

87-
exports[`Config Options should work Config - {Object}: warnings 1`] = `Array []`;
88+
exports[`"config" option should work with "false" value: warnings 1`] = `Array []`;
8889

89-
exports[`Config Options should work Config - Context - {Object}: css 1`] = `
90-
"a { color: rgba(0, 0, 0, 1.0) }
90+
exports[`"config" option should work with "package.json": css 1`] = `
91+
".import {
92+
color: red;
93+
}
9194
92-
.foo {
93-
float: right;
95+
.test {
96+
color: blue;
9497
}
9598
"
9699
`;
97100

98-
exports[`Config Options should work Config - Context - {Object}: errors 1`] = `Array []`;
101+
exports[`"config" option should work with "package.json": errors 1`] = `Array []`;
99102

100-
exports[`Config Options should work Config - Context - {Object}: warnings 1`] = `Array []`;
103+
exports[`"config" option should work with "package.json": warnings 1`] = `Array []`;
101104

102-
exports[`Config Options should work Config - Object - path file: css 1`] = `
103-
"a { color: rgba(0, 0, 0, 1.0) }
105+
exports[`"config" option should work with "postcss.config.js" and the array syntax of the "plugin" option: css 1`] = `
106+
".import {
107+
color: red;
108+
}
104109
105-
.foo {
106-
float: right;
110+
.test {
111+
color: cyan;
107112
}
108113
"
109114
`;
110115

111-
exports[`Config Options should work Config - Object - path file: errors 1`] = `Array []`;
116+
exports[`"config" option should work with "postcss.config.js" and the array syntax of the "plugin" option: errors 1`] = `Array []`;
112117

113-
exports[`Config Options should work Config - Object - path file: warnings 1`] = `Array []`;
118+
exports[`"config" option should work with "postcss.config.js" and the array syntax of the "plugin" option: warnings 1`] = `Array []`;
114119

115-
exports[`Config Options should work Config - Path - {String}: css 1`] = `
116-
"a { color: black }
120+
exports[`"config" option should work with "postcss.config.js" and the object syntax of the "plugin" option: css 1`] = `
121+
".import {
122+
color: red;
123+
}
117124
118-
.foo {
119-
float: right;
125+
.test {
126+
color: blue;
120127
}
121128
"
122129
`;
123130

124-
exports[`Config Options should work Config - Path - {String}: errors 1`] = `Array []`;
131+
exports[`"config" option should work with "postcss.config.js" and the object syntax of the "plugin" option: errors 1`] = `Array []`;
125132

126-
exports[`Config Options should work Config - Path - {String}: warnings 1`] = `Array []`;
133+
exports[`"config" option should work with "postcss.config.js" and the object syntax of the "plugin" option: warnings 1`] = `Array []`;
127134

128-
exports[`Config Options should work Config - false: css 1`] = `
129-
"a { color: black }
135+
exports[`"config" option should work with "string" value (absolute path): css 1`] = `
136+
"a { color: rgba(0, 0, 0, 1.0) }
130137
131138
.foo {
132139
float: right;
133140
}
134141
"
135142
`;
136143

137-
exports[`Config Options should work Config - false: errors 1`] = `Array []`;
144+
exports[`"config" option should work with "string" value (absolute path): errors 1`] = `Array []`;
138145

139-
exports[`Config Options should work Config - false: warnings 1`] = `Array []`;
146+
exports[`"config" option should work with "string" value (absolute path): warnings 1`] = `Array []`;
140147

141-
exports[`Config Options should work Config - true: css 1`] = `
148+
exports[`"config" option should work with "string" value (path to directory with the configuration): css 1`] = `
142149
"a { color: rgba(0, 0, 0, 1.0) }
143150
144151
.foo {
@@ -147,106 +154,60 @@ exports[`Config Options should work Config - true: css 1`] = `
147154
"
148155
`;
149156

150-
exports[`Config Options should work Config - true: errors 1`] = `Array []`;
151-
152-
exports[`Config Options should work Config - true: warnings 1`] = `Array []`;
157+
exports[`"config" option should work with "string" value (path to directory with the configuration): errors 1`] = `Array []`;
153158

154-
exports[`Config Options should work Config – Context – Loader {Object}: errors 1`] = `Array []`;
159+
exports[`"config" option should work with "string" value (path to directory with the configuration): warnings 1`] = `Array []`;
155160

156-
exports[`Config Options should work Config – Context – Loader {Object}: warnings 1`] = `Array []`;
157-
158-
exports[`Config Options should work if Config not found: css 1`] = `
161+
exports[`"config" option should work with "string" value and respect all options: css 1`] = `
159162
"a {
160-
color: black;
163+
color: black
161164
}
162165
163-
a {
164-
color: red;
165-
}
166-
167-
a {
168-
color: green;
169-
}
170-
171-
a {
172-
color: blue;
173-
}
174-
175-
.class {
176-
-x-border-color: blue blue *;
177-
-x-color: * #fafafa;
178-
}
179-
180-
.class-foo {
181-
-z-border-color: blue blue *;
182-
-z-color: * #fafafa;
183-
}
184-
185-
.phone {
186-
&_title {
187-
width: 500px;
188-
189-
@media (max-width: 500px) {
190-
width: auto;
191-
}
192-
193-
body.is_dark & {
194-
color: white;
195-
}
196-
}
197-
198-
img {
199-
display: block;
200-
}
201-
}
202-
"
166+
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLnNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFO0FBREYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYVxuICBjb2xvcjogYmxhY2tcbiJdfQ== */"
203167
`;
204168

205-
exports[`Config Options should work if Config not found: errors 1`] = `Array []`;
169+
exports[`"config" option should work with "string" value and respect all options: errors 1`] = `Array []`;
206170

207-
exports[`Config Options should work if Config not found: warnings 1`] = `Array []`;
171+
exports[`"config" option should work with "string" value and respect all options: warnings 1`] = `Array []`;
208172

209-
exports[`Config Options should work package.json - {Object} - Process CSS: css 1`] = `
210-
".import {
211-
color: red;
212-
}
173+
exports[`"config" option should work with "true" value: css 1`] = `
174+
"a { color: rgba(0, 0, 0, 1.0) }
213175
214-
.test {
215-
color: blue;
176+
.foo {
177+
float: right;
216178
}
217179
"
218180
`;
219181

220-
exports[`Config Options should work package.json - {Object} - Process CSS: errors 1`] = `Array []`;
182+
exports[`"config" option should work with "true" value: errors 1`] = `Array []`;
221183

222-
exports[`Config Options should work package.json - {Object} - Process CSS: warnings 1`] = `Array []`;
184+
exports[`"config" option should work with "true" value: warnings 1`] = `Array []`;
223185

224-
exports[`Config Options should work postcss.config.js - {Array} - Process CSS: css 1`] = `
225-
".import {
226-
color: red;
186+
exports[`"config" option should work with the "postcssOptions" option: css 1`] = `
187+
"a { color: rgba(0, 0, 0, 1.0) }
188+
189+
[dir=ltr] .foo { float: right;
227190
}
228191
229-
.test {
230-
color: cyan;
192+
[dir=rtl] .foo {
193+
float: left;
231194
}
232195
"
233196
`;
234197

235-
exports[`Config Options should work postcss.config.js - {Array} - Process CSS: errors 1`] = `Array []`;
198+
exports[`"config" option should work with the "postcssOptions" option: errors 1`] = `Array []`;
236199

237-
exports[`Config Options should work postcss.config.js - {Array} - Process CSS: warnings 1`] = `Array []`;
200+
exports[`"config" option should work with the "postcssOptions" option: warnings 1`] = `Array []`;
238201

239-
exports[`Config Options should work postcss.config.js - {Object} - Process CSS: css 1`] = `
240-
".import {
241-
color: red;
242-
}
202+
exports[`"config" option should work without the specified value: css 1`] = `
203+
"a { color: rgba(0, 0, 0, 1.0) }
243204
244-
.test {
245-
color: blue;
205+
.foo {
206+
float: right;
246207
}
247208
"
248209
`;
249210

250-
exports[`Config Options should work postcss.config.js - {Object} - Process CSS: errors 1`] = `Array []`;
211+
exports[`"config" option should work without the specified value: errors 1`] = `Array []`;
251212

252-
exports[`Config Options should work postcss.config.js - {Object} - Process CSS: warnings 1`] = `Array []`;
213+
exports[`"config" option should work without the specified value: warnings 1`] = `Array []`;

0 commit comments

Comments
 (0)