UNPKG

@mendix/pluggable-widgets-tools

Version:
48 lines (47 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkForEnzymeUsage = checkForEnzymeUsage; const fs_1 = require("fs"); const path_1 = require("path"); const ansi_colors_1 = require("ansi-colors"); const paths_1 = require("../widget/paths"); function checkForEnzymeUsage(srcDir = "src") { const srcPath = (0, path_1.join)(paths_1.widgetRoot, srcDir); if (!(0, fs_1.existsSync)(srcPath)) { return; } const enzymeFiles = []; function scanDirectory(dir) { try { const entries = (0, fs_1.readdirSync)(dir); for (const entry of entries) { const fullPath = (0, path_1.join)(dir, entry); const stat = (0, fs_1.statSync)(fullPath); if (stat.isDirectory()) { scanDirectory(fullPath); continue; } const isJsOrTsFile = /\.(jsx?|tsx?)$/.test(entry); if (!stat.isFile() || !isJsOrTsFile) { continue; } const content = (0, fs_1.readFileSync)(fullPath, "utf8"); if (/(from|require\s*\()\s*['"]enzyme['"]|enzyme.*(?:shallow|mount|render)|(?:shallow|mount|render).*enzyme/.test(content)) { enzymeFiles.push(fullPath.replace(paths_1.widgetRoot, ".")); } } } catch (error) { console.error(`Error scanning directory ${dir}:`, error); } } scanDirectory(srcPath); if (enzymeFiles.length > 0) { console.log((0, ansi_colors_1.yellow)("\nWARNING: Enzyme usage detected in your tests")); console.log((0, ansi_colors_1.yellow)("Enzyme is no longer supported. Please migrate your tests to React Testing Library.")); console.log((0, ansi_colors_1.yellow)("\nFiles with potential Enzyme usage:")); enzymeFiles.forEach(file => console.log((0, ansi_colors_1.yellow)(` ${file}`))); console.log((0, ansi_colors_1.yellow)("\nFor migration guidance, see: https://testing-library.com/docs/react-testing-library/migrate-from-enzyme")); console.log(); } }