lwc-convert 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -621,55 +621,55 @@ function getTestValueForType(type) {
621
621
  }
622
622
  // ============ Test File Generators ============
623
623
  function generateBeforeTestFile(componentName, tests) {
624
- let content = `/**
625
- * BEFORE CONVERSION: Expected Behaviors for ${componentName}
626
- *
627
- * This document describes the expected behaviors of the original Aura component.
628
- * These behaviors should be preserved in the converted LWC.
629
- *
630
- * Generated by lwc-convert
631
- */
632
-
633
- /**
634
- * Behavior Inventory
635
- * ==================
636
- *
637
- * The following behaviors were identified in the Aura component:
638
- */
639
-
624
+ let content = `/**
625
+ * BEFORE CONVERSION: Expected Behaviors for ${componentName}
626
+ *
627
+ * This document describes the expected behaviors of the original Aura component.
628
+ * These behaviors should be preserved in the converted LWC.
629
+ *
630
+ * Generated by lwc-convert
631
+ */
632
+
633
+ /**
634
+ * Behavior Inventory
635
+ * ==================
636
+ *
637
+ * The following behaviors were identified in the Aura component:
638
+ */
639
+
640
640
  `;
641
641
  const categories = [...new Set(tests.map(t => t.category))];
642
642
  for (const category of categories) {
643
643
  const categoryTests = tests.filter(t => t.category === category);
644
644
  content += `// ============ ${category.toUpperCase()} BEHAVIORS ============\n\n`;
645
645
  for (const test of categoryTests) {
646
- content += `/**
647
- * ${test.id}: ${test.name}
648
- * ${test.description}
649
- *
650
- * Aura Pattern:
651
- * ${test.auraBehavior.pattern}
652
- */
653
- ${test.testCode.before}
654
-
646
+ content += `/**
647
+ * ${test.id}: ${test.name}
648
+ * ${test.description}
649
+ *
650
+ * Aura Pattern:
651
+ * ${test.auraBehavior.pattern}
652
+ */
653
+ ${test.testCode.before}
654
+
655
655
  `;
656
656
  }
657
657
  }
658
- content += `
659
- /**
660
- * Summary
661
- * =======
662
- *
663
- * Total behaviors identified: ${tests.length}
664
- * - Lifecycle: ${tests.filter(t => t.category === 'lifecycle').length}
665
- * - Data: ${tests.filter(t => t.category === 'data').length}
666
- * - Events: ${tests.filter(t => t.category === 'event').length}
667
- * - UI: ${tests.filter(t => t.category === 'ui').length}
668
- * - LMS: ${tests.filter(t => t.category === 'lms').length}
669
- * - Apex: ${tests.filter(t => t.category === 'apex').length}
670
- *
671
- * Run the "after" tests to verify all behaviors are preserved.
672
- */
658
+ content += `
659
+ /**
660
+ * Summary
661
+ * =======
662
+ *
663
+ * Total behaviors identified: ${tests.length}
664
+ * - Lifecycle: ${tests.filter(t => t.category === 'lifecycle').length}
665
+ * - Data: ${tests.filter(t => t.category === 'data').length}
666
+ * - Events: ${tests.filter(t => t.category === 'event').length}
667
+ * - UI: ${tests.filter(t => t.category === 'ui').length}
668
+ * - LMS: ${tests.filter(t => t.category === 'lms').length}
669
+ * - Apex: ${tests.filter(t => t.category === 'apex').length}
670
+ *
671
+ * Run the "after" tests to verify all behaviors are preserved.
672
+ */
673
673
  `;
674
674
  return content;
675
675
  }
@@ -686,15 +686,15 @@ function generateAfterTestFile(lwcName, className, tests, transformedMarkup) {
686
686
  const channelVar = lms.channelName.replace(/__c$/i, '').toUpperCase() + '_CHANNEL';
687
687
  imports.push(`import ${channelVar} from '@salesforce/messageChannel/${lms.channelName}';`);
688
688
  }
689
- mocks.push(`jest.mock(
690
- 'lightning/messageService',
691
- () => ({
692
- publish: jest.fn(),
693
- subscribe: jest.fn(() => ({ unsubscribe: jest.fn() })),
694
- unsubscribe: jest.fn(),
695
- MessageContext: jest.fn()
696
- }),
697
- { virtual: true }
689
+ mocks.push(`jest.mock(
690
+ 'lightning/messageService',
691
+ () => ({
692
+ publish: jest.fn(),
693
+ subscribe: jest.fn(() => ({ unsubscribe: jest.fn() })),
694
+ unsubscribe: jest.fn(),
695
+ MessageContext: jest.fn()
696
+ }),
697
+ { virtual: true }
698
698
  );`);
699
699
  }
700
700
  // Add wire mocks if needed
@@ -710,42 +710,42 @@ function generateAfterTestFile(lwcName, className, tests, transformedMarkup) {
710
710
  const controller = controllerMatch ? controllerMatch[1] : 'ApexController';
711
711
  // Add import for the Apex method
712
712
  imports.push(`import ${method} from '@salesforce/apex/${controller}.${method}';`);
713
- mocks.push(`jest.mock(
714
- '@salesforce/apex/${controller}.${method}',
715
- () => ({ default: jest.fn() }),
716
- { virtual: true }
713
+ mocks.push(`jest.mock(
714
+ '@salesforce/apex/${controller}.${method}',
715
+ () => ({ default: jest.fn() }),
716
+ { virtual: true }
717
717
  );`);
718
718
  }
719
- let content = `/**
720
- * AFTER CONVERSION: Jest Tests for ${lwcName}
721
- * Converted from Aura component
722
- *
723
- * These tests verify that the converted LWC preserves all original behaviors.
724
- * Each test is linked to a specific behavior from the "before" document.
725
- *
726
- * Generated by lwc-convert
727
- */
728
-
729
- ${imports.join('\n')}
730
-
731
- ${mocks.length > 0 ? '\n// Mocks\n' + mocks.join('\n\n') + '\n' : ''}
732
-
733
- describe('${lwcName} - Behavior Verification', () => {
734
- let element;
735
-
736
- beforeEach(() => {
737
- element = createElement('c-${lwcName}', {
738
- is: ${className}
739
- });
740
- });
741
-
742
- afterEach(() => {
743
- while (document.body.firstChild) {
744
- document.body.removeChild(document.body.firstChild);
745
- }
746
- jest.clearAllMocks();
747
- });
748
-
719
+ let content = `/**
720
+ * AFTER CONVERSION: Jest Tests for ${lwcName}
721
+ * Converted from Aura component
722
+ *
723
+ * These tests verify that the converted LWC preserves all original behaviors.
724
+ * Each test is linked to a specific behavior from the "before" document.
725
+ *
726
+ * Generated by lwc-convert
727
+ */
728
+
729
+ ${imports.join('\n')}
730
+
731
+ ${mocks.length > 0 ? '\n// Mocks\n' + mocks.join('\n\n') + '\n' : ''}
732
+
733
+ describe('${lwcName} - Behavior Verification', () => {
734
+ let element;
735
+
736
+ beforeEach(() => {
737
+ element = createElement('c-${lwcName}', {
738
+ is: ${className}
739
+ });
740
+ });
741
+
742
+ afterEach(() => {
743
+ while (document.body.firstChild) {
744
+ document.body.removeChild(document.body.firstChild);
745
+ }
746
+ jest.clearAllMocks();
747
+ });
748
+
749
749
  `;
750
750
  const categories = [...new Set(tests.map(t => t.category))];
751
751
  for (const category of categories) {
@@ -753,44 +753,44 @@ describe('${lwcName} - Behavior Verification', () => {
753
753
  content += ` // ============ ${category.toUpperCase()} TESTS ============\n`;
754
754
  content += ` describe('${category.charAt(0).toUpperCase() + category.slice(1)} Behaviors', () => {\n`;
755
755
  for (const test of categoryTests) {
756
- content += ` /**
757
- * ${test.id}: ${test.name}
758
- * LWC Pattern: ${test.lwcBehavior.pattern}
759
- */
760
- ${test.testCode.after}
761
-
756
+ content += ` /**
757
+ * ${test.id}: ${test.name}
758
+ * LWC Pattern: ${test.lwcBehavior.pattern}
759
+ */
760
+ ${test.testCode.after}
761
+
762
762
  `;
763
763
  }
764
764
  content += ` });\n\n`;
765
765
  }
766
- content += `});
767
-
768
- /**
769
- * Test Results Comparison
770
- * =======================
771
- *
772
- * Run these tests with: npm test -- --testPathPattern="${lwcName}"
773
- *
774
- * Expected: All ${tests.length} behavior tests should pass
775
- *
776
- * If a test fails, compare with the corresponding "before" behavior
777
- * to understand what the original Aura component did.
778
- */
766
+ content += `});
767
+
768
+ /**
769
+ * Test Results Comparison
770
+ * =======================
771
+ *
772
+ * Run these tests with: npm test -- --testPathPattern="${lwcName}"
773
+ *
774
+ * Expected: All ${tests.length} behavior tests should pass
775
+ *
776
+ * If a test fails, compare with the corresponding "before" behavior
777
+ * to understand what the original Aura component did.
778
+ */
779
779
  `;
780
780
  return content;
781
781
  }
