1. postcss-parser-tests
Base tests for every PostCSS CSS parser
postcss-parser-tests
Package: postcss-parser-tests
Created by: postcss
Last modified: Tue, 29 Aug 2023 17:42:14 GMT
Version: 8.8.0
License: MIT
Downloads: 1,974
Repository: https://github.com/postcss/postcss-parser-tests

Install

npm install postcss-parser-tests
yarn add postcss-parser-tests

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/'
])

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code