suites-dev / suites

A testing meta-framework that simplifies unit testing by reducing boilerplate code and enabling developers to build comprehensive and reliable test suites
https://suites.dev
Apache License 2.0
361 stars 12 forks source link

`Mocked` type is missing in `@suites/unit` #426

Closed michaelcai closed 2 weeks ago

michaelcai commented 2 months ago

Is there an existing issue for this?

Current behavior

Description: The @suites/unit package does not export the Mocked type as expected. When trying to import the Mocked type from @suites/unit using:

import { TestBed, Mocked } from '@suites/unit';

I receive the following error message: Module '"@suites/unit"' has no exported member named 'Mocked'.

Minimum reproduction code

no

Steps to reproduce

No response

Expected behavior

Please include the Mocked type in the package's exports, or provide documentation for an alternative way to mock objects if the Mocked type has been deprecated or replaced.

Suites version

3.0.0

Node.js version

20.16.0

In which operating systems have you tested?

Other

No response

omermorad commented 1 month ago

Hi,

Thank you for submitting this issue. I'll take a look and update here soon!

roniavi commented 1 month ago

Plus one on this @omermorad 🙏

qballer commented 1 month ago

I will look into this issue in October and try and solve it.

omermorad commented 1 month ago

@roniavi @michaelcai - While @qballer works to resolve this problem, please try the following workaround:

Try importing Mocked from @suites/doubles.x instead of @suites/unit. (In this case, @suites/doubles.jest).

import type { Mocked } from '@suites/doubles.jest';

This is a workaround; in order to maintain consistency and library agnostic behavior (mocking library), the Mocked type should essentially be imported from @suites/unit. You may easily modify it back to be imported from @suites/unit after the bug has been fixed.

Tell me whether it was successful please :)

qballer commented 1 month ago

https://github.com/qballer/suites_issue_426 I was able to reconstruct the bug in the above repo relatively easily. I will dig into why this is happening later.

qballer commented 1 month ago

I reconstructed the bug in the exact way described in the issue.

https://github.com/qballer/suites_issue_426

It works out of the box as expected, but after installing an additional package (e.g yarn add get-port), for some reason, the following is missing: in
/node_modules/@suites/unit/dist/cjs/index.d.ts

Is missing: /// <reference types="@suites/doubles.jest/unit" />

The same triple slash is missing in node_modules/@suites/unit/dist/esm/index.d.ts

Manually adding that to the d.ts file fixes the problem.

I've also noticed that the following is missing from node_modules/@suites/types.di/typings.d.ts, which is export type IdentifierMetadata = import('@suites/di.nestjs').IdentifierMetadata;

Digging through the code, these are all added via post-install scripts of doubles.x and di.x. It looks like the fault is yarn for not running post-install script. this isn't happening in npm for example.

Which yarn version is being used?

https://github.com/yarnpkg/yarn/issues/5476

omermorad commented 4 weeks ago

@michaelcai @jeffrey-jian @roniavi (also related to #439 - @mbrunoviegas)

Due to a known issue with Yarn v1.x's postinstall script handling (https://github.com/yarnpkg/yarn/issues/5476), an extra step is required to set up reference types for your project. I've updated the docs, please follow: https://suites.dev/docs/overview/installation#for-yarn-v1x-users.

Please, let me know if it worked for you.