782
782
  function generateComparisonReport(componentName, lwcName, tests) {
783
- let report = `# Conversion Behavior Comparison Report
784
-
785
- ## Component: ${componentName} → ${lwcName}
786
-
787
- This report documents the behavioral mapping between the original Aura component
788
- and the converted LWC. Use this to verify the conversion is complete and correct.
789
-
790
- ## Behavior Summary
791
-
792
- | Category | Count | Status |
793
- |----------|-------|--------|
783
+ let report = `# Conversion Behavior Comparison Report
784
+
785
+ ## Component: ${componentName} → ${lwcName}
786
+
787
+ This report documents the behavioral mapping between the original Aura component
788
+ and the converted LWC. Use this to verify the conversion is complete and correct.
789
+
790
+ ## Behavior Summary
791
+
792
+ | Category | Count | Status |
793
+ |----------|-------|--------|
794
794
  `;
795
795
  const categories = ['lifecycle', 'data', 'event', 'ui', 'lms', 'apex'];
796
796
  for (const cat of categories) {
@@ -799,56 +799,56 @@ and the converted LWC. Use this to verify the conversion is complete and correct
799
799
  report += `| ${cat.charAt(0).toUpperCase() + cat.slice(1)} | ${count} | ${status} |\n`;
800
800
  }
801
801
  report += `| **Total** | **${tests.length}** | |\n`;
802
- report += `
803
- ## Detailed Behavior Mapping
804
-
802
+ report += `
803
+ ## Detailed Behavior Mapping
804
+
805
805
  `;
806
806
  for (const cat of categories) {
807
807
  const categoryTests = tests.filter(t => t.category === cat);
808
808
  if (categoryTests.length === 0)
809
809
  continue;
810
- report += `### ${cat.charAt(0).toUpperCase() + cat.slice(1)} Behaviors
811
-
810
+ report += `### ${cat.charAt(0).toUpperCase() + cat.slice(1)} Behaviors
811
+
812
812
  `;
813
813
  for (const test of categoryTests) {
814
- report += `#### ${test.id}: ${test.name}
815
-
816
- - **Description**: ${test.description}
817
- - **Aura Pattern**: \`${test.auraBehavior.pattern}\`
818
- - **LWC Pattern**: \`${test.lwcBehavior.pattern}\`
819
- - **Test Status**: ⬜ Not run
820
-
814
+ report += `#### ${test.id}: ${test.name}
815
+
816
+ - **Description**: ${test.description}
817
+ - **Aura Pattern**: \`${test.auraBehavior.pattern}\`
818
+ - **LWC Pattern**: \`${test.lwcBehavior.pattern}\`
819
+ - **Test Status**: ⬜ Not run
820
+
821
821
  `;
822
822
  }
823
823
  }
