test-rename.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const path = require("path");
  2. const { RefactorEngine } = require("./src/core/tools/refactor-code/engine");
  3. async function testRenameRefactor() {
  4. console.log("Starting rename refactoring test...");
  5. // Initialize the refactor engine with the project root
  6. const engine = new RefactorEngine({
  7. projectRootPath: __dirname,
  8. });
  9. // Define the rename operation - rename formatUserName to formatFullName
  10. const renameOp = {
  11. id: "rename-format-user-name",
  12. operation: "rename",
  13. selector: {
  14. type: "identifier",
  15. kind: "function",
  16. name: "formatUserName",
  17. filePath: "examples/src/utils/formatting.ts",
  18. },
  19. newName: "formatFullName",
  20. scope: "project",
  21. };
  22. console.log("Executing rename operation...");
  23. try {
  24. // Execute the operation
  25. const result = await engine.executeOperation(renameOp);
  26. console.log(`Operation result: ${result.success ? "SUCCESS" : "FAILURE"}`);
  27. if (!result.success) {
  28. console.error(`Error: ${result.error}`);
  29. } else {
  30. console.log(`Affected files: ${result.affectedFiles.join(", ")}`);
  31. }
  32. } catch (error) {
  33. console.error("Error during refactoring:", error);
  34. }
  35. }
  36. // Run the test
  37. testRenameRefactor().catch(console.error);