postcss/postcss-parser-tests

Name: postcss-parser-tests

Owner: PostCSS

Description: Base tests for every PostCSS CSS parser

Created: 2015-08-02 13:30:41.0

Updated: 2018-03-17 12:39:19.0

Pushed: 2018-03-08 16:19:09.0

Homepage: null

Size: 226

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

PostCSS Parser Tests Build Status

<img align=“right” width=“95” height=“95”

 title="Philosopher?s stone, logo of PostCSS"
 src="http://postcss.github.io/postcss/logo.svg">

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

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:

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

s.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:

.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:

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

});

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.