Skip to content

postcss/postcss-parser-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1fc5737 · Feb 10, 2025
Feb 10, 2025
Jan 31, 2025
Feb 10, 2025
Sep 7, 2018
Jan 31, 2022
Jan 31, 2022
Feb 10, 2025
Aug 2, 2015
Jun 15, 2022
Oct 8, 2023
Feb 10, 2025
Aug 28, 2015
Feb 10, 2025
Aug 15, 2023
Feb 10, 2025
Feb 10, 2025
Aug 15, 2023
Feb 1, 2022
Feb 10, 2025
Feb 10, 2025
May 16, 2023
Oct 8, 2023
Jul 10, 2020

Repository files navigation

PostCSS Parser Tests

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:

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

cases.each((name, css, ideal) => {
  it('parses ' + name, () => {
    const root = parse(css, { from: name })
    const json = cases.jsonify(root)
    expect(json).toEquql(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:

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

cases.real(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 third argument:

cases.real(css => {
  return parser(css).toResult({ map: { annotation: false } })
}, [
  'http://browserhacks.com/'
])