Skip to content

Add unit tests for Amplify Next.js template#12

Open
ghostyappbeta[bot] wants to merge 1 commit intomainfrom
add-unit-tests-v2
Open

Add unit tests for Amplify Next.js template#12
ghostyappbeta[bot] wants to merge 1 commit intomainfrom
add-unit-tests-v2

Conversation

@ghostyappbeta
Copy link
Copy Markdown

@ghostyappbeta ghostyappbeta bot commented Feb 21, 2026

This pull request was generated by @kiro-agent 👻

Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent


Summary

Adds a comprehensive unit test suite for the Amplify Next.js template repository using Node.js 22's built-in test runner (node:test). No external testing dependencies are required.

Changes

  • 6 test files with 30 passing tests covering all source modules
  • Added test script to package.json
  • Tests cover:
    • amplify/auth/resource.ts — verifies auth configuration with email login
    • amplify/data/resource.ts — verifies data schema definition and authorization rules
    • amplify/backend.ts — verifies backend configuration imports and structure
    • app/layout.tsx — verifies metadata, root layout exports, and HTML structure
    • app/page.tsx — verifies client directive, Amplify configuration, todo CRUD operations, and component structure
    • next.config.js — verifies Next.js configuration export

Testing Approach

  • Module mocking with mock.module() for pure .ts Amplify resource files — tests actual module behavior by mocking @aws-amplify/backend
  • Structural analysis via readFileSync for .tsx files — verifies code correctness without needing a JSX parser
  • Direct require() for next.config.js

How to run

npm test

Notes

  • Uses Node.js built-in --experimental-strip-types and --experimental-test-module-mocks flags
  • Zero additional npm dependencies needed

Add comprehensive unit tests for all source files using node:test module
with --experimental-strip-types for TypeScript and --experimental-test-module-mocks
for module mocking. No npm packages required.

Tests cover:
- amplify/auth/resource.ts: verifies defineAuth called with email login config
- amplify/data/resource.ts: verifies schema with Todo model and apiKey auth
- amplify/backend.ts: verifies imports and defineBackend assembly
- app/layout.tsx: verifies metadata export (title, description)
- app/page.tsx: verifies component structure, imports, and Amplify integration
- next.config.js: verifies empty config export

All 30 tests pass with 0 failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants