|
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import type { SentryNuxtModuleOptions } from '../../src/common/types'; |
| 3 | +import { getPluginOptions } from '../../src/vite/sourceMaps'; |
| 4 | + |
| 5 | +describe('getPluginOptions', () => { |
| 6 | + beforeEach(() => { |
| 7 | + vi.resetModules(); |
| 8 | + process.env = {}; |
| 9 | + }); |
| 10 | + |
| 11 | + it('uses environment variables when no moduleOptions are provided', () => { |
| 12 | + const defaultEnv = { |
| 13 | + SENTRY_ORG: 'default-org', |
| 14 | + SENTRY_PROJECT: 'default-project', |
| 15 | + SENTRY_AUTH_TOKEN: 'default-token', |
| 16 | + }; |
| 17 | + |
| 18 | + process.env = { ...defaultEnv }; |
| 19 | + |
| 20 | + const options = getPluginOptions({} as SentryNuxtModuleOptions); |
| 21 | + |
| 22 | + expect(options).toEqual( |
| 23 | + expect.objectContaining({ |
| 24 | + org: 'default-org', |
| 25 | + project: 'default-project', |
| 26 | + authToken: 'default-token', |
| 27 | + telemetry: true, |
| 28 | + sourcemaps: expect.objectContaining({ |
| 29 | + rewriteSources: expect.any(Function), |
| 30 | + }), |
| 31 | + _metaOptions: expect.objectContaining({ |
| 32 | + telemetry: expect.objectContaining({ |
| 33 | + metaFramework: 'nuxt', |
| 34 | + }), |
| 35 | + }), |
| 36 | + debug: false, |
| 37 | + }), |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it('returns default options when no moduleOptions are provided', () => { |
| 42 | + const options = getPluginOptions({} as SentryNuxtModuleOptions); |
| 43 | + |
| 44 | + expect(options.org).toBeUndefined(); |
| 45 | + expect(options.project).toBeUndefined(); |
| 46 | + expect(options.authToken).toBeUndefined(); |
| 47 | + expect(options).toEqual( |
| 48 | + expect.objectContaining({ |
| 49 | + telemetry: true, |
| 50 | + sourcemaps: expect.objectContaining({ |
| 51 | + rewriteSources: expect.any(Function), |
| 52 | + }), |
| 53 | + _metaOptions: expect.objectContaining({ |
| 54 | + telemetry: expect.objectContaining({ |
| 55 | + metaFramework: 'nuxt', |
| 56 | + }), |
| 57 | + }), |
| 58 | + debug: false, |
| 59 | + }), |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it('merges custom moduleOptions with default options', () => { |
| 64 | + const customOptions: SentryNuxtModuleOptions = { |
| 65 | + sourceMapsUploadOptions: { |
| 66 | + org: 'custom-org', |
| 67 | + project: 'custom-project', |
| 68 | + authToken: 'custom-token', |
| 69 | + telemetry: false, |
| 70 | + sourcemaps: { |
| 71 | + assets: ['custom-assets/**/*'], |
| 72 | + ignore: ['ignore-this.js'], |
| 73 | + filesToDeleteAfterUpload: ['delete-this.js'], |
| 74 | + }, |
| 75 | + }, |
| 76 | + debug: true, |
| 77 | + }; |
| 78 | + const options = getPluginOptions(customOptions); |
| 79 | + expect(options).toEqual( |
| 80 | + expect.objectContaining({ |
| 81 | + org: 'custom-org', |
| 82 | + project: 'custom-project', |
| 83 | + authToken: 'custom-token', |
| 84 | + telemetry: false, |
| 85 | + sourcemaps: expect.objectContaining({ |
| 86 | + assets: ['custom-assets/**/*'], |
| 87 | + ignore: ['ignore-this.js'], |
| 88 | + filesToDeleteAfterUpload: ['delete-this.js'], |
| 89 | + rewriteSources: expect.any(Function), |
| 90 | + }), |
| 91 | + _metaOptions: expect.objectContaining({ |
| 92 | + telemetry: expect.objectContaining({ |
| 93 | + metaFramework: 'nuxt', |
| 94 | + }), |
| 95 | + }), |
| 96 | + debug: true, |
| 97 | + }), |
| 98 | + ); |
| 99 | + }); |
| 100 | + |
| 101 | + it('overrides options that were undefined with options from unstable_sentryRollupPluginOptions', () => { |
| 102 | + const customOptions: SentryNuxtModuleOptions = { |
| 103 | + sourceMapsUploadOptions: { |
| 104 | + org: 'custom-org', |
| 105 | + project: 'custom-project', |
| 106 | + sourcemaps: { |
| 107 | + assets: ['custom-assets/**/*'], |
| 108 | + filesToDeleteAfterUpload: ['delete-this.js'], |
| 109 | + }, |
| 110 | + }, |
| 111 | + debug: true, |
| 112 | + unstable_sentryBundlerPluginOptions: { |
| 113 | + org: 'unstable-org', |
| 114 | + sourcemaps: { |
| 115 | + assets: ['unstable-assets/**/*'], |
| 116 | + }, |
| 117 | + release: { |
| 118 | + name: 'test-release', |
| 119 | + }, |
| 120 | + }, |
| 121 | + }; |
| 122 | + const options = getPluginOptions(customOptions); |
| 123 | + expect(options).toEqual( |
| 124 | + expect.objectContaining({ |
| 125 | + debug: true, |
| 126 | + org: 'unstable-org', |
| 127 | + project: 'custom-project', |
| 128 | + sourcemaps: expect.objectContaining({ |
| 129 | + assets: ['unstable-assets/**/*'], |
| 130 | + filesToDeleteAfterUpload: ['delete-this.js'], |
| 131 | + rewriteSources: expect.any(Function), |
| 132 | + }), |
| 133 | + release: expect.objectContaining({ |
| 134 | + name: 'test-release', |
| 135 | + }), |
| 136 | + }), |
| 137 | + ); |
| 138 | + }); |
| 139 | +}); |
0 commit comments