Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next (temp) [WIP] #99

Closed
wants to merge 7 commits into from
Closed

next (temp) [WIP] #99

wants to merge 7 commits into from

Conversation

omermorad
Copy link
Collaborator

@omermorad omermorad commented Aug 22, 2023

Major Refactor and Enhancement of Automock Core and Adapters

This PR introduces significant changes to the Automock library, aiming to enhance its adaptability, maintainability, and user experience. The changes are a culmination of feedback, continuous integration testing, and the need to support a broader spectrum of use-cases.

Key Changes:

  1. Refactoring of Core Mechanisms:

    • Transitioned from using dependency maps to dependency containers, streamlining the internal logic and improving integration with DI frameworks.
    • Major interface changes, especially around UnitReference, to support symbols and provide more accurate generic parameters.
    • Introduced the AutomockDependenciesAdapter interface, paving the way for more extensible and customizable adapter mechanisms.
  2. Enhancements to Adapters:

    • The NestJS adapter has been overhauled to work seamlessly with the new AutomockDependenciesAdapter interface.
    • Removed the native adapter from both Jest and Sinon packages, focusing on a more unified approach to mocking.
    • Added support for @types/sinon as a peer dependency.
  3. Improvements in Common Utilities:

    • Several interfaces have been removed or refactored for clarity and simplicity.
    • Introduced ConstantValue as a replacement for PrimitiveValue, providing a clearer distinction for values that remain unchanged during tests.
  4. Documentation and Typing:

    • Enhanced JSDoc comments across the board for better clarity and developer experience.
    • Refactored several type definitions to be more intuitive and accurate.
  5. Breaking Changes:

    • Numerous breaking changes have been introduced, especially in terms of removed interfaces and changed mechanisms. It's recommended to refer to the detailed list of changes and adapt your codebase accordingly.

…anism

- Entirely restructure the package to align with the updated adapters design, emphasizing container-based operations over map-based approaches.

BREAKING CHANGE: - Eliminate multiple interfaces and types to streamline the package:
  - `ClassDependencies`
  - `ClassCtorInjectables`
  - `ClassInjectableProperty`
  - `ClassPropsInjectables`
  - `ClassDependenciesMap`
  - `DependenciesReflector`
- Transition from `PrimitiveValue` to the more descriptive `ConstantValue`.
- Implement a revamped mechanism for the NestJS adapter, aligning with the new `AutomockDependenciesAdapter` interface.

BREAKING CHANGE: - Replace `DependenciesReflector` with the more versatile `AutomockDependenciesAdapter`.
- Modify export strategy: Shift from native literal export to default module export.
- Revamp the `UnitReference` interface to:
  - Incorporate symbols as identifiers.
  - Offer more precise generic parameters.

- Reorganize core types for better modularity:
  - Relocate `Type` to `@automock/types`.
  - Shift `UnitTestBed` to `@automock/core`.

- Adjust package dependencies:
  - Exclude `@automock/adapters.nestjs` from the npm dependencies in `package.json`.
  - Introduce `@types/sinon` as a peer dependency.

BREAKING CHANGE: - Users will need to adjust their imports due to the migration of `Type` and `UnitTestBed`.
- Adherence to the updated `UnitReference` interface might be necessary.
- Dependency changes may require updates in user projects.
- Revise the `UnitReference` interface to:
  - Support symbols as identifiers.
  - Provide more accurate generic parameters.

- Relocate core types for better organization:
  - Move `Type` to `@automock/types`.
  - Transfer `UnitTestBed` to `@automock/core`.

- Cleanup package dependencies:
  - Remove `@automock/adapters.nestjs` from the npm dependencies in `package.json`.

- Simplify and declutter:
  - Introduce a new, streamlined `UnitReference` interface.
  - Eliminate the `@Reflectable` decorator.
  - Remove redundant types: `MockFunction`, `Override`, and `TestBedResolver`.

BREAKING CHANGE: - Users will need to update their imports due to the relocation of `Type` and `UnitTestBed`.
- Adjustments may be required for the new `UnitReference` interface.
- Removal of certain decorators and types might affect existing implementations.
BREAKING CHANGE: - Remove `TClass` generic arg from `StubbedInstance`
- Refactor `DeepPartial`, remove arrays from it
- Adopt a dependencies container approach over the previous dependencies map.
- Introduce custom Automock errors for better error clarity.
- Refine the `UnitReference` interface for improved type safety.
- Utilize `require` with default in the package resolver.
- Add integration tests to validate new changes.
- Enhance JSDoc comments for better clarity.
- Update terminology: Replace "primitive" with "constant value".
- Remove redundant warning about undefined dependency values.
- Adjust error messages for more accurate feedback on invalid dependencies.
- Introduce error handling for invalid dependency identifiers in `.mock()`.

BREAKING CHANGE: - Transition from native `Error` to `InvalidIdentifierError` in `UnitReference`.
- Update `UnitReference.get()` to return both ConstantValue and StubbedInstance.
@codecov-commenter
Copy link

Codecov Report

Merging #99 (f7c691c) into master (0576ae5) will increase coverage by 0.97%.
The diff coverage is 91.57%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master      #99      +/-   ##
==========================================
+ Coverage   88.02%   89.00%   +0.97%     
==========================================
  Files          13       10       -3     
  Lines         192      200       +8     
  Branches       29       32       +3     
==========================================
+ Hits          169      178       +9     
+ Misses         19       15       -4     
- Partials        4        7       +3     
Flag Coverage Δ
adapters.nestjs 89.00% <91.57%> (+0.97%) ⬆️
core 89.00% <91.57%> (+0.97%) ⬆️
jest 89.00% <91.57%> (+0.97%) ⬆️
sinon 89.00% <91.57%> (+0.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
packages/adapters/nestjs/src/class-reflector.ts 81.81% <77.77%> (-18.19%) ⬇️
packages/core/src/services/package-resolver.ts 85.00% <83.33%> (-15.00%) ⬇️
packages/core/src/services/unit-reference.ts 85.71% <83.33%> (-14.29%) ⬇️
...kages/adapters/nestjs/src/params-token-resolver.ts 77.27% <85.71%> (ø)
packages/core/src/services/testbed-builder.ts 93.75% <90.00%> (-6.25%) ⬇️
...ckages/adapters/nestjs/src/class-ctor-reflector.ts 95.65% <100.00%> (+0.19%) ⬆️
...kages/adapters/nestjs/src/class-props-reflector.ts 100.00% <100.00%> (ø)
...estjs/src/property-reflection-strategies.static.ts 74.07% <100.00%> (ø)
packages/core/src/services/mocks-container.ts 100.00% <100.00%> (ø)
packages/core/src/services/unit-mocker.ts 100.00% <100.00%> (+7.40%) ⬆️

... and 3 files with indirect coverage changes

@omermorad omermorad closed this Aug 22, 2023
@omermorad omermorad deleted the next-new branch October 5, 2023 08:10
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.

2 participants