{"id":13790,"library":"postcss-parser-tests","title":"PostCSS Parser Tests","description":"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.","status":"active","version":"8.9.0","language":"javascript","source_language":"en","source_url":"https://github.com/postcss/postcss-parser-tests","tags":["javascript","postcss","parser","css","tests","typescript"],"install":[{"cmd":"npm install postcss-parser-tests","lang":"bash","label":"npm"},{"cmd":"yarn add postcss-parser-tests","lang":"bash","label":"yarn"},{"cmd":"pnpm add postcss-parser-tests","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` is shown in old examples, ESM `import` is the standard for modern Node.js and browser environments. The package ships with TypeScript types.","wrong":"const cases = require('postcss-parser-tests');","symbol":"cases","correct":"import cases from 'postcss-parser-tests';"},{"note":"`each` is a method on the default exported `cases` object, not a direct named export.","symbol":"each","correct":"import cases from 'postcss-parser-tests';\ncases.each((name, css, ideal) => { /* ... */ });"},{"note":"`real` is a method on the default exported `cases` object, used for integration tests, not a direct named export.","symbol":"real","correct":"import cases from 'postcss-parser-tests';\ncases.real(css => { /* ... */ });"},{"note":"Type import for the main exported object, useful for TypeScript users.","symbol":"Cases","correct":"import type { Cases } from 'postcss-parser-tests';"}],"quickstart":{"code":"import cases from 'postcss-parser-tests';\n\n// Assuming you have a CSS parser function called `parse` and a test runner like Mocha/Jest.\n// This example uses a simplified `parse` and `expect` for demonstration.\n\nconst mockParse = (css: string, options?: { from: string }) => {\n  // In a real scenario, this would be your actual CSS parser\n  // For example, from 'postcss': return postcss.parse(css, options);\n  console.log(`Parsing: ${options?.from || 'unknown'}`);\n  return { type: 'root', nodes: [], toJSON: () => ({ /* simplified AST */ }) };\n};\n\nconst mockExpect = (value: any) => ({\n  toEqual: (expected: any) => {\n    console.log(`Comparing parsed output with ideal AST... ${JSON.stringify(value) === JSON.stringify(expected) ? 'Success' : 'Failure'}`);\n    // In a real test, this would throw an error on mismatch\n  }\n});\n\ndescribe('PostCSS Parser Tests', () => {\n  cases.each((name, css, ideal) => {\n    it('parses ' + name, () => {\n      const root = mockParse(css, { from: name });\n      const json = cases.jsonify(root);\n      mockExpect(json).toEqual(ideal);\n    });\n  });\n\n  // Example of integration tests with a mock parser\n  it('runs integration tests', async () => {\n    const results = [];\n    await cases.real(css => {\n      // Your parser should take CSS string and return a PostCSS Result object (or similar).\n      // For this example, we just return the input CSS.\n      results.push({ input: css, output: css });\n      return { css: css, toResult: () => ({ css: css, map: { annotation: false } }) };\n    });\n    console.log(`Completed ${results.length} integration tests.`);\n    mockExpect(results.length).toEqual(20); // Example assertion, actual count varies.\n  });\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js runtime to a supported LTS version (e.g., 18 or 20).","message":"PostCSS 8 (and by extension, packages in its ecosystem like `postcss-parser-tests`) dropped support for Node.js versions 6.x, 8.x, 11.x, and 13.x. Ensure your environment uses a supported Node.js version (e.g., Node.js 12+).","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"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.","message":"This package provides test data and utility methods, not a CSS parser itself. Users must provide their own `parse` function (typically from a PostCSS-compatible parser) when using `cases.each` or a full parser/stringify callback for `cases.real`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"While the package exposes test data for any CSS parser, the `ideal` AST provided by `cases.each` and the expected output for `cases.jsonify` are specifically in the PostCSS AST format. Non-PostCSS parsers will need to convert their AST to match PostCSS's structure for direct comparison, or compare parsed CSS strings directly as suggested by the README.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'24':32 '8.9.0':64 'across':130 'ad':73 'aim':110 'alongsid':44 'base':16 'broad':117 'case':39,78,94 'cases.each':99 'cases.real':105 'challeng':122 'complianc':129 'comprehens':13 'continu':65 'cover':35 'coverag':69 'css':21,33,42,57,88,123,137 'current':61 'deriv':47 'design':18 'develop':84 'differ':131 'ecosystem':29 'edg':38 'enhanc':67 'ensur':125 'evalu':53 'exclus':24 'extrem':36 'facilit':82 'file':34 'helper':96 'implement':133 'includ':31 'input':124 'integr':45,107 'iter':101 'javascript':134 'like':98 'method':97 'offer':91 'packag':10,80 'pars':58,132 'parser':2,5,22,89,113,136 'popular':49 'postcss':1,4,28,135 'primarili':81 'provid':11 'real':55 'real-world':54 'recent':71 'robust':59,126 'rule':75 'semicolon':77 'spec':128 'specif':43 'spectrum':118 'stabl':62 'standard':112 'structur':92 'style':51 'suit':14 'test':3,6,17,46,68,93,103,108,114,138 'typescript':139 'updat':72 'util':9 'valid':86,120 'version':63 'websit':50 'within':26 'world':56","created_at":"2026-04-20T01:56:19.669871+00:00","updated_at":"2026-04-20T01:56:19.669871+00:00","problems":[{"fix":"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 });`","cause":"The user did not provide a `parse` function (their CSS parser) to be used within the `cases.each` callback.","error":"TypeError: parse is not a function"},{"fix":"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.","cause":"The test environment (e.g., Mocha, Jest) or an assertion library (e.g., Chai) has not been correctly set up or imported, so `expect` is not globally available or imported.","error":"ReferenceError: expect is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/postcss/postcss-parser-tests","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/postcss-parser-tests","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}