Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

ctrf

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ctrf - npm Package Compare versions

Comparing version
0.0.18-next-1
to
0.1.0
+4
-0
dist/builder.d.ts

@@ -7,2 +7,4 @@ /**

/**
*
* @group Builders
* Fluent builder for constructing CTRF reports.

@@ -98,2 +100,4 @@ *

/**
*
* @group Builders
* Fluent builder for constructing Test objects.

@@ -100,0 +104,0 @@ *

@@ -10,2 +10,4 @@ /**

/**
*
* @group Builders
* Fluent builder for constructing CTRF reports.

@@ -195,2 +197,4 @@ *

/**
*
* @group Builders
* Fluent builder for constructing Test objects.

@@ -197,0 +201,0 @@ *

@@ -6,2 +6,4 @@ /**

/**
*
* @group Errors
* Base error class for all CTRF errors.

@@ -14,2 +16,4 @@ * All CTRF-specific errors extend this class.

/**
*
* @group Errors
* Error thrown when schema validation fails.

@@ -24,2 +28,4 @@ * Contains detailed error information for each validation issue.

/**
*
* @group Errors
* Error thrown when JSON parsing fails.

@@ -33,2 +39,4 @@ */

/**
*
* @group Errors
* Error thrown when an unsupported CTRF specification version is encountered.

@@ -44,2 +52,4 @@ */

/**
*
* @group Errors
* Error thrown when a file read or write operation fails.

@@ -55,2 +65,4 @@ */

/**
*
* @group Errors
* Error thrown when building a report or test fails due to missing required fields.

@@ -57,0 +69,0 @@ */

@@ -5,2 +5,4 @@ /**

/**
*
* @group Errors
* Base error class for all CTRF errors.

@@ -17,2 +19,4 @@ * All CTRF-specific errors extend this class.

/**
*
* @group Errors
* Error thrown when schema validation fails.

@@ -32,2 +36,4 @@ * Contains detailed error information for each validation issue.

/**
*
* @group Errors
* Error thrown when JSON parsing fails.

@@ -46,2 +52,4 @@ */

/**
*
* @group Errors
* Error thrown when an unsupported CTRF specification version is encountered.

@@ -63,2 +71,4 @@ */

/**
*
* @group Errors
* Error thrown when a file read or write operation fails.

@@ -80,2 +90,4 @@ */

/**
*
* @group Errors
* Error thrown when building a report or test fails due to missing required fields.

@@ -82,0 +94,0 @@ */

