Back to Repositories

Testing gRPC Server Reflection Capabilities in Insomnia

This test suite validates gRPC request functionality with reflection in the Insomnia API client. It focuses on testing unary gRPC calls using server reflection capabilities, ensuring proper request handling and response validation.

Test Coverage Overview

The test suite covers essential gRPC functionality with a focus on server reflection capabilities.

Key areas tested include:
  • gRPC request sending with reflection enabled
  • Method selection and validation
  • Unary request processing
  • Response status verification
  • Response body content validation

Implementation Analysis

The testing approach utilizes Playwright’s testing framework to simulate user interactions with the Insomnia API client. The implementation employs fixture loading for test data and leverages platform-specific considerations for test execution timing.

Technical patterns include:
  • Clipboard-based fixture loading
  • Dynamic UI interaction simulation
  • Asynchronous response validation
  • Platform-specific test speed adjustments

Technical Details

Testing tools and configuration:
  • Playwright test framework
  • Custom fixture loading utilities
  • TestID-based element selection
  • Response status and body validation
  • Platform-specific test configurations
  • CodeMirror integration testing

Best Practices Demonstrated

The test implementation showcases high-quality testing practices for complex API client functionality.

Notable practices include:
  • Explicit wait conditions for UI elements
  • Clear test data separation using fixtures
  • Robust element selection strategies
  • Platform-specific test accommodations
  • Comprehensive response validation

kong/insomnia

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

            
import { expect } from '@playwright/test';

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

test('can send gRPC requests with reflection', async ({ app, page }) => {
  test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');
  const statusTag = page.locator('[data-testid="response-status-tag"]:visible');
  const responseBody = page.locator('[data-testid="response-pane"] >> [data-testid="CodeEditor"]:visible', {
    has: page.locator('.CodeMirror-activeline'),
  });

  const text = await loadFixture('grpc.yaml');
  await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);

  await page.getByLabel('Import').click();
  await page.locator('[data-test-id="import-from-clipboard"]').click();
  await page.getByRole('button', { name: 'Scan' }).click();
  await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
  await page.getByLabel('PreRelease gRPC').click();

  await page.getByLabel('Request Collection').getByTestId('UnaryWithOutProtoFile').press('Enter');
  await expect(page.getByRole('button', { name: 'Select Method' })).toBeDisabled();
  await page.getByTestId('button-server-reflection').click();

  await page.getByRole('button', { name: 'Select Method' }).click();
  await page.getByRole('option', { name: 'RouteGuide/GetFeature' }).click();

  await page.getByRole('tab', { name: 'Unary' }).click();
  await page.getByRole('button', { name: 'Send' }).click();

  // Check for the single Unary response
  await page.getByRole('tab', { name: 'Response 1' }).click();
  await expect(statusTag).toContainText('0 OK');
  await expect(responseBody).toContainText('Berkshire Valley Management Area Trail');
});