Quickly test PostCSS plugins
npm install postcss-tape[][npm-url]
[][cli-url]
[][git-url]
[PostCSS Tape] lets you quickly test [PostCSS] plugins.
1. Install this dependency to your project:
``sh`
npm install postcss-tape --save-dev
2. Add the postcss-tape task to your package.json:`
json`
{
"scripts": {
"test": "postcss-tape"
}
}
3. Add tests to your .tape.js file:`
js`
export default {
'basic': {
message: 'supports basic usage'
}
};
That’s it! Empty tests will be auto-generated.
`sh`
npm test
Options may be passed through package.json using postcssConfig:
`json`
{
"postcssConfig": {
"plugin": "path/to/plugin.js",
"config": "path/to/.tape.js",
"fixtures": "path/to/cssdir"
}
}
Options may be passed through arguments:
`sh`
postcss-tape --plugin path/to/plugin.js --config path/to/.tape.js
The message provided to the console to identify the test being run.
`js`
{
'some-test': {
message: 'supports some test usage'
}
}
The options passed into the PostCSS plugin for the test.
`js`
{
'some-test': {
options: {
someOption: true,
anotherOption: 5,
etc: 'etc'
}
}
}
The process options passed into PostCSS for the test. Read the
PostCSS documentation for
more details.
`js`
{
'some-test': {
processOptions: {
map: {
inline: true,
sourcesContent: true
}
}
}
}
Either the number of warnings expected to be generated by the test, or an
object used to match warnings given by the test.
`js`
{
'some-test': {
warnings: 3
}
}
`js`
{
'some-test': {
warnings: {
text: /should warn/
}
}
}
An object used to match an error thrown by the test.
`js`
{
'some-test': {
error: {
message: 'You should not have done that'
}
}
}
In that example, the error expects a field of message to be the stringYou should not have done that. So that an error can be inspecific, regularmessage: /^You should not have done/
expressions may also be used, so that something like would also matchYou should not have done this.
The location of the source CSS file, relative to the fixtures directory. This
file is passed through the PostCSS plugin.
`js`
{
'some-test': {
source: 'alterate-source.css'
}
}
In that example, a some-test field would automatically populate thesource as some-test.css unless it was overridden. In order that multiplesome-test:modifier
tests may use the same source file, a field would stillsource
populate the as some-test.css.
The location of the expected CSS file, relative to the fixtures directory.source
This file is represents the expected CSS result of after being passed
through the PostCSS plugin.
`js`
{
'some-test': {
expect: 'alterate-expect.css'
}
}
In that example, a some-test field would automatically populate theexpect as some-test.expect.css unless it was overridden. In order thatsome-test:modifier
multiple tests may use the same source file, a field wouldsource
still populate the as some-test.css, but alter the expect to besome-test.modifier.expect.css.
The location of the resulting CSS file, relative to the fixtures directory.source
This file is the CSS result of after being passed through the PostCSS
plugin.
`js`
{
'some-test': {
result: 'alterate-result.css'
}
}
In that example, a some-test field would automatically populate theresult as some-test.result.css unless it was overridden. In order thatsome-test:modifier
multiple tests may use the same source file, a field wouldsource
still populate the as some-test.css, but alter the result to besome-test.modifier.result.css.
A function to be run before the particular test. This is helpful for generating
variables, content, or files that will be used by the plugin.
`js`
{
'some-test': {
before: () => {
/ do something before the plugin runs /
}
}
}
A function to be run after the particular test. This is helpful for cleaning up
variables, content, or files that were used by the plugin.
`js`
{
'some-test': {
after: () => {
/ do something after the plugin runs /
}
}
}
A plugin or array of plugins that will specifying alternative plugin
`js`
{
'some-test': {
plugin: () => require('postcss')(
require('some-plugin-that-runs-before'),
require('.'),
require('some-plugin-that-runs-after')
)
}
}
Options can be passed into the postcss-tape function or defined inpackage.json using the postcssConfig property.
The path to the plugin being tested.
`bash`
postcss-tape --plugin path/to/plugin.js
`json`
{
"postcssConfig": {
"plugin": "path/to/plugin.js"
}
}
By default, plugin is the resolved file from the current working directory.
The path to the configuration file used to run tests.
`bash`
postcss-tape --config path/to/config.js
`json`
{
"postcssConfig": {
"config": "path/to/config.js"
}
}
By default, [PostCSS Tape] will try to use the file defined by config, orconfig
the directory’s postcss-tape.config.js or .tape.js file. Byconfig
default, is the current working directory.
The path to the fixtures used by tests.
`bash`
postcss-tape --fixtures path/to/tests
`json``
{
"postcssConfig": {
"fixtures": "path/to/tests"
}
}
[npm-url]: https://www.npmjs.com/package/postcss-tape
[cli-url]: https://travis-ci.org/csstools/postcss-tape
[git-url]: https://gitter.im/postcss/postcss
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Tape]: https://github.com/csstools/postcss-tape