or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Karma Plugin File Injector

Build a Karma plugin that automatically injects necessary framework files into the test environment.

Requirements

Your plugin should automatically inject required JavaScript and CSS files from an external testing framework into Karma's test environment. The plugin needs to:

  1. Register itself as a Karma framework plugin
  2. Locate framework files from node_modules using Node's module resolution
  3. Create file patterns that instruct Karma to include, serve, and load the framework files
  4. Inject both JavaScript library files and CSS stylesheets
  5. Inject a custom adapter script that bridges the framework with Karma

File Pattern Configuration

Each injected file should have specific loading behaviors:

  • Files should be marked as included so they load in the browser
  • Files should be marked as served so Karma serves them
  • Files should NOT be watched for changes during test runs
  • Files should have nocache: true to ensure fresh loading

Plugin Structure

Create a Karma framework plugin that follows Karma's plugin architecture:

  • Export the plugin using Karma's factory pattern
  • The plugin should modify Karma's file list to inject the necessary files
  • Files must be injected in the correct order: library files first, then CSS, then adapter
  • The adapter script should be a local file in your plugin (e.g., lib/adapter.js)

Test Cases

  • The plugin correctly injects the main framework JavaScript file from node_modules @test
  • The plugin correctly injects the framework CSS file from node_modules @test
  • The plugin correctly injects the adapter script @test
  • All injected files have the correct pattern configuration (included, served, not watched, nocache) @test

Implementation

@generates

API

/**
 * Karma plugin factory that injects framework files
 * @param {Array} files - Karma's file list to inject files into
 */
function initFramework(files) {
  // Implementation
}

// Export as Karma plugin
module.exports = {
  'framework:testframework': ['factory', initFramework]
};

Dependencies { .dependencies }

karma { .dependency }

Provides the test runner infrastructure and plugin system.

mock-framework { .dependency }

A mock testing framework package used for demonstration purposes. Provides:

  • mock-framework/dist/framework.js - Main framework library
  • mock-framework/dist/framework.css - Framework styles