npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

playwright-results-parser

v1.0.2

Published

Core building block for Playwright test analysis tools - provides foundational parsing, normalization, and transformation APIs that other packages can build upon.

Downloads

24

Readme

npm codecov Node.js Version License: MIT TypeScript

A powerful Node.js library for parsing and analyzing Playwright test results. This package provides comprehensive parsing capabilities for Playwright's JSON reporter output, making it easy to extract insights, generate reports, and integrate test results into your CI/CD workflows.

Features

  • Comprehensive Parsing: Parse Playwright JSON test results with full type safety
  • Statistical Analysis: Calculate pass rates, duration statistics, and test metrics
  • Flexible Filtering: Filter results by status, tags, projects, and custom predicates
  • Tag Management: Extract and analyze test tags from various formats
  • Detailed Information: Access test errors, annotations, retries, and attachments
  • Type-Safe: Built with TypeScript for excellent IDE support and type safety

Installation

npm install playwright-results-parser

or

yarn add playwright-results-parser

or

pnpm add playwright-results-parser

Usage

Basic Example

import { parsePlaywrightResults } from "playwright-results-parser";

// Parse results from a file
const results = await parsePlaywrightResults("path/to/results.json");

// Or parse from JSON data directly
const jsonData = {
  /* your playwright JSON results */
};
const results = await parsePlaywrightResults(jsonData);

// Access parsed data
console.log(`Total tests: ${results.summary.total}`);
console.log(`Passed: ${results.summary.passed}`);
console.log(`Failed: ${results.summary.failed}`);
console.log(`Pass rate: ${(results.summary.passRate * 100).toFixed(2)}%`);

Filtering Results

import { parsePlaywrightResults, filterResults } from "playwright-results-parser";

const results = await parsePlaywrightResults("results.json");

// Filter by status
const failedTests = filterResults(results, { status: ["failed", "timedOut"] });

// Filter by tags
const smokeTests = filterResults(results, { tags: ["@smoke"] });

// Filter by project
const chromeTests = filterResults(results, { projects: ["chromium"] });

// Custom filter
const slowTests = filterResults(results, {
  predicate: (test) => test.duration > 5000,
});

// Combine multiple filters
const criticalFailures = filterResults(results, {
  status: ["failed"],
  tags: ["@critical"],
  projects: ["chromium", "firefox"],
});

Working with Test Details

import { parsePlaywrightResults } from "playwright-results-parser";

const results = await parsePlaywrightResults("results.json");

// Iterate through all tests
results.tests.forEach((test) => {
  console.log(`Test: ${test.title}`);
  console.log(`  File: ${test.file}:${test.line}`);
  console.log(`  Status: ${test.status}`);
  console.log(`  Duration: ${test.duration}ms`);

  // Access test tags
  if (test.tags.length > 0) {
    console.log(`  Tags: ${test.tags.join(", ")}`);
  }

  // Check for errors
  if (test.errors.length > 0) {
    test.errors.forEach((error) => {
      console.log(`  Error: ${error.message}`);
      if (error.snippet) {
        console.log(`    Snippet: ${error.snippet}`);
      }
    });
  }

  // Access annotations
  test.annotations.forEach((annotation) => {
    console.log(`  ${annotation.type}: ${annotation.description}`);
  });
});

Analyzing Test Suites

import { parsePlaywrightResults } from "playwright-results-parser";

const results = await parsePlaywrightResults("results.json");

// Access suite hierarchy
results.suites.forEach((suite) => {
  console.log(`Suite: ${suite.title}`);
  console.log(`  File: ${suite.file}`);
  console.log(`  Total tests: ${suite.tests.length}`);
  console.log(`  Pass rate: ${(suite.stats.passRate * 100).toFixed(2)}%`);

  // Access nested suites
  if (suite.suites.length > 0) {
    console.log(`  Nested suites: ${suite.suites.length}`);
  }
});

Statistical Analysis

import { parsePlaywrightResults, getStatistics } from "playwright-results-parser";

const results = await parsePlaywrightResults("results.json");
const stats = getStatistics(results);

console.log("Test Statistics:");
console.log(`  Total: ${stats.total}`);
console.log(`  Passed: ${stats.passed}`);
console.log(`  Failed: ${stats.failed}`);
console.log(`  Flaky: ${stats.flaky}`);
console.log(`  Skipped: ${stats.skipped}`);
console.log(`  Pass Rate: ${(stats.passRate * 100).toFixed(2)}%`);
console.log(`  Average Duration: ${stats.avgDuration.toFixed(2)}ms`);
console.log(`  Total Duration: ${stats.totalDuration}ms`);

API Reference

Main Functions

parsePlaywrightResults(input)

Parses Playwright JSON results from a file path or JSON object.

  • Parameters:
    • input: File path (string) or Playwright JSON results object
  • Returns: Promise<ParsedResults>

filterResults(results, options)

Filters parsed results based on specified criteria.

  • Parameters:
    • results: Parsed results object
    • options: Filter options object
      • status: Array of test statuses to include
      • tags: Array of tags to filter by
      • projects: Array of project names to filter by
      • predicate: Custom filter function
  • Returns: FilteredResults

getStatistics(results)

Calculates statistical metrics from test results.

  • Parameters:
    • results: Parsed or filtered results
  • Returns: Statistics object with metrics

Types

The package exports comprehensive TypeScript types for all data structures:

import type {
  ParsedResults,
  TestResult,
  Suite,
  TestStatus,
  Statistics,
  FilterOptions,
  // ... and more
} from "playwright-results-parser";

Showcases

This package serves as the core parsing library for several GitHub Actions:

Playwright Results Summary Action

Generate test result summaries directly in your pull requests and workflow runs.

Playwright Results Notify Action

Send test results notifications via Slack, email, or other channels.

Playwright Prometheus Metrics Action

Export Playwright test metrics to Prometheus for monitoring and alerting.

Requirements

  • Node.js 18.x or later
  • Playwright test results in JSON format (generated using --reporter=json)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Created and maintained by Idan Fishman

Support

If you find this package helpful, please consider giving it a star on GitHub.

For issues, questions, or suggestions, please open an issue.