nest
nest copied to clipboard
fix(testing): add fallback option to file type validator
trafficstars
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [x] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
Currently, the FileTypeValidator fails when file-type is unable to determine the MIME type — particularly for file formats with undetectable signatures. This can cause valid uploads to fail unexpectedly.
Additionally, the related unit test did not cover scenarios involving fallback logic or validator option validation.
Issue Number: #15055
What is the new behavior?
- Added mimeTypeFallback support to the FileTypeValidator to allow more resilient handling when file-type cannot detect MIME.
- Improved the test case in parse-file-pipe.builder.spec.ts to assert that validator options (including mimeTypeFallback) are properly passed and used.
- Updated package.json:
- Downgraded redis from v5 (ESM-only) to ^4.7.1 for compatibility.
- Moved redis from devDependencies to dependencies.
- Ensured backwards compatibility with existing file validation logic.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
This PR resolves compatibility issues related to MIME type detection and improves developer experience by making file validation more fault-tolerant in real-world uploads. It also keeps dependencies aligned with current CommonJS-based usage patterns.