UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

48 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const run_1 = require("../run"); const nextjs_wizard_agent_1 = require("../nextjs/nextjs-wizard-agent"); const analytics_1 = require("../utils/analytics"); const constants_1 = require("../lib/constants"); jest.mock('../nextjs/nextjs-wizard-agent'); jest.mock('../utils/analytics'); jest.mock('../utils/clack'); const mockRunNextjsWizardAgent = nextjs_wizard_agent_1.runNextjsWizardAgent; const mockAnalytics = analytics_1.analytics; describe('runWizard error handling', () => { beforeEach(() => { jest.clearAllMocks(); mockAnalytics.setTag = jest.fn(); mockAnalytics.captureException = jest.fn(); mockAnalytics.shutdown = jest.fn().mockResolvedValue(undefined); jest.spyOn(process, 'exit').mockImplementation(() => { throw new Error('process.exit called'); }); }); afterEach(() => { jest.restoreAllMocks(); }); it('should capture exception and shutdown analytics on wizard error', async () => { const testError = new Error('Wizard failed'); const testArgs = { integration: constants_1.Integration.nextjs, debug: true, forceInstall: false, }; mockRunNextjsWizardAgent.mockRejectedValue(testError); await expect((0, run_1.runWizard)(testArgs)).rejects.toThrow('process.exit called'); expect(mockAnalytics.captureException).toHaveBeenCalledWith(testError, { integration: constants_1.Integration.nextjs, arguments: JSON.stringify(testArgs), }); expect(mockAnalytics.shutdown).toHaveBeenCalledWith('error'); }); it('should not call captureException when wizard succeeds', async () => { const testArgs = { integration: constants_1.Integration.nextjs }; mockRunNextjsWizardAgent.mockResolvedValue(undefined); await (0, run_1.runWizard)(testArgs); expect(mockAnalytics.captureException).not.toHaveBeenCalled(); expect(mockAnalytics.shutdown).not.toHaveBeenCalled(); }); }); //# sourceMappingURL=run.test.js.map