@@ -6,2 +6,4 @@ /**

/**
*
* @group Query & Filter
* Filter tests in a report by criteria.

@@ -28,2 +30,4 @@ *

/**
*
* @group Query & Filter
* Find a single test in a report.

@@ -30,0 +34,0 @@ *

@@ -5,2 +5,4 @@ /**

/**
*
* @group Query & Filter
* Filter tests in a report by criteria.

@@ -29,2 +31,4 @@ *

/**
*
* @group Query & Filter
* Find a single test in a report.

@@ -31,0 +35,0 @@ *

@@ -5,2 +5,4 @@ /**

/**
*
* @group ID Generation
* Generate a deterministic UUID v5 for a test based on its properties.

@@ -32,2 +34,4 @@ * The same inputs will always produce the same UUID, enabling

/**
*
* @group ID Generation
* Generate a random UUID v4 for report identification.

@@ -34,0 +38,0 @@ *

@@ -7,2 +7,4 @@ /**

/**
*
* @group ID Generation
* Generate a deterministic UUID v5 for a test based on its properties.

@@ -51,2 +53,4 @@ * The same inputs will always produce the same UUID, enabling

/**
*
* @group ID Generation
* Generate a random UUID v4 for report identification.

@@ -53,0 +57,0 @@ *

+1
-1

@@ -15,3 +15,3 @@ /**

export { parse, stringify } from './parse.js';
export { mergeReports } from './merge.js';
export { merge } from './merge.js';
export { filterTests, findTest } from './filter.js';

@@ -18,0 +18,0 @@ export { addInsights, isTestFlaky } from './insights.js';

@@ -32,3 +32,3 @@ /**

// ============================================================================
export { mergeReports } from './merge.js';
export { merge } from './merge.js';
// ============================================================================

@@ -35,0 +35,0 @@ // Filtering & Querying

@@ -9,2 +9,4 @@ /**

/**
*
* @group Insights
* Determines if a test is flaky based on the CTRF specification.

@@ -87,2 +89,4 @@ *

/**
*
* @group Insights
* Add insights to a CTRF report using historical data.

@@ -89,0 +93,0 @@ *

@@ -11,2 +11,4 @@ /**

/**
*
* @group Insights
* Determines if a test is flaky based on the CTRF specification.

@@ -694,2 +696,4 @@ *

/**
*
* @group Insights
* Add insights to a CTRF report using historical data.

@@ -696,0 +700,0 @@ *

@@ -6,2 +6,4 @@ /**

/**
*
* @group Merge
* Merge multiple CTRF reports into a single report.

@@ -17,11 +19,11 @@ * Useful for combining results from parallel or sharded test runs.

* ```typescript
* const merged = mergeReports([report1, report2, report3]);
* const merged = merge([report1, report2, report3]);
*
* // With deduplication by test ID
* const merged = mergeReports(reports, { deduplicateTests: true });
* const merged = merge(reports, { deduplicateTests: true });
*
* // Keep first environment only
* const merged = mergeReports(reports, { preserveEnvironment: 'first' });
* const merged = merge(reports, { preserveEnvironment: 'first' });
* ```
*/
export declare function mergeReports(reports: CTRFReport[], options?: MergeOptions): CTRFReport;
export declare function merge(reports: CTRFReport[], options?: MergeOptions): CTRFReport;

