Skip to content
Base tests for every PostCSS CSS parser
Branch: master
Clone or download
Latest commit a74ef48 Nov 18, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cases
test
.editorconfig
.gitignore Use yarn and Jest Feb 13, 2017
.npmignore
.travis.yml
CHANGELOG.md Release 6.3.1 version Nov 18, 2018
LICENSE Initialize new project Aug 2, 2015
README.md
each.js
extra-cases.json
index.js
jsonify.js
package.json
path.js
real.js
update Update dependencies and ESLint config Jun 21, 2018
yarn.lock

README.md

PostCSS Parser Tests Build Status

This project contains base tests for every PostCSS CSS parser, including:

  • 24 CSS files to test extreme cases of the CSS specification.
  • Integration tests by popular website styles to test CSS from the wild.

These tests are useful for any CSS parser, not just parsers within the PostCSS ecosystem.

Cases

You can iterate through all test cases using the cases.each method:

var cases = require('postcss-parser-tests');

cases.each( (name, css, ideal) => {
    it('parses ' + name, () => {
        let root = parse(css, { from: name });
        let json = cases.jsonify(root);
        expect(json).to.eql(ideal);
    });
});

This returns the case name, CSS string, and PostCSS AST JSON.

If you create a non-PostCSS parser, just compare if the input CSS is equal to the output CSS after parsing.

You can also get the path to some specific test cases using the cases.path(name) method.

Integration

Integration tests are packed into a Gulp task:

gulp.task('integration', function (done) {
    var cases  = require('postcss-parser-tests');
    let parser = require('./');
    cases.real(done, function (css) {
        return parser(css).toResult({ map: { annotation: false } });
    });
});

Your callback must parse CSS and stringify it back. The plugin will then compare the input and output CSS.

You can add extra sites using an optional second argument:

cases.real(done, [['Browserhacks', 'http://browserhacks.com/']],
    function (css) {

    });
You can’t perform that action at this time.