Skip to content

Commit

Permalink
Added Minimal Tests for plugin-postcss (#1357)
Browse files Browse the repository at this point in the history
* initial commit

* removed unnecessary mocks

* removed snapshots & mocked execa

* removed console logs
  • Loading branch information
thescripted authored Oct 27, 2020
1 parent 3d30c5a commit 127ffd2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
46 changes: 46 additions & 0 deletions plugins/plugin-postcss/test/plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fs = require('fs');
const path = require('path');
const plugin = require("../plugin.js");

const cssPath = path.resolve(__dirname, './stubs/style.css');
const cssContent = fs.readFileSync(cssPath, 'utf-8');
const configFilePath = path.resolve(__dirname, './stubs/postcss.config.js');

jest.mock('execa')
const execa = require('execa');

describe('@snowpack/plugin-postcss', () => {
beforeEach(() => {
execa.mockClear();
execaFn = jest.fn(() => {
return {
stdout: "stdout",
stderr: "stderr"
}
});
execa.mockImplementation(execaFn)
});

test('with no options', async () => {
const pluginInstance = plugin({}, {});
const transformCSSResults = await pluginInstance.transform({
fileExt: path.extname(cssPath),
contents: cssContent
});
expect(execa.mock.calls[0]).toContain('postcss')
expect(execa.mock.calls[0][1]).not.toEqual([`--config ${configFilePath}`])
});

test('passing in a config file', async () => {
const options = {
config: path.resolve(configFilePath)
}
const pluginInstance = plugin({}, options)
const transformCSSResults = await pluginInstance.transform({
fileExt: path.extname(cssPath),
contents: cssContent
});
expect(execa.mock.calls[0]).toContain('postcss')
expect(execa.mock.calls[0][1]).toEqual([`--config ${configFilePath}`])
});
});
7 changes: 7 additions & 0 deletions plugins/plugin-postcss/test/stubs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
plugins: [
require('cssnano')({
preset: 'default',
}),
],
};
16 changes: 16 additions & 0 deletions plugins/plugin-postcss/test/stubs/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body {
background: #fff;
}

#root {
width: 480px;
margin: auto;
padding: 16px;
box-sizing: border-box;
}

.content {
color: blue;
}


1 comment on commit 127ffd2

@vercel
Copy link

@vercel vercel bot commented on 127ffd2 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.