|
| 1 | +import * as assert from 'assert/strict'; |
1 | 2 | import { |
2 | | - loadSourcemapUploadRecords, |
3 | | - assertSourcemapUploadRequests, |
4 | | - getArtifactBundleManifests, |
5 | | - assertDebugIdPairs, |
6 | | - assertSourcemapMappings, |
7 | | - assertSourcemapSources, |
8 | | - assertArtifactBundleAssembly, |
9 | | - getSourcemapUploadSummary, |
| 3 | + loadMockServerResults, |
| 4 | + getArtifactBundles, |
| 5 | + getDebugIdPairs, |
| 6 | + getSourcemaps, |
| 7 | + getChunkUploadPosts, |
| 8 | + getAssembleRequests, |
10 | 9 | } from '@sentry-internal/test-utils'; |
11 | 10 |
|
12 | | -const requests = loadSourcemapUploadRecords(); |
| 11 | +const requests = loadMockServerResults(); |
13 | 12 |
|
14 | 13 | console.log(`Captured ${requests.length} requests to mock Sentry server:\n`); |
15 | 14 | for (const req of requests) { |
16 | 15 | console.log(` ${req.method} ${req.url} (${req.bodySize} bytes)`); |
17 | 16 | } |
18 | 17 | console.log(''); |
19 | 18 |
|
20 | | -assertSourcemapUploadRequests(requests, 'fake-auth-token'); |
| 19 | +// Auth token is present |
| 20 | +const authenticated = requests.filter(r => r.authorization.includes('fake-auth-token')); |
| 21 | +assert.ok(authenticated.length > 0, 'Expected requests with the configured auth token'); |
21 | 22 |
|
22 | | -const manifests = getArtifactBundleManifests(requests); |
23 | | -console.log(`Found ${manifests.length} artifact bundle manifest(s):\n`); |
| 23 | +// Chunk uploads happened |
| 24 | +const chunkPosts = getChunkUploadPosts(requests); |
| 25 | +assert.ok(chunkPosts.length > 0, 'Expected at least one chunk upload POST'); |
| 26 | +assert.ok( |
| 27 | + chunkPosts.some(r => r.bodySize > 0), |
| 28 | + 'Expected at least one chunk upload with a non-empty body', |
| 29 | +); |
24 | 30 |
|
25 | | -const debugIdPairs = assertDebugIdPairs(manifests); |
26 | | -console.log(`Found ${debugIdPairs.length} JS/sourcemap pairs with debug IDs:`); |
| 31 | +// Release endpoint was called |
| 32 | +assert.ok( |
| 33 | + requests.some(r => r.url?.includes('/releases/')), |
| 34 | + 'Expected at least one request to releases endpoint', |
| 35 | +); |
| 36 | + |
| 37 | +// Artifact bundles have manifests |
| 38 | +const bundles = getArtifactBundles(requests); |
| 39 | +assert.ok(bundles.length > 0, 'Expected at least one artifact bundle with a manifest'); |
| 40 | +console.log(`Found ${bundles.length} artifact bundle(s)\n`); |
| 41 | + |
| 42 | +// Debug ID pairs exist and are valid UUIDs |
| 43 | +const debugIdPairs = getDebugIdPairs(bundles); |
| 44 | +assert.ok(debugIdPairs.length > 0, 'Expected at least one JS/sourcemap pair with matching debug IDs'); |
| 45 | + |
| 46 | +const uuidRegex = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i; |
27 | 47 | for (const pair of debugIdPairs) { |
| 48 | + assert.match(pair.debugId, uuidRegex, `Invalid debug ID: ${pair.debugId}`); |
28 | 49 | console.log(` ${pair.debugId} ${pair.jsUrl}`); |
29 | 50 | } |
30 | 51 | console.log(''); |
31 | 52 |
|
32 | | -assertSourcemapMappings(manifests); |
33 | | -assertSourcemapSources(manifests, /client-page|page\.tsx/); |
34 | | -assertArtifactBundleAssembly(requests, 'test-project'); |
| 53 | +// Sourcemaps have real content |
| 54 | +const sourcemaps = getSourcemaps(bundles); |
| 55 | +assert.ok( |
| 56 | + sourcemaps.some(s => s.sourcemap.mappings && s.sourcemap.mappings.length > 0), |
| 57 | + 'Expected at least one sourcemap with non-empty mappings', |
| 58 | +); |
35 | 59 |
|
36 | | -const summary = getSourcemapUploadSummary(requests, manifests, debugIdPairs); |
| 60 | +// At least one sourcemap references app source files |
| 61 | +assert.ok( |
| 62 | + sourcemaps.some(s => s.sourcemap.sources?.some(src => /client-page|page\.tsx/.test(src))), |
| 63 | + 'Expected at least one sourcemap referencing app source files', |
| 64 | +); |
| 65 | + |
| 66 | +// Assemble requests reference the correct project |
| 67 | +const assembleReqs = getAssembleRequests(requests); |
| 68 | +assert.ok(assembleReqs.length > 0, 'Expected at least one assemble request'); |
| 69 | +for (const req of assembleReqs) { |
| 70 | + assert.ok(req.assembleBody?.projects?.includes('test-project'), 'Expected assemble request to include test-project'); |
| 71 | + assert.ok((req.assembleBody?.chunks?.length ?? 0) > 0, 'Expected assemble request to have chunk checksums'); |
| 72 | +} |
37 | 73 |
|
38 | | -console.log('\nAll sourcemap upload assertions passed!'); |
39 | | -console.log(` - ${summary.totalRequests} total requests captured`); |
40 | | -console.log(` - ${summary.chunkUploadPosts} chunk upload POST requests`); |
41 | | -console.log(` - ${summary.artifactBundles} artifact bundles with manifests`); |
42 | | -console.log(` - ${summary.debugIdPairs} JS/sourcemap pairs with debug IDs`); |
43 | | -console.log(` - ${summary.assembleRequests} artifact bundle assemble requests`); |
| 74 | +console.log('All sourcemap upload assertions passed!'); |
0 commit comments