-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrun.test.ts
More file actions
62 lines (47 loc) · 1.86 KB
/
run.test.ts
File metadata and controls
62 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { runWizard } from '../run';
import { runNextjsWizardAgent } from '../nextjs/nextjs-wizard-agent';
import { analytics } from '../utils/analytics';
import { Integration } from '../lib/constants';
jest.mock('../nextjs/nextjs-wizard-agent');
jest.mock('../utils/analytics');
jest.mock('../utils/clack');
const mockRunNextjsWizardAgent = runNextjsWizardAgent as jest.MockedFunction<
typeof runNextjsWizardAgent
>;
const mockAnalytics = analytics as jest.Mocked<typeof 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: Integration.nextjs,
debug: true,
forceInstall: false,
};
mockRunNextjsWizardAgent.mockRejectedValue(testError);
await expect(runWizard(testArgs)).rejects.toThrow('process.exit called');
expect(mockAnalytics.captureException).toHaveBeenCalledWith(testError, {
integration: Integration.nextjs,
arguments: JSON.stringify(testArgs),
});
expect(mockAnalytics.shutdown).toHaveBeenCalledWith('error');
});
it('should not call captureException when wizard succeeds', async () => {
const testArgs = { integration: Integration.nextjs };
mockRunNextjsWizardAgent.mockResolvedValue(undefined);
await runWizard(testArgs);
expect(mockAnalytics.captureException).not.toHaveBeenCalled();
expect(mockAnalytics.shutdown).not.toHaveBeenCalled();
});
});