CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lilconfig

A zero-dependency alternative to cosmiconfig for loading configuration files

89

1.21x
Overview
Eval results
Files

task.mdevals/scenario-8/

Configuration Cache Manager

Build a configuration cache testing utility that demonstrates the performance benefits and control mechanisms of configuration file caching.

Requirements

Create a module that helps developers test and benchmark configuration loading performance with different cache settings. The module should:

  1. Provide a function benchmarkSearch(moduleName, searchPath, options) that:

    • Searches for a configuration file from the given search path
    • Performs the search operation twice to demonstrate caching behavior
    • Returns an object containing:
      • firstSearchTime: time in milliseconds for the first search
      • secondSearchTime: time in milliseconds for the second search
      • result: the configuration result from the second search
      • cacheEnabled: boolean indicating whether caching was enabled
  2. Provide a function testCacheControl(moduleName, searchPath) that:

    • Creates an explorer instance with caching enabled
    • Performs a search operation and records the result
    • Clears all caches
    • Performs the same search again
    • Returns an object with:
      • firstResult: result from the first search
      • secondResult: result from the second search
      • resultsMatch: boolean indicating if both results have the same filepath
  3. Provide a function compareSearchCaching(moduleName, searchPath) that:

    • Performs a search with caching enabled and measures time
    • Performs the same search with caching disabled and measures time
    • Returns an object with:
      • withCacheTime: time taken with cache enabled
      • withoutCacheTime: time taken with cache disabled
      • result: the configuration result

Test Cases

  • When benchmarkSearch is called with caching enabled, the second search should be faster than the first search @test

  • When benchmarkSearch is called with caching disabled, both searches should take similar amounts of time (difference < 5ms) @test

  • When testCacheControl is called, clearing caches should not affect the ability to find the same configuration file again @test

  • When compareSearchCaching is called, both cached and non-cached searches should return the same configuration filepath @test

Implementation

@generates

API

/**
 * Benchmarks search performance with specified cache settings
 * @param {string} moduleName - Name of the configuration module to search for
 * @param {string} searchPath - Directory path to start searching from
 * @param {Object} options - Configuration options including cache setting
 * @param {boolean} options.cache - Whether to enable caching
 * @returns {Promise<Object>} Object with timing data and results
 */
export async function benchmarkSearch(moduleName, searchPath, options);

/**
 * Tests cache control methods
 * @param {string} moduleName - Name of the configuration module to search for
 * @param {string} searchPath - Directory path to start searching from
 * @returns {Promise<Object>} Object showing results before and after cache clearing
 */
export async function testCacheControl(moduleName, searchPath);

/**
 * Compares search performance with and without caching
 * @param {string} moduleName - Name of the configuration module to search for
 * @param {string} searchPath - Directory path to start searching from
 * @returns {Promise<Object>} Object with timing comparisons
 */
export async function compareSearchCaching(moduleName, searchPath);

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file search and loading with caching support.

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json