PostCSS Parser Tests is a utility package providing a comprehensive suite of base tests designed for any CSS parser, not exclusively those within the PostCSS ecosystem. It includes 24 CSS files covering extreme and edge cases of the CSS specification, alongside integration tests derived from popular website styles to evaluate real-world CSS parsing robustness. The current stable version, 8.9.0, continues to enhance test coverage, with recent updates adding more rules for semicolon cases. This package primarily facilitates the development and validation of CSS parsers by offering structured test cases and helper methods like `cases.each` for iterating through tests and `cases.real` for integration testing. It aims to standardize parser testing against a broad spectrum of valid and challenging CSS inputs, ensuring robustness and spec compliance across different parsing implementations.
npm install postcss-parser-testsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to iterate through all standard CSS test cases using `cases.each` and run integration tests with `cases.real`, simulating a test runner and a custom parser. It shows how to use the provided CSS strings and compare parsed ASTs with the 'ideal' PostCSS AST JSON.
Upgrade your Node.js runtime to a supported LTS version (e.g., 18 or 20).
Ensure your test setup includes an actual CSS parser library (e.g., `postcss`) and passes its parsing function to `cases.each` or `cases.real` callbacks.
For non-PostCSS parsers, either implement a conversion layer to PostCSS AST format before comparing with `ideal`, or compare the input CSS string directly with the stringified output of your parser.
Define and pass your CSS parsing function to the `cases.each` callback, or ensure it's available in the scope where `cases.each` is called. E.g., `const root = yourParser(css, { from: name });`Install and configure a test runner (e.g., Jest, Mocha) and an assertion library (e.g., Jest's built-in assertions, Chai) as per their respective documentation.
No dependency data recorded yet.