NestJS Unit Test and E2E Test File Placement

Tadashi Shigeoka ·  Tue, May 18, 2021

I researched the placement of Unit Test and E2E Test files in NestJS, so I’ll introduce what I found.

NestJS

Prerequisites: NestJS v7.6.17

git clone [email protected]:nestjs/nest.git
cd nest
git checkout refs/tags/v7.6.17

NestJS Unit Test File Placement: Co-located Under src/

After checking NestJS sample code, I decided to adopt the policy of co-locating them under src/.

$ find sample/* -name "*.spec.ts"
sample/01-cats-app/src/cats/cats.controller.spec.ts
sample/19-auth-jwt/src/auth/auth.service.spec.ts
sample/19-auth-jwt/src/app.service.spec.ts
sample/19-auth-jwt/src/app.controller.spec.ts
sample/19-auth-jwt/src/users/users.service.spec.ts
sample/25-dynamic-modules/src/config/config.service.spec.ts
sample/25-dynamic-modules/src/app.controller.spec.ts
sample/26-queues/src/app.controller.spec.ts
sample/27-scheduling/src/app.controller.spec.ts
sample/30-event-emitter/src/app.controller.spec.ts

NestJS E2E Test File Placement: Under e2e/

After checking NestJS sample code, I decided to adopt the policy of placing them under e2e/.

$ find sample/* -name "e2e"
sample/01-cats-app/e2e
sample/19-auth-jwt/e2e
sample/29-file-upload/e2e

That’s all from the Gemba about investigating the placement of Unit Test and E2E Test files in NestJS.