|
6 | 6 | constructWrappedFunctionExportQuery,
|
7 | 7 | extractFunctionReexportQueryParameters,
|
8 | 8 | findDefaultSdkInitFile,
|
| 9 | + getExternalOptionsWithSentryNuxt, |
9 | 10 | getFilenameFromNodeStartCommand,
|
10 | 11 | QUERY_END_INDICATOR,
|
11 | 12 | removeSentryQueryFromPath,
|
@@ -366,3 +367,60 @@ export { foo_sentryWrapped as foo };
|
366 | 367 | expect(result).toBe('');
|
367 | 368 | });
|
368 | 369 | });
|
| 370 | + |
| 371 | +describe('getExternalOptionsWithSentryNuxt', () => { |
| 372 | + it('should return sentryExternals when previousExternal is undefined', () => { |
| 373 | + const result = getExternalOptionsWithSentryNuxt(undefined); |
| 374 | + expect(result).toEqual(/^@sentry\/nuxt$/); |
| 375 | + }); |
| 376 | + |
| 377 | + it('should merge sentryExternals with array previousExternal', () => { |
| 378 | + const previousExternal = [/vue/, 'react']; |
| 379 | + const result = getExternalOptionsWithSentryNuxt(previousExternal); |
| 380 | + expect(result).toEqual([/^@sentry\/nuxt$/, /vue/, 'react']); |
| 381 | + }); |
| 382 | + |
| 383 | + it('should create array with sentryExternals and non-array previousExternal', () => { |
| 384 | + const previousExternal = 'vue'; |
| 385 | + const result = getExternalOptionsWithSentryNuxt(previousExternal); |
| 386 | + expect(result).toEqual([/^@sentry\/nuxt$/, 'vue']); |
| 387 | + }); |
| 388 | + |
| 389 | + it('should create a proxy when previousExternal is a function', () => { |
| 390 | + const mockExternalFn = vi.fn().mockReturnValue(false); |
| 391 | + const result = getExternalOptionsWithSentryNuxt(mockExternalFn); |
| 392 | + |
| 393 | + expect(typeof result).toBe('function'); |
| 394 | + expect(result).toBeInstanceOf(Function); |
| 395 | + }); |
| 396 | + |
| 397 | + it('should return true from proxied function when source is @sentry/nuxt', () => { |
| 398 | + const mockExternalFn = vi.fn().mockReturnValue(false); |
| 399 | + const result = getExternalOptionsWithSentryNuxt(mockExternalFn); |
| 400 | + |
| 401 | + // @ts-expect-error - result is a function |
| 402 | + const output = result('@sentry/nuxt', undefined, false); |
| 403 | + expect(output).toBe(true); |
| 404 | + expect(mockExternalFn).not.toHaveBeenCalled(); |
| 405 | + }); |
| 406 | + |
| 407 | + it('should return false from proxied function and call function when source just includes @sentry/nuxt', () => { |
| 408 | + const mockExternalFn = vi.fn().mockReturnValue(false); |
| 409 | + const result = getExternalOptionsWithSentryNuxt(mockExternalFn); |
| 410 | + |
| 411 | + // @ts-expect-error - result is a function |
| 412 | + const output = result('@sentry/nuxt/dist/index.js', undefined, false); |
| 413 | + expect(output).toBe(false); |
| 414 | + expect(mockExternalFn).toHaveBeenCalledWith('@sentry/nuxt/dist/index.js', undefined, false); |
| 415 | + }); |
| 416 | + |
| 417 | + it('should call original function when source does not include @sentry/nuxt', () => { |
| 418 | + const mockExternalFn = vi.fn().mockReturnValue(false); |
| 419 | + const result = getExternalOptionsWithSentryNuxt(mockExternalFn); |
| 420 | + |
| 421 | + // @ts-expect-error - result is a function |
| 422 | + const output = result('vue', undefined, false); |
| 423 | + expect(output).toBe(false); |
| 424 | + expect(mockExternalFn).toHaveBeenCalledWith('vue', undefined, false); |
| 425 | + }); |
| 426 | +}); |
0 commit comments