Skip to content

Add End-to-End Testing Infrastructure with Playwright #986

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IliasHad
Copy link

@IliasHad IliasHad commented Mar 7, 2025

Add End-to-End Testing Infrastructure with Playwright

Summary

This PR adds a comprehensive end-to-end testing infrastructure to the Shopify Remix template using Playwright. It includes MSW (Mock Service Worker) for mocking Shopify API responses, a custom Shopify test harness for authentication, and initial test examples.

Motivation

End-to-end testing is essential for ensuring the reliability of Shopify apps. This implementation allows developers to:

  • Test the full app flow in an isolated environment
  • Mock Shopify API responses without requiring a real store connection
  • Validate UI components and user interactions
  • Ensure changes don't break existing functionality

Implementation Details

Core Components:

  1. Mock Service Worker Configuration:

    • Added handlers for simulating Shopify GraphQL and REST API responses
    • Implemented product creation and variant update mocks
  2. Custom Shopify Test Harness:

    • Created a specialized Playwright test extension with Shopify authentication
    • Handles JWT token generation and session management
    • Provides automatic cleanup after tests
  3. Environment Configuration:

    • Added .env.testing support for test-specific environment variables
    • Validates required environment variables before tests run
  4. Example Tests:

    • Implemented basic navigation and UI interaction tests
    • Demonstrated testing of product generation workflow

File Changes:

  • tests/constants/index.ts: Added constants for test shop and API version
  • tests/mocks/node.ts: Setup MSW server for Node.js environment
  • tests/mocks/handlers.ts: Implemented GraphQL and REST API mock handlers
  • tests/global/shopify.ts: Created custom Shopify test harness
  • tests/e2e/example.spec.ts: Added example test cases
  • .env.testing.example: Added example environment file for testing

How to Test

  1. Copy .env.testing.example to .env.testing and fill in your Shopify API credentials
  2. Run tests with npm run test

@IliasHad IliasHad requested a review from a team as a code owner March 7, 2025 21:40
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.

1 participant