Skip to content

Commit

Permalink
test: more
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 6, 2020
1 parent b4d3bcc commit 108d871
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 193 deletions.
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Module from 'module';
import { cosmiconfig } from 'cosmiconfig';

const parentModule = module;
const moduleName = 'postcss';

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

const explorer = cosmiconfig(moduleName);
const explorer = cosmiconfig('postcss');

let result;

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

// No need them for processOptions
delete processOptionsFromConfig.plugins;
delete processOptionsFromConfig.file;

const processOptionsFromOptions = { ...normalizedPostcssOptions };

Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/config-scope/all-options/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');

module.exports = () => ({
from: path.resolve(__dirname, '../../sss/style.sss'),
to: path.resolve(__dirname, '../../sss/style.css'),
parser: 'sugarss',
map: {
inline: true,
annotation: true,
},
plugins: [
['postcss-short', { prefix: 'x' }]
]
});
2 changes: 0 additions & 2 deletions test/fixtures/css/plugins.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {
plugins: {
'postcss-import': {},
'postcss-nested': { preserveEmpty: true },
'postcss-short': { prefix: 'x' },
}
};
2 changes: 1 addition & 1 deletion test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
module: {
rules: [
{
test: /\.css$/i,
test: /\.(css|sss)$/i,
use: [
{
loader: require.resolve('./testLoader'),
Expand Down
205 changes: 83 additions & 122 deletions test/options/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

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

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

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

exports[`Config Options should work "config" and "postcssOptions" options: css 1`] = `
exports[`"config" option should work "string" value (relative path): css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
[dir=ltr] .foo { float: right;
}
[dir=rtl] .foo {
float: left;
.foo {
float: right;
}
"
`;

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

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

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

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

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

exports[`Config Options should work Config - "string" with relative path: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
exports[`"config" option should work Config - Path - {String}: css 1`] = `
"a { color: black }
.foo {
float: right;
}
"
`;

exports[`Config Options should work Config - "string" with relative path: errors 1`] = `Array []`;
exports[`"config" option should work Config - Path - {String}: errors 1`] = `Array []`;

exports[`"config" option should work Config - Path - {String}: warnings 1`] = `Array []`;

exports[`"config" option should work Config – Context – Loader {Object}: errors 1`] = `Array []`;

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

exports[`Config Options should work Config - "string": css 1`] = `
exports[`"config" option should work with "Object" value: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
.foo {
Expand All @@ -69,76 +70,82 @@ exports[`Config Options should work Config - "string": css 1`] = `
"
`;

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

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

exports[`Config Options should work Config - {Object}: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
exports[`"config" option should work with "false" value: css 1`] = `
"a { color: black }
.foo {
float: right;
}
"
`;

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

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

exports[`Config Options should work Config - Context - {Object}: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
exports[`"config" option should work with "package.json": css 1`] = `
".import {
color: red;
}
.foo {
float: right;
.test {
color: blue;
}
"
`;

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

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

exports[`Config Options should work Config - Object - path file: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
exports[`"config" option should work with "postcss.config.js" and the array syntax of the "plugin" option: css 1`] = `
".import {
color: red;
}
.foo {
float: right;
.test {
color: cyan;
}
"
`;

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

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

exports[`Config Options should work Config - Path - {String}: css 1`] = `
"a { color: black }
exports[`"config" option should work with "postcss.config.js" and the object syntax of the "plugin" option: css 1`] = `
".import {
color: red;
}
.foo {
float: right;
.test {
color: blue;
}
"
`;

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

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

exports[`Config Options should work Config - false: css 1`] = `
"a { color: black }
exports[`"config" option should work with "string" value (absolute path): css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
.foo {
float: right;
}
"
`;

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

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

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

exports[`Config Options should work Config - true: errors 1`] = `Array []`;

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

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

exports[`Config Options should work Config – Context – Loader {Object}: warnings 1`] = `Array []`;

exports[`Config Options should work if Config not found: css 1`] = `
exports[`"config" option should work with "string" value and respect all options: css 1`] = `
"a {
color: black;
color: black
}
a {
color: red;
}
a {
color: green;
}
a {
color: blue;
}
.class {
-x-border-color: blue blue *;
-x-color: * #fafafa;
}
.class-foo {
-z-border-color: blue blue *;
-z-color: * #fafafa;
}
.phone {
&_title {
width: 500px;
@media (max-width: 500px) {
width: auto;
}
body.is_dark & {
color: white;
}
}
img {
display: block;
}
}
"
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLnNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFO0FBREYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYVxuICBjb2xvcjogYmxhY2tcbiJdfQ== */"
`;

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

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

exports[`Config Options should work package.json - {Object} - Process CSS: css 1`] = `
".import {
color: red;
}
exports[`"config" option should work with "true" value: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
.test {
color: blue;
.foo {
float: right;
}
"
`;

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

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

exports[`Config Options should work postcss.config.js - {Array} - Process CSS: css 1`] = `
".import {
color: red;
exports[`"config" option should work with the "postcssOptions" option: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
[dir=ltr] .foo { float: right;
}
.test {
color: cyan;
[dir=rtl] .foo {
float: left;
}
"
`;

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

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

exports[`Config Options should work postcss.config.js - {Object} - Process CSS: css 1`] = `
".import {
color: red;
}
exports[`"config" option should work without the specified value: css 1`] = `
"a { color: rgba(0, 0, 0, 1.0) }
.test {
color: blue;
.foo {
float: right;
}
"
`;

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

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

0 comments on commit 108d871

Please sign in to comment.