Skip to content

Feature Request: Add unregisterAllSchemas() to clean up registered schemas in test suites #122

@Suyog241005

Description

@Suyog241005

Context

While contributing to and working with the repository, I noticed that all the test files (lib/schema.spec.ts) have to manually track and unregister every single registered schema inside their afterEach hooks:

afterEach(() => {
  unregisterSchema(`${testDomain}/schema`);
  unregisterSchema(`${testDomain}/relative-schema`);
  unregisterSchema(`https://example.com/schema`);
});

The Problem

Currently, there is no public API to clear or flush the entire schema registry at once.

If any one forgets to unregister even a single schema in a spec file, that schema leaks into all subsequent tests. This results in state pollution, making it difficult to guarantee test isolation and potentially causing unpredictable test failures depending on the execution order.

Proposed Solution

Exposing a simple, top-level unregisterAllSchemas() function would solve this perfectly. It would allow developers to completely reset the registry's state.

We can define it by leveraging the existing getAllRegisteredSchemaUris() and unregisterSchema(uri) methods:

export const unregisterAllSchemas = () => {
  for (const uri of getAllRegisteredSchemaUris()) {
    unregisterSchema(uri);
  }
};

This would:

  1. Provide a standard, robust way to reset the registry.
  2. Drastically simplify the repository's own unit tests by replacing repetitive unregisterSchema lists with a single unregisterAllSchemas() call.

Please let me know if this looks like a valid addition! I would be very happy to implement this and open a PR to clean up the test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions