@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
48 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const run_1 = require("../run");
const nextjs_wizard_1 = require("../nextjs/nextjs-wizard");
const analytics_1 = require("../utils/analytics");
const constants_1 = require("../lib/constants");
jest.mock('../nextjs/nextjs-wizard');
jest.mock('../utils/analytics');
jest.mock('../utils/clack');
const mockRunNextjsWizard = nextjs_wizard_1.runNextjsWizard;
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,
};
mockRunNextjsWizard.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 };
mockRunNextjsWizard.mockResolvedValue(undefined);
await (0, run_1.runWizard)(testArgs);
expect(mockAnalytics.captureException).not.toHaveBeenCalled();
expect(mockAnalytics.shutdown).not.toHaveBeenCalled();
});
});
//# sourceMappingURL=run.test.js.map