Back to Repositories

Testing Git URL Transformation Utilities in Insomnia

This test suite validates the addDotGit utility function in the Insomnia repository, ensuring proper handling of Git repository URLs across different protocols. The tests verify URL transformation behavior for both bare links and those already containing .git extensions.

Test Coverage Overview

The test suite provides comprehensive coverage for Git URL handling across multiple protocols including SCP, SSH, HTTP, and HTTPS. Key functionality focuses on URL transformation consistency, while edge cases include handling pre-existing .git extensions. Integration points cover various Git remote URL formats commonly used in repository operations.

Implementation Analysis

Testing approach utilizes Jest’s describe/it pattern for organized test grouping. The implementation employs a structured test data object containing paired bare/dotGit URLs for each protocol, enabling systematic verification of URL transformations. Framework-specific features include Jest’s expect assertions for precise equality checking.

Technical Details

  • Testing Framework: Jest/Vitest
  • Test Structure: Describe/It blocks
  • Assertion Methods: .toEqual()
  • Test Data: Structured object with protocol-specific URL pairs

Best Practices Demonstrated

The test suite exemplifies clean testing practices through well-organized test data, clear test case separation, and comprehensive protocol coverage. Notable practices include:
  • Structured test data organization
  • Consistent test case naming
  • Complete protocol coverage
  • Clear separation of positive and negative test cases

kong/insomnia

packages/insomnia/src/sync/git/__tests__/utils.test.ts

            
import { describe, expect, it } from 'vitest';

import { addDotGit } from '../utils';

const links = {
  scp: {
    bare: '[email protected]:a/b',
    dotGit: '[email protected]:a/b.git',
  },
  ssh: {
    bare: 'ssh://[email protected]/b',
    dotGit: 'ssh://[email protected]/b.git',
  },
  http: {
    bare: 'http://github.com/a/b',
    dotGit: 'http://github.com/a/b.git',
  },
  https: {
    bare: 'https://github.com/a/b',
    dotGit: 'https://github.com/a/b.git',
  },
};

describe('addDotGit', () => {
  it('adds the .git to bare links', () => {
    expect(addDotGit(links.scp.bare)).toEqual(links.scp.dotGit);
    expect(addDotGit(links.ssh.bare)).toEqual(links.ssh.dotGit);
    expect(addDotGit(links.http.bare)).toEqual(links.http.dotGit);
    expect(addDotGit(links.https.bare)).toEqual(links.https.dotGit);
  });

  it('leaves links that already have .git alone', () => {
    expect(addDotGit(links.scp.dotGit)).toEqual(links.scp.dotGit);
    expect(addDotGit(links.ssh.dotGit)).toEqual(links.ssh.dotGit);
    expect(addDotGit(links.http.dotGit)).toEqual(links.http.dotGit);
    expect(addDotGit(links.https.dotGit)).toEqual(links.https.dotGit);
  });
});