Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Mocked type is missing in @suites/unit #426

Closed
2 of 4 tasks
michaelcai opened this issue Sep 3, 2024 · 7 comments
Closed
2 of 4 tasks

Mocked type is missing in @suites/unit #426

michaelcai opened this issue Sep 3, 2024 · 7 comments
Assignees
Labels
bug Something isn't working hacktoberfest Hacktoberfest

Comments

@michaelcai
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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?

  • macOS
  • Windows
  • Linux

Other

No response

@omermorad
Copy link
Collaborator

Hi,

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

@omermorad omermorad added hacktoberfest Hacktoberfest bug Something isn't working labels Sep 17, 2024
@roniavi
Copy link

roniavi commented Sep 23, 2024

Plus one on this @omermorad 🙏

@qballer
Copy link
Collaborator

qballer commented Sep 27, 2024

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

@qballer qballer self-assigned this Sep 27, 2024
@omermorad
Copy link
Collaborator

@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
Copy link
Collaborator

qballer commented Oct 2, 2024

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.

@omermorad omermorad changed the title Mocked type is missing in '@suites/unit' Mocked type is missing in @suites/unit Oct 4, 2024
@qballer
Copy link
Collaborator

qballer commented Oct 4, 2024

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?

yarnpkg/yarn#5476

jeffrey-jian added a commit to CS3219-AY2425S1/cs3219-ay2425s1-project-g30 that referenced this issue Oct 5, 2024
### Description

This pull request refactors the questions-service to adopt the
**hexagonal architecture**, separating business logic from database
concerns and improving testability.

![Question Hexagonal Architecture drawio
(2)](https://github.com/user-attachments/assets/3949985f-6859-48b0-b1dc-7179dccb4442)


### Changes made

- Created the `questions.repository.ts` abstract class
- existing `questions.service.ts` now depends on this new abstract class
to handle database operations
  
- Moved supabase-related methods to its own class:
`questions.supabase.ts`
  - implements `questions.repository.ts`
 

### New directory structure
```text
src/
├── adapters/
│   └── controllers/
│   │   └── questions.controller.ts
│   └── db/
│       └── questions.supabase.ts
├── domains/
│   └── ports/
│       ├── questions.repository.ts
│       └── questions.service.ts
├── questions.module.ts
└── main.ts
```


### Future enhancements

**Testing**
- `nestjs` recommends using
[automock](https://docs.nestjs.com/recipes/automock#introduction)
library (now called suites) for testing, but there are issues with the
library at the moment.
- I'll incorporate unit tests into our microservices once the this
[issue](suites-dev/suites#426) has been
resolved (I've tried using their suggested workaround, it doesn't work)
@suites-dev suites-dev deleted a comment from qballer Oct 9, 2024
@omermorad
Copy link
Collaborator

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

Due to a known issue with Yarn v1.x's postinstall script handling (yarnpkg/yarn#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.

@suites-dev suites-dev locked and limited conversation to collaborators Oct 18, 2024
@omermorad omermorad converted this issue into discussion #473 Oct 18, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working hacktoberfest Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants