Helper function to support test runner for Babel plugin fixture-based testing
npx @tessl/cli install tessl/npm-babel-helper-plugin-test-runner@6.24.0Babel 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.
npm install babel-helper-plugin-test-runnerimport pluginTestRunner from "babel-helper-plugin-test-runner";For CommonJS:
const pluginTestRunner = require("babel-helper-plugin-test-runner");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.jsExecutes 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:
path.basename(path.dirname(loc))loc + "/fixtures"babel-helper-transform-fixture-test-runnerBehavior:
babel-helper-transform-fixture-test-runner(fixturesPath, testName)actual.js and expected.js filesUsage 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.jsThis package depends on:
babel-helper-transform-fixture-test-runner: Core test execution enginebabel-runtime: Babel runtime helperspath (Node.js built-in): Path manipulation utilitiesThe package is a thin wrapper that:
path.basename(path.dirname(loc))loc + "/fixtures"testRunner(fixturesPath, testName) to execute the testsThis design standardizes the plugin testing process within the Babel ecosystem by enforcing consistent directory naming and structure conventions.