@@ -8,2 +8,4 @@ /**

/**
*
* @group Merge
* Merge multiple CTRF reports into a single report.

@@ -19,12 +21,12 @@ * Useful for combining results from parallel or sharded test runs.

* ```typescript
* const merged = mergeReports([report1, report2, report3]);
* const merged = merge([report1, report2, report3]);
*
* // With deduplication by test ID
* const merged = mergeReports(reports, { deduplicateTests: true });
* const merged = merge(reports, { deduplicateTests: true });
*
* // Keep first environment only
* const merged = mergeReports(reports, { preserveEnvironment: 'first' });
* const merged = merge(reports, { preserveEnvironment: 'first' });
* ```
*/
export function mergeReports(reports, options = {}) {
export function merge(reports, options = {}) {
if (!reports || reports.length === 0) {

@@ -31,0 +33,0 @@ throw new Error('No reports provided for merging');

import { describe, it, expect } from 'vitest';
import { mergeReports } from './merge.js';
import { merge } from './merge.js';
import { ReportBuilder, TestBuilder } from './builder.js';

@@ -15,9 +15,9 @@ describe('merge', () => {

};
describe('mergeReports', () => {
describe('merge', () => {
it('should throw for empty reports array', () => {
expect(() => mergeReports([])).toThrow('No reports provided');
expect(() => merge([])).toThrow('No reports provided');
});
it('should return copy for single report', () => {
const report = createReport([{ name: 'test', status: 'passed' }]);
const merged = mergeReports([report]);
const merged = merge([report]);
expect(merged.results.tests).toHaveLength(1);

@@ -29,3 +29,3 @@ expect(merged).not.toBe(report);

const report2 = createReport([{ name: 'test2', status: 'failed' }]);
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.tests).toHaveLength(2);

@@ -41,3 +41,3 @@ expect(merged.results.tests[0].name).toBe('test1');

const report2 = createReport([{ name: 'test3', status: 'failed' }]);
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.summary.tests).toBe(3);

@@ -54,3 +54,3 @@ expect(merged.results.summary.passed).toBe(2);

report2.results.summary.stop = 3000;
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.summary.start).toBe(1000);

@@ -64,3 +64,3 @@ expect(merged.results.summary.stop).toBe(3000);

report2.results.tool = { name: 'vitest', version: '1.0.0' };
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.tool.name).toBe('jest');

@@ -74,3 +74,3 @@ expect(merged.results.tool.version).toBe('29.0.0');

report2.results.tests[0].id = 'same-id';
const merged = mergeReports([report1, report2], {
const merged = merge([report1, report2], {
deduplicateTests: true,

@@ -87,3 +87,3 @@ });

report2.results.tests[0].id = 'same-id';
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.tests).toHaveLength(2);

@@ -96,3 +96,3 @@ });

report2.results.environment = { branchName: 'feature', commit: 'def' };
const merged = mergeReports([report1, report2], {
const merged = merge([report1, report2], {
preserveEnvironment: 'first',

@@ -107,3 +107,3 @@ });

report2.results.environment = { branchName: 'feature' };
const merged = mergeReports([report1, report2], {
const merged = merge([report1, report2], {
preserveEnvironment: 'last',

@@ -118,3 +118,3 @@ });

report2.results.environment = { commit: 'abc123' };
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.environment?.branchName).toBe('main');

@@ -129,3 +129,3 @@ expect(merged.results.environment?.buildId).toBe('build-1');

report2.reportId = 'old-id-2';
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.reportId).toBeDefined();

@@ -141,3 +141,3 @@ expect(merged.reportId).not.toBe('old-id-1');

report2.results.extra = { key2: 'value2' };
const merged = mergeReports([report1, report2]);
const merged = merge([report1, report2]);
expect(merged.results.extra?.key1).toBe('value1');

@@ -144,0 +144,0 @@ expect(merged.results.extra?.key2).toBe('value2');

@@ -6,2 +6,4 @@ /**

/**
*
* @group Core Operations
* Parse a JSON string into a CTRFReport.

@@ -25,2 +27,4 @@ *

/**
*
* @group Core Operations
* Serialize a CTRFReport to a JSON string.

@@ -27,0 +31,0 @@ *

@@ -11,2 +11,4 @@ /**

/**
*
* @group Core Operations
* Parse a JSON string into a CTRFReport.

@@ -42,2 +44,4 @@ *

/**
*
* @group Core Operations
* Serialize a CTRFReport to a JSON string.

@@ -44,0 +48,0 @@ *

@@ -5,2 +5,4 @@ /**

/**
*
* @group Schema & Versioning
* The current version CTRF JSON Schema object.

@@ -16,2 +18,4 @@ *

/**
*
* @group Schema & Versioning
* Get the JSON Schema for a specific CTRF spec version.

@@ -31,2 +35,4 @@ *

/**
*
* @group Schema & Versioning
* Get the current spec version.

@@ -38,2 +44,4 @@ *

/**
*
* @group Schema & Versioning
* Get all supported spec versions.

@@ -40,0 +48,0 @@ *

@@ -34,2 +34,4 @@ /**

/**
*
* @group Schema & Versioning
* The current version CTRF JSON Schema object.

@@ -45,2 +47,4 @@ *

/**
*
* @group Schema & Versioning
* Get the JSON Schema for a specific CTRF spec version.

@@ -65,2 +69,4 @@ *

/**
*
* @group Schema & Versioning
* Get the current spec version.

@@ -74,2 +80,4 @@ *

/**
*
* @group Schema & Versioning
* Get all supported spec versions.

@@ -76,0 +84,0 @@ *

@@ -6,2 +6,4 @@ /**

/**
*
* @group Core Operations
* Calculate summary statistics from an array of tests.

@@ -8,0 +10,0 @@ *

@@ -5,2 +5,4 @@ /**

/**
*
* @group Core Operations
* Calculate summary statistics from an array of tests.

@@ -7,0 +9,0 @@ *

@@ -7,2 +7,4 @@ /**

* The root CTRF report object
*
* @group Core Types
*/

@@ -31,2 +33,4 @@ export interface CTRFReport {

* Container for test results
*
* @group Core Types
*/

@@ -47,2 +51,4 @@ export interface Results {

* Test tool information
*
* @group Core Types
*/

@@ -59,2 +65,4 @@ export interface Tool {

* Aggregated test statistics
*
* @group Core Types
*/

@@ -89,2 +97,4 @@ export interface Summary {

* Individual test result
*
* @group Core Types
*/

@@ -155,2 +165,4 @@ export interface Test {

* Test status enum
*
* @group Core Types
*/

@@ -160,2 +172,4 @@ export type TestStatus = 'passed' | 'failed' | 'skipped' | 'pending' | 'other';

* Details of a test retry attempt
*
* @group Core Types
*/

@@ -192,2 +206,4 @@ export interface RetryAttempt {

* File attachment
*
* @group Core Types
*/

@@ -206,2 +222,4 @@ export interface Attachment {

* Test step
*
* @group Core Types
*/

@@ -218,2 +236,4 @@ export interface Step {

* Environment information
*
* @group Core Types
*/

@@ -258,2 +278,4 @@ export interface Environment {

* Run-level insights computed from historical data
*
* @group Insights
*/

@@ -280,2 +302,4 @@ export interface Insights {

* Test-level insights computed from historical data
*
* @group Insights
*/

@@ -300,2 +324,4 @@ export interface TestInsights {

* Metric with current value, baseline, and change
*
* @group Insights
*/

@@ -312,2 +338,4 @@ export interface MetricDelta {

* Reference to a baseline report
*
* @group Core Types
*/

@@ -334,2 +362,4 @@ export interface Baseline {

* Result of schema validation
*
* @group Validation Options
*/

@@ -344,2 +374,4 @@ export interface ValidationResult {

* Details of a validation error
*
* @group Validation Options
*/

@@ -356,2 +388,4 @@ export interface ValidationErrorDetail {

* Options for merging reports
*
* @group Merge Options
*/

@@ -368,2 +402,4 @@ export interface MergeOptions {

* Criteria for filtering and finding tests.
*
* @group Query & Filter Options
*/

@@ -390,2 +426,4 @@ export interface FilterCriteria {

* Options for insights calculation
*
* @group Insights Options
*/

@@ -400,2 +438,4 @@ export interface InsightsOptions {

* Options for ReportBuilder
*
* @group Builder Options
*/

@@ -410,2 +450,4 @@ export interface ReportBuilderOptions {

* Options for TestBuilder
*
* @group Builder Options
*/

@@ -418,2 +460,4 @@ export interface TestBuilderOptions {

* Options for calculating summary
*
* @group Core Options
*/

@@ -428,2 +472,4 @@ export interface SummaryOptions {

* Options for parsing JSON
*
* @group Core Options
*/

@@ -436,2 +482,4 @@ export interface ParseOptions {

* Options for stringifying to JSON
*
* @group Core Options
*/

@@ -446,2 +494,4 @@ export interface StringifyOptions {

* Options for validation
*
* @group Validation Options
*/

@@ -448,0 +498,0 @@ export interface ValidateOptions {

@@ -9,2 +9,3 @@ /**

*
* @group Core Operations
* @param report - The object to validate

@@ -27,2 +28,4 @@ * @param options - Validation options (e.g., specific spec version)

/**
*
* @group Core Operations
* Check if a report is valid (type guard).

@@ -43,2 +46,4 @@ *

/**
*
* @group Core Operations
* Validate a report and throw if invalid (assertion).

@@ -63,2 +68,4 @@ *

/**
*
* @group Type Guards
* Checks if an object has the basic structure of a CTRF report.

@@ -81,2 +88,4 @@ * This is a quick, lightweight check that doesn't validate against the full schema.

/**
*
* @group Type Guards
* Type guard for Test objects.

@@ -93,2 +102,4 @@ *

/**
*
* @group Type Guards
* Type guard for TestStatus values.

@@ -101,2 +112,4 @@ *

/**
*
* @group Type Guards
* Type guard for RetryAttempt objects.

@@ -112,2 +125,4 @@ *

/**
*
* @group Type Guards
* Check if a report has insights.

@@ -114,0 +129,0 @@ *

@@ -12,2 +12,3 @@ /**

*
* @group Core Operations
* @param report - The object to validate

@@ -47,2 +48,4 @@ * @param options - Validation options (e.g., specific spec version)

/**
*
* @group Core Operations
* Check if a report is valid (type guard).

@@ -66,2 +69,4 @@ *

/**
*
* @group Core Operations
* Validate a report and throw if invalid (assertion).

@@ -94,2 +99,4 @@ *

/**
*
* @group Type Guards
* Checks if an object has the basic structure of a CTRF report.

@@ -115,2 +122,4 @@ * This is a quick, lightweight check that doesn't validate against the full schema.

/**
*
* @group Type Guards
* Type guard for Test objects.

@@ -132,2 +141,4 @@ *

/**
*
* @group Type Guards
* Type guard for TestStatus values.

@@ -143,2 +154,4 @@ *

/**
*
* @group Type Guards
* Type guard for RetryAttempt objects.

@@ -158,2 +171,4 @@ *

/**
*
* @group Type Guards
* Check if a report has insights.

@@ -160,0 +175,0 @@ *

{
"name": "ctrf",
"version": "0.0.18-next-1",
"version": "0.1.0",
"description": "CTRF reference implementation in TypeScript for creating and validating CTRF documents.",

@@ -45,4 +45,22 @@ "type": "module",

"homepage": "https://ctrf.io",
"author": "Matthew Thomas",
"author": "Matthew Poulton-White",
"license": "MIT",
"security": {
"email": "security@ctrf.io",
"url": "https://github.com/ctrf-io/security/blob/main/SECURITY.md"
},
"keywords": [
"test",
"testing",
"ctrf",
"reporter",
"report",
"json",
"standard",
"typescript",
"reference-implementation",
"test-results",
"validation",
"schema"
],
"dependencies": {

@@ -49,0 +67,0 @@ "ajv": "^8.17.1",

+18
-12

@@ -5,19 +5,21 @@ # CTRF Reference Implementation TypeScript

## Open Standard
## CTRF Open Standard
[CTRF](https://github.com/ctrf-io/ctrf) is an open standard built and shaped by community contributions.
CTRF is a community-driven open standard for test reporting.
Your feedback and contributions are essential to the project's success:
By standardizing test results, reports can be validated, merged, compared, and analyzed consistently across languages and frameworks.
- [Contribute](CONTRIBUTING.md)
- [Discuss](https://github.com/orgs/ctrf-io/discussions)
- **CTRF Specification**: https://github.com/ctrf-io/ctrf
The official specification defining the format and semantics
- **Discussions**: https://github.com/orgs/ctrf-io/discussions
Community forum for questions, ideas, and support
## Support
> [!NOTE]
> ⭐ Starring the **CTRF specification repository** (https://github.com/ctrf-io/ctrf)
> helps support the standard.
You can support the project by giving this repository a star ⭐
## Installation
```sh
npm install ctrf@0.0.18-next-1
npm install ctrf
```

@@ -56,3 +58,3 @@

> 📚 **Full API Documentation:** [API Reference](../docs/README.md)
> 📚 **Full API Documentation:** [API Reference](/docs/README.md)

@@ -157,6 +159,6 @@ ### Types

```typescript
import { mergeReports } from 'ctrf'
import { merge } from 'ctrf'
// Merge multiple reports into one
const merged = mergeReports([report1, report2, report3], {
const merged = merge([report1, report2, report3], {
deduplicateTests: true, // Remove duplicate tests by ID

@@ -267,1 +269,5 @@ })

```
## ⚠️ Upgrading from v0.0.17?
**Version 0.1.0 contains breaking changes.** See the [Migration Guide](MIGRATION.md) for detailed upgrade instructions.

@@ -173,3 +173,3 @@ # CTRF TypeScript SDK

// Merge multiple reports into one
const merged = ctrf.mergeReports([report1, report2, report3], {
const merged = ctrf.merge([report1, report2, report3], {
deduplicateTests: true, // Remove duplicate tests by ID

@@ -176,0 +176,0 @@ })