UNPKG

jest-codemods

Version:

Codemods for migrating test files to Jest

35 lines (34 loc) 1.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.api = api; exports.runPlugin = runPlugin; exports.wrapPlugin = wrapPlugin; var jscodeshift_1 = __importDefault(require("jscodeshift")); // simulate the jscodeshift api function api(options) { var j = jscodeshift_1.default; if (options.parser) { j = j.withParser(options.parser); } return { jscodeshift: j, j: j, stats: function () { }, report: function () { }, }; } function runPlugin(plugin, file, options) { if (options === void 0) { options = {}; } var source = typeof file === 'string' ? file : file.source; var path = typeof file === 'string' ? 'test.js' : file.path; return plugin({ source: source, path: path }, api(options), options); } function wrapPlugin(plugin) { return function (source, options) { if (options === void 0) { options = {}; } return runPlugin(plugin, source, options) || null; }; }