Writing Tests for Plugin-Postcss: Mocking? #1326
Unanswered
thescripted
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Not a naïve question at all! This actually seems difficult, especially since we’re running the CLI command But I think we could mock const postcss = require('postcss');
jest.mock('execa', () => (command) => {
postcss(/* do some custom config here for testing */)
}));
const plugin = import ('./plugin.js'); // make sure this comes after `jest.mock`! It’s a bit involved, but we could basically load our own PostCSS everything by mocking If this totally wasn’t what you were asking, forgive me! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This may be a naive question, but I believe it would be useful to add a stub postcss config file to run and test this block:
https://github.com/pikapkg/snowpack/blob/f563593a2511573b1a9962afe4fcef34c91dff4c/plugins/plugin-postcss/plugin.js#L7-L11
I'm not entirely sure how to mock imported plugins. (i.e., if cssnano is in the postcss config, then the snapshot output should be a minified css file). Is there any advice on how to do this, if this is the right track?
Beta Was this translation helpful? Give feedback.
All reactions