Skip to content

Commit 5c01344

Browse files
committed
Fix lint issue and tests
1 parent 229fe5f commit 5c01344

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/react-router/src/vite/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ConfigEnv } from 'vite';
22
import { type Plugin } from 'vite';
3+
import { makeConfigInjectorPlugin } from './makeConfigInjectorPlugin';
34
import { makeCustomSentryVitePlugins } from './makeCustomSentryVitePlugins';
45
import { makeEnableSourceMapsPlugin } from './makeEnableSourceMapsPlugin';
56
import type { SentryReactRouterBuildOptions } from './types';
6-
import { makeConfigInjectorPlugin } from './makeConfigInjectorPlugin';
77

88
/**
99
* A Vite plugin for Sentry that handles source map uploads and bundle size optimizations.

packages/react-router/test/vite/plugin.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { makeConfigInjectorPlugin } from '../../src/vite/makeConfigInjectorPlugin';
23
import { makeCustomSentryVitePlugins } from '../../src/vite/makeCustomSentryVitePlugins';
34
import { makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin';
45
import { sentryReactRouter } from '../../src/vite/plugin';
@@ -12,57 +13,61 @@ vi.spyOn(console, 'warn').mockImplementation(() => {
1213

1314
vi.mock('../../src/vite/makeCustomSentryVitePlugins');
1415
vi.mock('../../src/vite/makeEnableSourceMapsPlugin');
16+
vi.mock('../../src/vite/makeConfigInjectorPlugin');
1517

1618
describe('sentryReactRouter', () => {
1719
const mockPlugins = [{ name: 'test-plugin' }];
1820
const mockSourceMapsPlugin = { name: 'source-maps-plugin' };
21+
const mockConfigInjectorPlugin = { name: 'sentry-config-injector' };
1922

2023
beforeEach(() => {
2124
vi.clearAllMocks();
2225
vi.mocked(makeCustomSentryVitePlugins).mockResolvedValue(mockPlugins);
2326
vi.mocked(makeEnableSourceMapsPlugin).mockReturnValue(mockSourceMapsPlugin);
27+
vi.mocked(makeConfigInjectorPlugin).mockReturnValue(mockConfigInjectorPlugin);
2428
});
2529

2630
afterEach(() => {
2731
vi.resetModules();
2832
});
2933

30-
it('should return an empty array in development mode', async () => {
34+
it('should return sentry config injector plugin in development mode', async () => {
3135
const originalNodeEnv = process.env.NODE_ENV;
3236
process.env.NODE_ENV = 'development';
3337

3438
const result = await sentryReactRouter({}, { command: 'build', mode: 'production' });
3539

36-
expect(result).toEqual([]);
40+
expect(result).toEqual([mockConfigInjectorPlugin]);
3741
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
3842
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
3943

4044
process.env.NODE_ENV = originalNodeEnv;
4145
});
4246

43-
it('should return an empty array when not in build mode', async () => {
47+
it('should return config injector plugin when not in build mode', async () => {
4448
const result = await sentryReactRouter({}, { command: 'serve', mode: 'production' });
4549

46-
expect(result).toEqual([]);
50+
expect(result).toEqual([mockConfigInjectorPlugin]);
4751
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
4852
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
4953
});
5054

51-
it('should return an empty array when in development mode', async () => {
55+
it('should return config injector plugin in development build mode', async () => {
5256
const result = await sentryReactRouter({}, { command: 'build', mode: 'development' });
5357

54-
expect(result).toEqual([]);
58+
expect(result).toEqual([mockConfigInjectorPlugin]);
5559
expect(makeCustomSentryVitePlugins).not.toHaveBeenCalled();
5660
expect(makeEnableSourceMapsPlugin).not.toHaveBeenCalled();
5761
});
5862

59-
it('should return plugins in production build mode', async () => {
63+
it('should return all plugins in production build mode', async () => {
6064
const originalNodeEnv = process.env.NODE_ENV;
6165
process.env.NODE_ENV = 'production';
6266

6367
const result = await sentryReactRouter({}, { command: 'build', mode: 'production' });
6468

65-
expect(result).toEqual([mockSourceMapsPlugin, ...mockPlugins]);
69+
expect(result).toEqual([mockConfigInjectorPlugin, mockSourceMapsPlugin, ...mockPlugins]);
70+
expect(makeConfigInjectorPlugin).toHaveBeenCalledWith({});
6671
expect(makeCustomSentryVitePlugins).toHaveBeenCalledWith({});
6772
expect(makeEnableSourceMapsPlugin).toHaveBeenCalledWith({});
6873

@@ -81,6 +86,7 @@ describe('sentryReactRouter', () => {
8186

8287
await sentryReactRouter(options, { command: 'build', mode: 'production' });
8388

89+
expect(makeConfigInjectorPlugin).toHaveBeenCalledWith(options);
8490
expect(makeCustomSentryVitePlugins).toHaveBeenCalledWith(options);
8591
expect(makeEnableSourceMapsPlugin).toHaveBeenCalledWith(options);
8692

0 commit comments

Comments
 (0)