Skip to content

Commit 36f0ab9

Browse files
committed
update unit tests for sentryTanstackStart
1 parent 8872fc1 commit 36f0ab9

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

packages/tanstackstart-react/src/vite/autoInstrumentMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function makeAutoInstrumentMiddlewarePlugin(options: AutoInstrumentMiddle
7373
* Returns null if contents contain non-identifier expressions (function calls, etc.)
7474
* which cannot be converted to object shorthand.
7575
*/
76-
function arrayToObjectShorthand(contents: string): string | null {
76+
export function arrayToObjectShorthand(contents: string): string | null {
7777
const items = contents
7878
.split(',')
7979
.map(s => s.trim())

packages/tanstackstart-react/test/vite/sentryTanstackStart.test.ts

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,59 +36,73 @@ describe('sentryTanstackStart()', () => {
3636
process.env.NODE_ENV = 'production';
3737
});
3838

39-
it('returns plugins in production mode', () => {
40-
const plugins = sentryTanstackStart({ org: 'test-org' });
39+
describe('middleware auto-instrumentation', () => {
40+
it('adds middleware plugin by default', () => {
41+
process.env.NODE_ENV = 'development';
42+
const plugins = sentryTanstackStart({});
4143

42-
expect(plugins.length).toBeGreaterThan(0);
43-
});
44+
expect(plugins).toHaveLength(1);
45+
expect(plugins.find(p => p.name === 'sentry-tanstack-middleware-auto-instrument')).toBeDefined();
46+
});
4447

45-
it('returns no plugins in development mode', () => {
46-
process.env.NODE_ENV = 'development';
48+
it('adds middleware plugin when autoInstrumentMiddleware is true', () => {
49+
process.env.NODE_ENV = 'development';
50+
const plugins = sentryTanstackStart({ autoInstrumentMiddleware: true });
4751

48-
const plugins = sentryTanstackStart({ org: 'test-org' });
52+
expect(plugins).toHaveLength(1);
53+
expect(plugins.find(p => p.name === 'sentry-tanstack-middleware-auto-instrument')).toBeDefined();
54+
});
4955

50-
expect(plugins).toHaveLength(0);
51-
});
56+
it('does not add middleware plugin when autoInstrumentMiddleware is false', () => {
57+
process.env.NODE_ENV = 'development';
58+
const plugins = sentryTanstackStart({ autoInstrumentMiddleware: false });
5259

53-
it('returns Sentry Vite plugins but not enable source maps plugin when sourcemaps.disable is true', () => {
54-
const plugins = sentryTanstackStart({
55-
sourcemaps: { disable: true },
60+
expect(plugins).toHaveLength(0);
5661
});
57-
58-
expect(plugins).toHaveLength(2);
59-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
60-
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
61-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeUndefined();
6262
});
6363

64-
it('returns Sentry Vite plugins but not enable source maps plugin when sourcemaps.disable is "disable-upload"', () => {
65-
const plugins = sentryTanstackStart({
66-
sourcemaps: { disable: 'disable-upload' },
64+
describe('source maps', () => {
65+
it('returns Sentry Vite plugins but not enable source maps plugin when sourcemaps.disable is true', () => {
66+
const plugins = sentryTanstackStart({
67+
autoInstrumentMiddleware: false,
68+
sourcemaps: { disable: true },
69+
});
70+
71+
expect(plugins).toHaveLength(2);
72+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
73+
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
74+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeUndefined();
6775
});
6876

69-
expect(plugins).toHaveLength(2);
70-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
71-
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
72-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeUndefined();
73-
});
77+
it('returns Sentry Vite plugins but not enable source maps plugin when sourcemaps.disable is "disable-upload"', () => {
78+
const plugins = sentryTanstackStart({
79+
autoInstrumentMiddleware: false,
80+
sourcemaps: { disable: 'disable-upload' },
81+
});
7482

75-
it('returns Sentry Vite plugins and enable source maps plugin when sourcemaps.disable is false', () => {
76-
const plugins = sentryTanstackStart({
77-
sourcemaps: { disable: false },
83+
expect(plugins).toHaveLength(2);
84+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
85+
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
86+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeUndefined();
7887
});
7988

80-
expect(plugins).toHaveLength(3);
81-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
82-
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
83-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeDefined();
84-
});
89+
it('returns Sentry Vite plugins and enable source maps plugin when sourcemaps.disable is false', () => {
90+
const plugins = sentryTanstackStart({
91+
autoInstrumentMiddleware: false,
92+
sourcemaps: { disable: false },
93+
});
8594

86-
it('returns Sentry Vite Plugins and enable source maps plugin by default when sourcemaps is not specified', () => {
87-
const plugins = sentryTanstackStart({});
95+
expect(plugins).toHaveLength(3);
96+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
97+
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
98+
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeDefined();
99+
});
88100

89-
expect(plugins).toHaveLength(3);
90-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-source-maps-config')).toBeDefined();
91-
expect(plugins.find(p => p.name === 'sentry-vite-debug-id-upload-plugin')).toBeDefined();
92-
expect(plugins.find(p => p.name === 'sentry-tanstackstart-react-source-maps')).toBeDefined();
101+
it('returns no source maps plugins in development mode', () => {
102+
process.env.NODE_ENV = 'development';
103+
const plugins = sentryTanstackStart({ autoInstrumentMiddleware: false });
104+
105+
expect(plugins).toHaveLength(0);
106+
});
93107
});
94108
});

0 commit comments

Comments
 (0)