Image Upload & Thumbnails Tutorial · Module 08 of 11

Testing & Quality Assurance

Write comprehensive tests: unit tests for transformations, integration tests for upload workflow, malware detection tests, thumbnail generation tests. Test with various image formats and sizes. Coverage > 85%. By the end, image handling is well-tested and reliable.

~3–4 hrsIntermediateTesting focus
← Back to Module 08 overview
What You'll Have at the End

Definition of Done

  • Unit tests: Transformation logic (resize, blur, filters), metadata extraction, validation.
  • Integration tests: Upload endpoint, thumbnail generation, S3 storage.
  • Edge case tests: Large files, malformed files, invalid MIME types, corrupted images.
  • Format tests: JPEG, PNG, WebP with various dimensions.
  • Performance tests: Upload 10MB file completes in < 2 sec, thumbnail generation in < 500ms.
  • Coverage > 85% for core image handling logic.
The Steps

Build It

STEP 1

Set up Jest testing framework

Install: npm install --save-dev jest ts-jest @types/jest testcontainers

Create jest.config.js:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['/src'],
  testMatch: ['**/__tests__/**/*.test.ts'],
  collectCoverageFrom: [
    'src/**/*.ts',
    '!src/**/*.d.ts',
    '!src/index.ts'
  ],
  coverageThreshold: {
    global: { branches: 80, functions: 85, lines: 85, statements: 85 }
  }
};