824
- report += `
825
- ## Verification Checklist
826
-
827
- Run the test suite and update this checklist:
828
-
824
+ report += `
825
+ ## Verification Checklist
826
+
827
+ Run the test suite and update this checklist:
828
+
829
829
  `;
830
830
  for (const test of tests) {
831
831
  report += `- [ ] ${test.id}: ${test.name}\n`;
832
832
  }
833
- report += `
834
- ## How to Run Tests
835
-
836
- \`\`\`bash
837
- # Run all tests for this component
838
- npm test -- --testPathPattern="${lwcName}"
839
-
840
- # Run with coverage
841
- npm test -- --testPathPattern="${lwcName}" --coverage
842
-
843
- # Run in watch mode
844
- npm test -- --testPathPattern="${lwcName}" --watch
845
- \`\`\`
846
-
847
- ## Notes
848
-
849
- - Tests marked with "⏳ Pending verification" need manual review
850
- - If a test fails, compare the Aura and LWC patterns to understand the difference
851
- - Some behaviors may require manual implementation (marked as TODO in tests)
833
+ report += `
834
+ ## How to Run Tests
835
+
836
+ \`\`\`bash
837
+ # Run all tests for this component
838
+ npm test -- --testPathPattern="${lwcName}"
839
+
840
+ # Run with coverage
841
+ npm test -- --testPathPattern="${lwcName}" --coverage
842
+
843
+ # Run in watch mode
844
+ npm test -- --testPathPattern="${lwcName}" --watch
845
+ \`\`\`
846
+
847
+ ## Notes
848
+
849
+ - Tests marked with "⏳ Pending verification" need manual review
850
+ - If a test fails, compare the Aura and LWC patterns to understand the difference
851
+ - Some behaviors may require manual implementation (marked as TODO in tests)
852
852
  `;
853
853
  return report;
854
854
  }