-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathplugin.test.ts
More file actions
95 lines (73 loc) · 3.59 KB
/
plugin.test.ts
File metadata and controls
95 lines (73 loc) · 3.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { makeConfigInjectorPlugin } from '../../src/vite/makeConfigInjectorPlugin';
import { makeCustomSentryVitePlugins } from '../../src/vite/makeCustomSentryVitePlugins';
import { makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin';
import { sentryReactRouter } from '../../src/vite/plugin';
vi.spyOn(console, 'log').mockImplementation(() => {
/* noop */
});
vi.spyOn(console, 'warn').mockImplementation(() => {
/* noop */
});
vi.mock('../../src/vite/makeCustomSentryVitePlugins');
vi.mock('../../src/vite/makeEnableSourceMapsPlugin');
vi.mock('../../src/vite/makeConfigInjectorPlugin');
describe('sentryReactRouter', () => {
const mockPlugins = [{ name: 'test-plugin' }];
const mockSourceMapsPlugin = { name: 'source-maps-plugin' };
const mockConfigInjectorPlugin = { name: 'sentry-config-injector' };
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(makeCustomSentryVitePlugins).mockResolvedValue(mockPlugins);
vi.mocked(makeEnableSourceMapsPlugin).mockReturnValue(mockSourceMapsPlugin);
vi.mocked(makeConfigInjectorPlugin).mockReturnValue(mockConfigInjectorPlugin);
});
afterEach(() => {
vi.resetModules();
});
it('should return sentry config injector plugin in development mode', async () => {
const originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
const result = await sentryReactRouter({}, { command: 'build', mode: 'production' });
expect(result).toEqual([mockConfigInjectorPlugin]);
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
process.env.NODE_ENV = originalNodeEnv;
});
it('should return config injector plugin when not in build mode', async () => {
const result = await sentryReactRouter({}, { command: 'serve', mode: 'production' });
expect(result).toEqual([mockConfigInjectorPlugin]);
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
});
it('should return config injector plugin in development build mode', async () => {
const result = await sentryReactRouter({}, { command: 'build', mode: 'development' });
expect(result).toEqual([mockConfigInjectorPlugin]);
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
});
it('should return all plugins in production build mode', async () => {
const originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
const result = await sentryReactRouter({}, { command: 'build', mode: 'production' });
expect(result).toEqual([mockConfigInjectorPlugin, mockSourceMapsPlugin, ...mockPlugins]);
expect(makeConfigInjectorPlugin).toHaveBeenCalledWith({});
expect(makeCustomSentryVitePlugins).toHaveBeenCalledWith({});
expect(makeEnableSourceMapsPlugin).toHaveBeenCalledWith({});
process.env.NODE_ENV = originalNodeEnv;
});
it('should pass release configuration to plugins', async () => {
const originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
const options = {
release: {
name: 'v1.0.0',
},
};
await sentryReactRouter(options, { command: 'build', mode: 'production' });
expect(makeConfigInjectorPlugin).toHaveBeenCalledWith(options);
expect(makeCustomSentryVitePlugins).toHaveBeenCalledWith(options);
expect(makeEnableSourceMapsPlugin).toHaveBeenCalledWith(options);
process.env.NODE_ENV = originalNodeEnv;
});
});