|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest'; |
2 | 2 | import { getCurrentScope } from '../../src/currentScopes'; |
3 | | -import { addIntegration, getIntegrationsToSetup, installedIntegrations, setupIntegration } from '../../src/integration'; |
| 3 | +import { |
| 4 | + _clearDisabledIntegrationsMarks, |
| 5 | + _isIntegrationMarkedDisabled, |
| 6 | + _markIntegrationsDisabled, |
| 7 | + addIntegration, |
| 8 | + getIntegrationsToSetup, |
| 9 | + installedIntegrations, |
| 10 | + setupIntegration, |
| 11 | +} from '../../src/integration'; |
4 | 12 | import { setCurrentClient } from '../../src/sdk'; |
5 | 13 | import type { Integration } from '../../src/types-hoist/integration'; |
6 | 14 | import type { Options } from '../../src/types-hoist/options'; |
@@ -683,3 +691,127 @@ describe('addIntegration', () => { |
683 | 691 | expect(logs).toHaveBeenCalledWith('Integration skipped because it was already installed: test'); |
684 | 692 | }); |
685 | 693 | }); |
| 694 | + |
| 695 | +describe('Integration marking system', () => { |
| 696 | + beforeEach(() => { |
| 697 | + // Clear marks before each test |
| 698 | + _clearDisabledIntegrationsMarks(); |
| 699 | + // Reset installed integrations |
| 700 | + installedIntegrations.splice(0, installedIntegrations.length); |
| 701 | + }); |
| 702 | + |
| 703 | + afterEach(() => { |
| 704 | + // Clean up after tests |
| 705 | + _clearDisabledIntegrationsMarks(); |
| 706 | + }); |
| 707 | + |
| 708 | + describe('_markIntegrationsDisabled', () => { |
| 709 | + it('marks a single integration as disabled', () => { |
| 710 | + _markIntegrationsDisabled('TestIntegration'); |
| 711 | + expect(_isIntegrationMarkedDisabled('TestIntegration')).toBe(true); |
| 712 | + }); |
| 713 | + |
| 714 | + it('marks multiple integrations as disabled using array', () => { |
| 715 | + _markIntegrationsDisabled(['Integration1', 'Integration2', 'Integration3']); |
| 716 | + expect(_isIntegrationMarkedDisabled('Integration1')).toBe(true); |
| 717 | + expect(_isIntegrationMarkedDisabled('Integration2')).toBe(true); |
| 718 | + expect(_isIntegrationMarkedDisabled('Integration3')).toBe(true); |
| 719 | + }); |
| 720 | + |
| 721 | + it('does not affect unmarked integrations', () => { |
| 722 | + _markIntegrationsDisabled('Integration1'); |
| 723 | + expect(_isIntegrationMarkedDisabled('Integration1')).toBe(true); |
| 724 | + expect(_isIntegrationMarkedDisabled('Integration2')).toBe(false); |
| 725 | + }); |
| 726 | + }); |
| 727 | + |
| 728 | + describe('_isIntegrationMarkedDisabled', () => { |
| 729 | + it('returns false for integrations that are not marked', () => { |
| 730 | + expect(_isIntegrationMarkedDisabled('SomeIntegration')).toBe(false); |
| 731 | + }); |
| 732 | + |
| 733 | + it('returns true for integrations that are marked', () => { |
| 734 | + _markIntegrationsDisabled('MarkedIntegration'); |
| 735 | + expect(_isIntegrationMarkedDisabled('MarkedIntegration')).toBe(true); |
| 736 | + }); |
| 737 | + }); |
| 738 | + |
| 739 | + describe('_clearDisabledIntegrationsMarks', () => { |
| 740 | + it('clears all marks', () => { |
| 741 | + _markIntegrationsDisabled(['Integration1', 'Integration2']); |
| 742 | + expect(_isIntegrationMarkedDisabled('Integration1')).toBe(true); |
| 743 | + expect(_isIntegrationMarkedDisabled('Integration2')).toBe(true); |
| 744 | + |
| 745 | + _clearDisabledIntegrationsMarks(); |
| 746 | + |
| 747 | + expect(_isIntegrationMarkedDisabled('Integration1')).toBe(false); |
| 748 | + expect(_isIntegrationMarkedDisabled('Integration2')).toBe(false); |
| 749 | + }); |
| 750 | + |
| 751 | + it('removes marked integrations from installedIntegrations list', () => { |
| 752 | + // Simulate integrations being installed |
| 753 | + installedIntegrations.push('Integration1', 'Integration2', 'Integration3'); |
| 754 | + |
| 755 | + // Mark some as disabled |
| 756 | + _markIntegrationsDisabled(['Integration1', 'Integration3']); |
| 757 | + |
| 758 | + // Clear should remove marked ones from installed list |
| 759 | + _clearDisabledIntegrationsMarks(); |
| 760 | + |
| 761 | + expect(installedIntegrations).toEqual(['Integration2']); |
| 762 | + }); |
| 763 | + |
| 764 | + it('preserves integrations that are not marked when clearing', () => { |
| 765 | + installedIntegrations.push('Integration1', 'Integration2', 'Integration3'); |
| 766 | + _markIntegrationsDisabled('Integration2'); |
| 767 | + |
| 768 | + _clearDisabledIntegrationsMarks(); |
| 769 | + |
| 770 | + expect(installedIntegrations).toEqual(['Integration1', 'Integration3']); |
| 771 | + }); |
| 772 | + }); |
| 773 | + |
| 774 | + describe('setupIntegration with marked integrations', () => { |
| 775 | + it('skips setupOnce for marked integrations', () => { |
| 776 | + const client = getTestClient(); |
| 777 | + const integration = new MockIntegration('MarkedIntegration'); |
| 778 | + |
| 779 | + // Mark the integration as disabled before setup |
| 780 | + _markIntegrationsDisabled('MarkedIntegration'); |
| 781 | + |
| 782 | + setupIntegration(client, integration, {}); |
| 783 | + |
| 784 | + // setupOnce should not be called |
| 785 | + expect(integration.setupOnce).not.toHaveBeenCalled(); |
| 786 | + // Integration should not be in installed list |
| 787 | + expect(installedIntegrations).not.toContain('MarkedIntegration'); |
| 788 | + }); |
| 789 | + |
| 790 | + it('calls setupOnce for non-marked integrations', () => { |
| 791 | + const client = getTestClient(); |
| 792 | + const integration = new MockIntegration('NormalIntegration'); |
| 793 | + |
| 794 | + setupIntegration(client, integration, {}); |
| 795 | + |
| 796 | + // setupOnce should be called |
| 797 | + expect(integration.setupOnce).toHaveBeenCalledTimes(1); |
| 798 | + // Integration should be in installed list |
| 799 | + expect(installedIntegrations).toContain('NormalIntegration'); |
| 800 | + }); |
| 801 | + |
| 802 | + it('allows setup after clearing marks', () => { |
| 803 | + const client = getTestClient(); |
| 804 | + const integration = new MockIntegration('TestIntegration'); |
| 805 | + |
| 806 | + // Mark, clear, then setup |
| 807 | + _markIntegrationsDisabled('TestIntegration'); |
| 808 | + _clearDisabledIntegrationsMarks(); |
| 809 | + |
| 810 | + setupIntegration(client, integration, {}); |
| 811 | + |
| 812 | + // setupOnce should be called after marks are cleared |
| 813 | + expect(integration.setupOnce).toHaveBeenCalledTimes(1); |
| 814 | + expect(installedIntegrations).toContain('TestIntegration'); |
| 815 | + }); |
| 816 | + }); |
| 817 | +}); |
0 commit comments