Skip to content

Add comprehensive unit tests for @leanmcp/core (Issue #8) - #51

Merged
rosaboyle merged 1 commit into
Leanmcp:mainfrom
Erebuzzz:feature/add-core-unit-tests
Feb 7, 2026
Merged

Add comprehensive unit tests for @leanmcp/core (Issue #8)#51
rosaboyle merged 1 commit into
Leanmcp:mainfrom
Erebuzzz:feature/add-core-unit-tests

Conversation

@Erebuzzz

@Erebuzzz Erebuzzz commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Description

Adds 106 comprehensive unit tests for the @leanmcp/core package, covering all core decorators, validation utilities, and schema generation features. Also fixes Jest configuration to properly locate test files.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this change manually

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Related Issues

Fixes #8 (Add Core Decorator Tests from GOOD_FIRST_ISSUES.md)

Screenshots (if applicable)

N/A - Test files only

Additional Notes

  • jest.config.js fix: Changed roots from ['<rootDir>/src', '<rootDir>/test'] to ['<rootDir>/tests', '<rootDir>/packages'] to match actual project structure
  • Schema decorator tests define decorators inline to avoid ESM compatibility issues with type-parser.ts

- Add decorators.test.ts (40 tests for all core decorators)

- Add validation.test.ts (53 tests for validation utilities)

- Add schema-generator.test.ts (14 tests for schema decorators)

- Fix jest.config.js roots to match project structure
Copilot AI review requested due to automatic review settings February 6, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a broad unit test suite for @leanmcp/core and updates the root Jest configuration so the repository’s test runner discovers the new tests under the actual project layout.

Changes:

  • Added unit tests for core validation utilities (validatePort, validatePath, validateServiceName, validateNonEmpty, validateUrl).
  • Added unit tests for core decorators and helper functions (Tool, Prompt, Resource, Auth, UI, Render, Deprecated, UserEnvs, getMethodMetadata, getDecoratedMethods).
  • Updated root jest.config.js roots to match the repo’s tests/ and packages/ structure.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/unit/validation.test.ts Adds unit coverage for core validation helpers and expected error behavior.
tests/unit/schema-generator.test.ts Adds tests for schema-related decorator metadata behavior (implemented inline).
tests/unit/decorators.test.ts Adds unit coverage for core decorators and metadata helper functions.
jest.config.js Updates Jest roots to ensure test discovery matches the repository layout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,554 @@
import 'reflect-metadata';
import { describe, it, expect, beforeEach } from '@jest/globals';

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterEach and the jest object are used later in this file, but neither is imported from @jest/globals. Given this file already opts into explicit Jest imports, this can break when injectGlobals is disabled and can also cause TS type errors with the current tsconfig types settings. Import afterEach (and jest, if you want to reference jest.SpyInstance / jest.spyOn) from @jest/globals to make the test self-contained.

Suggested change
import { describe, it, expect, beforeEach } from '@jest/globals';
import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals';

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +32

// ============================================================================
// Schema Decorator Tests
// These tests directly test the decorator behavior using only reflect-metadata
// without importing schema-generator.ts (which has ESM-only dependencies)
// ============================================================================

// Define decorators inline to avoid ESM import issues with type-parser.ts
function Optional(): PropertyDecorator {
return (target, propertyKey) => {
Reflect.defineMetadata('optional', true, target, propertyKey);
};
}

function SchemaConstraint(constraints: {
minLength?: number;
maxLength?: number;
minimum?: number;
maximum?: number;
pattern?: string;
enum?: any[];
description?: string;
default?: any;
type?: string;
}): PropertyDecorator {
return (target, propertyKey) => {
Reflect.defineMetadata('schema:constraints', constraints, target, propertyKey);
};
}

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests re-implement Optional and SchemaConstraint locally instead of importing them from packages/core/src/schema-generator.ts. This means the tests can pass even if the real decorators change, so they aren’t actually exercising the exported API. Consider extracting the decorators into a small module with no ESM-only dependencies (e.g. schema-decorators.ts) and importing that here, or adjusting the Jest/ts-jest setup to handle the ESM dependency chain so you can test the real exports.

Suggested change
// ============================================================================
// Schema Decorator Tests
// These tests directly test the decorator behavior using only reflect-metadata
// without importing schema-generator.ts (which has ESM-only dependencies)
// ============================================================================
// Define decorators inline to avoid ESM import issues with type-parser.ts
function Optional(): PropertyDecorator {
return (target, propertyKey) => {
Reflect.defineMetadata('optional', true, target, propertyKey);
};
}
function SchemaConstraint(constraints: {
minLength?: number;
maxLength?: number;
minimum?: number;
maximum?: number;
pattern?: string;
enum?: any[];
description?: string;
default?: any;
type?: string;
}): PropertyDecorator {
return (target, propertyKey) => {
Reflect.defineMetadata('schema:constraints', constraints, target, propertyKey);
};
}
import { Optional, SchemaConstraint } from '../../packages/core/src/schema-generator';
// ============================================================================
// Schema Decorator Tests
// These tests directly test the decorator behavior using the real decorators
// exported from schema-generator.ts so that changes to the implementation are
// covered by these tests.
// ============================================================================

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Erebuzzz , what copilot is telling makes sense. The whole point of unit test to make sure the existing one is functioning as needed.

Also, what is the issue with testing on ESM decorators?

@rosaboyle
rosaboyle merged commit 896dc7d into Leanmcp:main Feb 7, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants