Helper function to support test runner for Babel plugin fixture-based testing
npx @tessl/cli install tessl/npm-babel--helper-plugin-test-runner@7.27.0The @babel/helper-plugin-test-runner package provides a helper function to support fixture-based test runners for Babel plugins. It simplifies the process of running fixture-based tests for Babel transformations by providing a standardized interface to @babel/helper-transform-fixture-test-runner, handling file system operations, path resolution, and cross-platform compatibility.
npm install @babel/helper-plugin-test-runnerimport testRunner from "@babel/helper-plugin-test-runner";For CommonJS:
const testRunner = require("@babel/helper-plugin-test-runner");import testRunner from "@babel/helper-plugin-test-runner";
// Run tests for fixtures in a directory
testRunner("file:///path/to/plugin/test/");
// Legacy path format also supported
testRunner("/path/to/plugin/test/");The main export is a function that processes fixture-based tests for Babel plugins, providing cross-platform compatibility and automatic fixture discovery.
/**
* Run fixture-based tests for Babel plugins
* @param loc - Location path (file:// URL or regular path) pointing to directory containing test fixtures
*/
function testRunner(loc: string): void;Parameters:
loc (string): Location path that can be either:
file:// URL pointing to the test directoryfixtures subdirectory within the provided locationBehavior:
fixtures subdirectory and determines test names from directory structurefile:// URLs and legacy file system paths@babel/helper-transform-fixture-test-runner for actual test executionBABEL_8_BREAKING environment variable for version compatibilityUsage Examples:
import testRunner from "@babel/helper-plugin-test-runner";
// Using file:// URL (modern approach)
testRunner("file:///path/to/my-babel-plugin/test/");
// Using regular path (legacy support)
testRunner("/path/to/my-babel-plugin/test/");
// The function will automatically:
// 1. Look for a "fixtures" subdirectory
// 2. Extract the plugin name from the parent directory
// 3. Call the underlying test runner with proper configuration/**
* Main test runner function signature
*/
type TestRunnerFunction = (loc: string) => void;BABEL_8_BREAKING for version compatibilityThis package requires:
@babel/helper-transform-fixture-test-runner: Core test runner functionalitynode:path: Path manipulation utilitiesnode:url: URL handling for file:// URLsThe function will throw errors in the following cases:
Common error scenarios:
// This will work
testRunner("file:///Users/dev/my-plugin/test/");
// This will also work (legacy format)
testRunner("/Users/dev/my-plugin/test/");
// This may fail if fixtures directory doesn't exist
testRunner("/path/without/fixtures/");