or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-babel-helper-plugin-test-runner

Helper function to support test runner for Babel plugin fixture-based testing

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-helper-plugin-test-runner@6.24.x

To install, run

npx @tessl/cli install tessl/npm-babel-helper-plugin-test-runner@6.24.0

index.mddocs/

Babel Helper Plugin Test Runner

Babel Helper Plugin Test Runner is an internal Babel utility that provides a convenient wrapper for running fixture-based tests on Babel plugins. It simplifies the test execution process by automatically extracting test names from directory paths and delegating to the core fixture test runner.

Package Information

  • Package Name: babel-helper-plugin-test-runner
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install babel-helper-plugin-test-runner
  • Note: This is an internal Babel module intended for use within the Babel ecosystem

Core Imports

import pluginTestRunner from "babel-helper-plugin-test-runner";

For CommonJS:

const pluginTestRunner = require("babel-helper-plugin-test-runner");

Basic Usage

import pluginTestRunner from "babel-helper-plugin-test-runner";

// Run tests for a plugin located at a specific directory
// The function will look for fixtures in the "fixtures" subdirectory
// and use the parent directory name as the test name
pluginTestRunner("/path/to/my-babel-plugin");

// Example directory structure:
// /path/to/my-babel-plugin/
//   fixtures/
//     transform-arrow/
//       actual.js
//       expected.js
//     transform-class/
//       actual.js  
//       expected.js

Capabilities

Plugin Test Runner

Executes fixture-based tests for Babel plugins by wrapping babel-helper-transform-fixture-test-runner with automatic test name extraction.

/**
 * Runs fixture-based tests for a Babel plugin
 * @param {string} loc - Directory path containing the plugin and fixtures
 * @returns {undefined} - No return value
 */
export default function (loc);

Parameters:

  • loc (string): Directory path to the plugin directory. The function will:
    • Extract the test name from path.basename(path.dirname(loc))
    • Look for fixtures in loc + "/fixtures"
    • Pass both to babel-helper-transform-fixture-test-runner

Behavior:

  • Automatically extracts the test suite name from the parent directory name
  • Appends "/fixtures" to the provided location to find test fixtures
  • Delegates test execution to babel-helper-transform-fixture-test-runner(fixturesPath, testName)
  • Expects standard Babel fixture structure with actual.js and expected.js files

Usage Examples:

import pluginTestRunner from "babel-helper-plugin-test-runner";

// For a plugin at "/projects/babel-plugins/arrow-functions/"
// This will:
// - Use "babel-plugins" as the test name (parent directory)
// - Look for fixtures at "/projects/babel-plugins/arrow-functions/fixtures/"
pluginTestRunner("/projects/babel-plugins/arrow-functions/");

// Directory structure expected:
// /projects/babel-plugins/arrow-functions/
//   fixtures/
//     basic-arrow/
//       actual.js    // Input code to transform
//       expected.js  // Expected output after transformation
//     nested-arrow/
//       actual.js
//       expected.js

Dependencies

This package depends on:

  • babel-helper-transform-fixture-test-runner: Core test execution engine
  • babel-runtime: Babel runtime helpers
  • path (Node.js built-in): Path manipulation utilities

Implementation Details

The package is a thin wrapper that:

  1. Takes a directory location as input
  2. Extracts the test name using path.basename(path.dirname(loc))
  3. Constructs the fixtures path using loc + "/fixtures"
  4. Calls testRunner(fixturesPath, testName) to execute the tests

This design standardizes the plugin testing process within the Babel ecosystem by enforcing consistent directory naming and structure conventions.