GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tanstack.com/scripts/test-npm-cache.ts at main · stackgraph/tanstack.com

Expand file tree

/

test-npm-cache.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
105 lines (94 loc) · 2.94 KB
/

test-npm-cache.ts

Copy path

File metadata and controls

105 lines (94 loc) · 2.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Test script for NPM download chunk caching
* Tests that chunks are properly cached and retrieved
*/
import {
getCachedNpmDownloadChunk,
setCachedNpmDownloadChunk,
} from '../src/utils/npm-download-cache.server'
async function testCache() {
console.log('\n' + '='.repeat(80))
console.log('🧪 Testing NPM Download Chunk Cache')
console.log('='.repeat(80) + '\n')
const testPackage = '@tanstack/react-query'
const testDateFrom = '2024-01-01'
const testDateTo = '2024-06-30'
// Test 1: Cache miss
console.log('Test 1: Cache miss (should return null)')
const miss = await getCachedNpmDownloadChunk(
testPackage,
testDateFrom,
testDateTo,
)
console.log(
` Result: ${miss === null ? '✅ NULL (as expected)' : '❌ Got data (unexpected)'}`,
)
// Test 2: Write to cache
console.log('\nTest 2: Write to cache')
await setCachedNpmDownloadChunk({
packageName: testPackage,
dateFrom: testDateFrom,
dateTo: testDateTo,
binSize: 'daily',
totalDownloads: 100000,
dailyData: [
{ day: '2024-01-01', downloads: 1000 },
{ day: '2024-01-02', downloads: 1100 },
],
isImmutable: false, // Will be calculated
})
console.log(' ✅ Write completed')
// Test 3: Cache hit
console.log('\nTest 3: Cache hit (should return data)')
const hit = await getCachedNpmDownloadChunk(
testPackage,
testDateFrom,
testDateTo,
)
if (hit) {
console.log(` ✅ Got cached data:`)
console.log(` Package: ${hit.packageName}`)
console.log(` Range: ${hit.dateFrom} to ${hit.dateTo}`)
console.log(` Total downloads: ${hit.totalDownloads.toLocaleString()}`)
console.log(` Daily data points: ${hit.dailyData.length}`)
console.log(` Is immutable: ${hit.isImmutable}`)
} else {
console.log(' ❌ Cache miss (unexpected)')
}
// Test 4: Historical chunk (should be immutable)
console.log('\nTest 4: Historical chunk (should be marked immutable)')
const historicalDateFrom = '2023-01-01'
const historicalDateTo = '2023-06-30'
await setCachedNpmDownloadChunk({
packageName: testPackage,
dateFrom: historicalDateFrom,
dateTo: historicalDateTo,
binSize: 'daily',
totalDownloads: 50000,
dailyData: [
{ day: '2023-01-01', downloads: 500 },
{ day: '2023-01-02', downloads: 550 },
],
isImmutable: false, // Will be calculated based on dateTo
})
const historical = await getCachedNpmDownloadChunk(
testPackage,
historicalDateFrom,
historicalDateTo,
)
if (historical) {
console.log(
` Is immutable: ${historical.isImmutable ? '✅ YES (as expected)' : '❌ NO (unexpected)'}`,
)
} else {
console.log(' ❌ Failed to retrieve historical chunk')
}
console.log('\n' + '='.repeat(80))
console.log('✅ Cache tests completed')
console.log('='.repeat(80) + '\n')
process.exit(0)
}
testCache().catch((error) => {
console.error('❌ Test failed:', error)
process.exit(1)
})
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.