-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Minimal Tests for plugin-postcss (#1357)
* initial commit * removed unnecessary mocks * removed snapshots & mocked execa * removed console logs
- Loading branch information
1 parent
3d30c5a
commit 127ffd2
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`]) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
plugins: [ | ||
require('cssnano')({ | ||
preset: 'default', | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
127ffd2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: