{"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install postcss-parser-tests"],"cli":null},"imports":["import cases from 'postcss-parser-tests';","import cases from 'postcss-parser-tests';\ncases.each((name, css, ideal) => { /* ... */ });","import cases from 'postcss-parser-tests';\ncases.real(css => { /* ... */ });","import type { Cases } from 'postcss-parser-tests';"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}