Back to Repositories

Testing Mock Server Route Operations in Insomnia

This test suite validates the mock route functionality in Insomnia’s testing infrastructure. It focuses on creating, modifying, and testing mock server routes while ensuring proper HTTP responses and console interactions.

Test Coverage Overview

The test suite provides comprehensive coverage of mock server route operations in Insomnia.

Key functionality tested includes:
  • Mock server creation and initialization
  • Route creation and modification
  • Route renaming capabilities
  • HTTP response validation
  • Console output verification

Implementation Analysis

The test implements a Playwright-based approach for end-to-end testing of Insomnia’s mock server functionality. It utilizes page object interactions and async/await patterns for reliable test execution.

Technical implementation features:
  • Platform-specific test speed adjustments
  • Role-based element selection
  • Label and text-based element targeting
  • Sequential action verification

Technical Details

Testing tools and configuration:
  • Playwright test runner
  • Platform-specific test configurations
  • Custom label selectors
  • Role-based element targeting
  • HTTP/2 response validation
  • Console output monitoring

Best Practices Demonstrated

The test demonstrates several quality testing practices for UI automation.

Notable practices include:
  • Clear test scenario isolation
  • Robust element selection strategies
  • Platform-aware test configuration
  • Step-by-step action verification
  • Response validation
  • Console output verification

kong/insomnia

packages/insomnia-smoke-test/tests/smoke/mock.test.ts

            
import { test } from '../../playwright/test';

test('can make a mock route: WARNING: THIS TEST DEPENDS ON mock.insomnia.moe to be up', async ({ page }) => {
  test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');

  await page.getByLabel('New Mock Server').click();
  await page.getByRole('button', { name: 'Create', exact: true }).click();
  await page.getByRole('button', { name: 'New Mock Route' }).click();
  await page.locator('#prompt-input').fill('/123');
  await page.getByRole('button', { name: 'Create' }).click();
  await page.getByLabel('Mock Route Actions').click();
  await page.getByText('Rename').click();
  await page.locator('#prompt-input').fill('/456');
  await page.getByRole('button', { name: 'Rename' }).click();

  await page.getByRole('button', { name: 'Test' }).click();
  await page.getByText('No body returned for response').click();
  await page.getByRole('tab', { name: 'Console' }).click();
  await page.getByText('HTTP/2 200').click();
});