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

@Body transform issue: The metatype property of the 2nd Arg to ValidationPipe.transform(v, metadata) is undefined during jest e2e supertest run. #13108

Closed
5 of 12 tasks
m-fire opened this issue Jan 28, 2024 · 8 comments
Labels
needs triage This issue has not been looked into

Comments

@m-fire
Copy link

m-fire commented Jan 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

1. Typical app runs or standalone E2E supertest situations:

image

2-1. Nested request API scenario testing situations:

image

2-2. ValidationPipe.transform Status:

image

Minimum reproduction code

  1. CodeSandbox
  2. GitHub repository

Steps to reproduce

  1. Run npm run test:e2e, check the result: success2, failure3
  2. DTO transform success tests. path: test/module/auth/feature
    • /sign-in-user.api.test.ts
    • /sign-up-user.api.test.ts
  3. Failed tests. path: test/module/board/feature
    • /register-board.api.test.ts
    • /register-comment.api.test.ts
    • /get-comment-list.api.test.ts
  4. debug the request method in src/module/auth/feature/sign-in-user.api.ts for each test
  5. the undefined check in the title should be checked in the ValidationPipe.transform() method.

Expected behavior

ValidationPipe should have no problem converting DTOs through @Body. It's too unreliable.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.1

Packages versions


### Node.js version

20.11.0

### In which operating systems have you tested?

- [ ] macOS
- [X] Windows
- [ ] Linux

### Other

[System Information]
OS Version     : Windows 10.0.22631
NodeJS Version : v20.11.0
NPM Version    : 9.6.7 

[Nest CLI]
Nest CLI Version : 10.3.0

[Nest Platform Information]
platform-express version : 10.3.1
mapped-types version     : 2.0.4
serve-static version     : 4.0.0
schematics version       : 10.1.0
passport version         : 10.0.3
typeorm version          : 10.0.1
testing version          : 10.3.1
common version           : 10.3.1
config version           : 3.1.1
core version             : 10.3.1
jwt version              : 10.2.0
cli version              : 10.3.0

[Warnings]
The following packages are not in the same minor version
This could lead to runtime errors
* Under version 10.3
- @nestjs/platform-express 10.3.1
- @nestjs/common 10.3.1
- @nestjs/core 10.3.1
* Under version 10.1
- @nestjs/schematics 10.1.0
@m-fire m-fire added the needs triage This issue has not been looked into label Jan 28, 2024
@micalevisk
Copy link
Member

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

@m-fire
Copy link
Author

m-fire commented Jan 29, 2024

@micalevisk May I request a review? I've updated the minimal reproduction comments and reproduction procedure above, and I've posted sample code as you suggested - it's a minimal scenario test, so there's a lot of source code.

@m-fire
Copy link
Author

m-fire commented Jan 29, 2024

@micalevisk I think this issue is related to the import/export behavior of Typescript. What do you think? I think it's right, it suddenly started working again 😑. All import/export code is working fine during the overhaul. I've had a hard time with this, you've had a hard time, so you can rest now.😌

@m-fire m-fire closed this as completed Jan 29, 2024
@micalevisk
Copy link
Member

I've no ideia 🤔

@m-fire
Copy link
Author

m-fire commented Jan 29, 2024

This is the second time this has happened to me.

in src/module/auth/feature/sign-in-user.api.ts

before

: The Request was placed inside the auth module outside the Api class.
import { AuthToken, SignInUserRequest } from '@src-module/auth/feature'

after

: Located in the same folder as the API class
import { SignInUserRequest } from './sign-in-user.request'

I thought it was fixed. It was my mistake. It's hard...

@m-fire
Copy link
Author

m-fire commented Jan 29, 2024

I'll commit the rest of the code to the repository to reflect this, so take a look when you need to.

@m-fire
Copy link
Author

m-fire commented Jan 29, 2024

Let's reopen it first.
because it's impossible to reproduce what happened😑. I don't know how it was fixed.
I don't think it's just an import/export issue with Typescript. I feel like I'm getting lost in a maze...

@m-fire m-fire reopened this Jan 29, 2024
@kamilmysliwiec
Copy link
Member

I'm sure it's just an import/export issue, possibly caused by barrel files (index.ts) introducing a cyclic import in your code, leading to TS metadata being undefined in a specific context

@nestjs nestjs locked and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

3 participants