Skip to content

Commit 2372d8d

Browse files
committed
Init script to check proxy test filtering coverage
1 parent 8c571a2 commit 2372d8d

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"test:ui": "vitest --ui",
99
"update-env": "tsx scripts/update-env.ts",
1010
"update-known-good": "tsx scripts/update-env.ts --update-known-good",
11-
"postinstall": "husky install"
11+
"postinstall": "husky install",
12+
"check-proxy-coverage": "tsx scripts/check-proxy-coverage.ts"
1213
},
1314
"type": "module",
1415
"workspaces": [

scripts/check-proxy-coverage.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { readFileSync, readdirSync } from 'node:fs'
2+
import { dirname, join } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import {
5+
AssetHubProxyTypes,
6+
CollectivesProxyTypes,
7+
CoretimeProxyTypes,
8+
KusamaProxyTypes,
9+
PeopleProxyTypes,
10+
PolkadotProxyTypes,
11+
} from '../packages/shared/src/helpers/proxyTypes.js'
12+
13+
type ProxyTypeMap = Record<string, number>
14+
15+
interface NetworkProxyTypes {
16+
name: string
17+
proxyTypes: ProxyTypeMap
18+
}
19+
20+
const networks: NetworkProxyTypes[] = [
21+
{ name: 'Polkadot', proxyTypes: PolkadotProxyTypes },
22+
{ name: 'Kusama', proxyTypes: KusamaProxyTypes },
23+
{ name: 'AssetHubPolkadot', proxyTypes: AssetHubProxyTypes },
24+
{ name: 'AssetHubKusama', proxyTypes: AssetHubProxyTypes },
25+
{ name: 'CollectivesPolkadot', proxyTypes: CollectivesProxyTypes },
26+
{ name: 'CoretimePolkadot', proxyTypes: CoretimeProxyTypes },
27+
{ name: 'CoretimeKusama', proxyTypes: CoretimeProxyTypes },
28+
{ name: 'PeoplePolkadot', proxyTypes: PeopleProxyTypes },
29+
{ name: 'PeopleKusama', proxyTypes: PeopleProxyTypes },
30+
]
31+
32+
function findProxyTestSnapshots(dir: string): string[] {
33+
const files: string[] = []
34+
const entries = readdirSync(dir, { withFileTypes: true })
35+
36+
for (const entry of entries) {
37+
const fullPath = join(dir, entry.name)
38+
if (entry.isDirectory()) {
39+
files.push(...findProxyTestSnapshots(fullPath))
40+
} else if (entry.isFile() && entry.name.endsWith('proxy.e2e.test.ts.snap')) {
41+
files.push(fullPath)
42+
}
43+
}
44+
45+
return files
46+
}
47+
48+
function checkProxyTypeTests(network: NetworkProxyTypes, snapshotFiles: string[]): void {
49+
console.log(`\nChecking ${network.name} proxy type test coverage:`)
50+
51+
const proxyTypes = network.proxyTypes
52+
const missingTests: string[] = []
53+
54+
const proxyTypesToCheck = Object.keys(proxyTypes)
55+
56+
// Filter snapshots for this network
57+
const networkSnapshots = snapshotFiles.filter((file) => file.includes(network.name))
58+
59+
for (const proxyTypeName of proxyTypesToCheck) {
60+
const allowed = networkSnapshots.some((file) =>
61+
readFileSync(file, 'utf-8').includes(`allowed proxy calls for ${proxyTypeName}`),
62+
)
63+
const forbidden = networkSnapshots.some((file) =>
64+
readFileSync(file, 'utf-8').includes(`forbidden proxy calls for ${proxyTypeName}`),
65+
)
66+
67+
if (!allowed) missingTests.push(`${proxyTypeName} (allowed tests missing)`)
68+
if (!forbidden) missingTests.push(`${proxyTypeName} (forbidden tests missing)`)
69+
}
70+
71+
if (missingTests.length === 0) {
72+
console.log('✅ All proxy types have both allowed and forbidden test coverage')
73+
} else {
74+
console.log('❌ Missing test coverage for:')
75+
missingTests.forEach((test) => console.log(` - ${test}`))
76+
}
77+
}
78+
79+
function main() {
80+
const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..')
81+
const snapshotFiles = findProxyTestSnapshots(rootDir)
82+
console.log(snapshotFiles)
83+
84+
console.log('Proxy Type Test Coverage Checker')
85+
console.log('===============================')
86+
87+
for (const network of networks) {
88+
checkProxyTypeTests(network, snapshotFiles)
89+
}
90+
}
91+
92+
main()

0 commit comments

Comments
 (0)