Back to Repositories

Testing Plugin Installation Dependency Validation in Insomnia

This test suite evaluates the plugin installation process in Insomnia, focusing on dependency deprecation warnings and error handling. It contains comprehensive tests for validating warning message patterns and ensuring proper handling of deprecated dependencies during the installation process.

Test Coverage Overview

The test suite provides thorough coverage of plugin installation validation scenarios:

  • Verification of deprecation warning detection
  • Handling of mixed warning and error messages
  • Validation of deprecated dependency message patterns
  • Edge cases including falsy values and varied message formats

Implementation Analysis

The testing approach utilizes Jest’s describe/it blocks with vitest for structured test organization. It employs spy functionality to monitor console warnings and implements systematic validation of string patterns for deprecation messages.

The implementation focuses on two main functions: containsOnlyDeprecationWarnings and isDeprecatedDependencies, using regex patterns and string analysis.

Technical Details

  • Testing Framework: Vitest with Jest syntax
  • Mocking: Console spy implementation
  • Test Structure: Nested describe blocks
  • Validation Methods: Regular expressions and string parsing
  • Error Handling: Multiple message format validation

Best Practices Demonstrated

The test suite exemplifies several testing best practices including isolated test cases, comprehensive edge case coverage, and proper mock implementation.

  • Structured test organization
  • Proper spy cleanup
  • Comprehensive error scenarios
  • Clear test case descriptions
  • Isolated function testing

kong/insomnia

packages/insomnia/src/__tests__/install.test.ts

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

import { containsOnlyDeprecationWarnings, isDeprecatedDependencies } from '../main/install-plugin';

describe('install.js', () => {
  describe('containsOnlyDeprecationWarning', () => {
    it('should return true when all lines in stderr are deprecation warnings', () => {
      const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
      const stderr = // Warning #1
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.\r\n' + // Warning #2
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.\n' + // Warning #3
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.';
      expect(containsOnlyDeprecationWarnings(stderr)).toBe(true);
      expect(consoleWarnSpy).toHaveBeenCalledTimes(3);
    });

    it('should return false when stderr contains a deprecation warning and an error', () => {
      const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
      const stderr = // Warning #1
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.\r\n' + // Error #1
        'error https://npm.example.net/@types%example/-/nello-1.3.5.tgz:' +
        'Integrity check failed for "@types/example"' +
        '(computed integrity doesn\'t match our records, got "sha512-z4kkSfaPg==")\n' + // Warning #2
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.';
      expect(containsOnlyDeprecationWarnings(stderr)).toBe(false);
      expect(consoleWarnSpy).toHaveBeenCalledTimes(2);
    });
  });

  describe('isDeprecatedDependencies', () => {
    it('should not match when the message is falsy', () => {
      expect(isDeprecatedDependencies('')).toBe(false);
      expect(isDeprecatedDependencies(null)).toBe(false);
      expect(isDeprecatedDependencies(undefined)).toBe(false);
    });

    it('should match with multiple nested dependencies', () => {
      const msg =
        'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.';
      expect(isDeprecatedDependencies(msg)).toBe(true);
    });

    it('should match with one nested dependency', () => {
      const msg =
        'warning insomnia-plugin-xxx-yyy > xyz: ' +
        'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
        'Please, upgrade your dependencies to the actual version of xyz.';
      expect(isDeprecatedDependencies(msg)).toBe(true);
    });

    it('should not match with an unrelated warning', () => {
      const msg =
        'warning You are using Node "6.0.0" which is not supported and may encounter bugs or unexpected behaviour. ' +
        'Yarn supports the following server range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"';
      expect(isDeprecatedDependencies(msg)).toBe(false);
    });

    it('should not match with an unrelated error', () => {
      const msg =
        'error https://npm.example.net/@types%example/-/nello-1.3.5.tgz: ' +
        'Integrity check failed for "@types/example" ' +
        '(computed integrity doesn\'t match our records, got "sha512-z4kkSfaPg==")';
      expect(isDeprecatedDependencies(msg)).toBe(false);
    });
  });
});