Skip to content

Commit

Permalink
Add warnings to custom result handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrinicolas committed Aug 14, 2018
1 parent 6221c65 commit 6140c9a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Create a new tester by calling `new PostcssTester` with an options object:
- `postcss`: The postcss module to use for process
- `plugin`: You PostCSS plugin to test (can be an array of plugins)
tolerateWarnings;
- `from`: __Optional__, default: `''`, The `from` parameter passed to
- `from`: *Optional*, default: `''`, The `from` parameter passed to
`postcss.process`, must be a file path
- `tolerateWarnings`: __Optional__, default: `false`, Ignore PostCSS warnings
- `exactComparaison`: __Optional__, default: `false`, Compare the `input` and
- `tolerateWarnings`: Optional, default: `false`, Ignore PostCSS warnings
- `exactComparaison`: Optional, default: `false`, Compare the `input` and
`output` without any trimming or line breaks cleaning

```js
Expand All @@ -61,10 +61,14 @@ const tester = new PostcssTester({
Then you can run the async function `tester.test(input, output, t, options)``:

- `input`: A string containing your css input
- `output`: A string containing your excpected output, or a function receiving
(err, result, t) for finishing test as you would like it
- `output`: A string containing your excpected output, it can be either a CSS
string, an `Error` or a function receiving (error, warnings, result) letting
you finish the test as you would like it
- `error`: A string containing the Error message
- `warnings`: An array of PostCSS warnings, is null if there an error occured
- `result`: A string containing the PostCSS process result
- `t`: The AVA test `t` object
- `options`: __Optional__, An object containing those additional parameters:
- `options`: *Optional*, An object containing those additional parameters:
- `pluginOptions`: Options passed to your plugin
- `pluginsBefore`: An array of plugins to load before your plugin
- `pluginsAfter`: An array of plugins to load after your plugin
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class PostcssTester {
}

if (typeof output === 'function') {
output(null, result.css, t);
output(null, warnings, result.css);
return;
}

t.fail(`${PREFIX} Invalid output type`);
}).catch(err => {
if (typeof output === 'function') {
output(err, null, t);
output(err, null, null);
return;
}

Expand Down
21 changes: 11 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"clean-publish": "^1.0.9",
"coveralls": "^3.0.2",
"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-react": "^7.11.1",
"nodemon": "^1.18.3",
"nyc": "^12.0.2",
"postcss-import": "^12.0.0",
"postcss-import-ext-glob": "^1.0.0"
"postcss-import-ext-glob": "^1.1.0"
},
"dependencies": {
"one-liner": "^1.3.0"
Expand Down
7 changes: 5 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ test('Function output', async t => {
tolerateWarnings: true
});
t.plan(1);
await tester.test('@import a.css', (err, result) => {
await tester.test('@import a.css', (err, warnings, result) => {
t.is(result, '');
});
});
Expand Down Expand Up @@ -188,6 +188,9 @@ test('Error output', async t => {
plugin: [postcssImportExtGlob]
});
const input = '@import-glob';
const output = new Error('No string found with rule @import-glob ');
const output = new Error(
'postcss-import-ext-glob: <css input>:1:1: No string found with rule'
+ ' @import-glob '
);
await tester.test(input, output, t);
});

0 comments on commit 6140c9a

Please sign in to comment.