|
1 | 1 | importtype{NuxtConfigScriptRegistry}from'../../packages/script/src/runtime/types' |
2 | 2 | import{describe,expect,it}from'vitest' |
3 | | -import{applyAutoInject}from'../../packages/script/src/module' |
| 3 | +import{applyAutoInject,resolveConfiguredProxyDomains}from'../../packages/script/src/module' |
4 | 4 |
|
5 | 5 | describe('applyAutoInject',()=>{ |
6 | 6 | constposthogAutoInject={ |
@@ -89,3 +89,63 @@ describe('applyAutoInject', () => { |
89 | 89 | expect((registryasany).posthog[0].apiHost).toBe('/_analytics/us.i.posthog.com') |
90 | 90 | }) |
91 | 91 | }) |
| 92 | + |
| 93 | +describe('resolveConfiguredProxyDomains',()=>{ |
| 94 | +constumamiProxyConfig={ |
| 95 | +autoInject: { |
| 96 | +configField: 'hostUrl', |
| 97 | +computeValue: (proxyPrefix: string)=>`${proxyPrefix}/cloud.umami.is`, |
| 98 | +}, |
| 99 | +} |
| 100 | + |
| 101 | +it('includes the hostname from a custom scriptInput src',()=>{ |
| 102 | +expect(resolveConfiguredProxyDomains({ |
| 103 | +scriptInput: { |
| 104 | +src: 'https://analytics.example.com/script.js', |
| 105 | +}, |
| 106 | +},umamiProxyConfig)).toEqual(['analytics.example.com']) |
| 107 | +}) |
| 108 | + |
| 109 | +it('includes the hostname from an explicit endpoint field',()=>{ |
| 110 | +expect(resolveConfiguredProxyDomains({ |
| 111 | +hostUrl: 'https://analytics.example.com', |
| 112 | +},umamiProxyConfig)).toEqual(['analytics.example.com']) |
| 113 | +}) |
| 114 | + |
| 115 | +it('ignores relative proxy paths injected by the module',()=>{ |
| 116 | +expect(resolveConfiguredProxyDomains({ |
| 117 | +hostUrl: '/_scripts/p/cloud.umami.is', |
| 118 | +},umamiProxyConfig)).toEqual([]) |
| 119 | +}) |
| 120 | + |
| 121 | +it('deduplicates equivalent domains',()=>{ |
| 122 | +expect(resolveConfiguredProxyDomains({ |
| 123 | +hostUrl: 'https://analytics.example.com', |
| 124 | +scriptInput: { |
| 125 | +src: 'https://analytics.example.com/script.js', |
| 126 | +}, |
| 127 | +},umamiProxyConfig)).toEqual(['analytics.example.com']) |
| 128 | +}) |
| 129 | + |
| 130 | +it('includes additional registry-declared config domain fields',()=>{ |
| 131 | +expect(resolveConfiguredProxyDomains({ |
| 132 | +trackerUrl: 'https://analytics.example.com/matomo.php', |
| 133 | +matomoUrl: 'https://analytics.example.com', |
| 134 | +},{ |
| 135 | +configDomainFields: ['matomoUrl','trackerUrl'], |
| 136 | +})).toEqual(['analytics.example.com']) |
| 137 | +}) |
| 138 | + |
| 139 | +it('handles multiple custom hosts across script and endpoint fields',()=>{ |
| 140 | +expect(resolveConfiguredProxyDomains({ |
| 141 | +scriptUrl: 'https://cdn.analytics.example.com/databuddy.js', |
| 142 | +apiUrl: 'https://events.analytics.example.com', |
| 143 | +},{ |
| 144 | +autoInject: { |
| 145 | +configField: 'apiUrl', |
| 146 | +computeValue: (proxyPrefix: string)=>`${proxyPrefix}/basket.databuddy.cc`, |
| 147 | +}, |
| 148 | +configDomainFields: ['scriptUrl'], |
| 149 | +})).toEqual(['cdn.analytics.example.com','events.analytics.example.com']) |
| 150 | +}) |
| 151 | +}) |
0 commit comments