Skip to content

Commit 5a84cd3

Browse files
authored
chore: add migration status workflow and job for vitest (#6148)
1 parent 6588cf2 commit 5a84cd3

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Migration Status
2+
on:
3+
schedule:
4+
- cron: '0 0 * * *'
5+
workflow_dispatch:
6+
7+
jobs:
8+
vitest:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
12+
- name: Set up Node.js
13+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
14+
with:
15+
node-version: 22
16+
cache: 'npm'
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Run migration script
20+
run: |
21+
node --experimental-strip-types script/vitest-migration-status.mts >> $GITHUB_STEP_SUMMARY

script/vitest-migration-status.mts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import path from 'node:path'
2+
import fs from 'node:fs'
3+
import glob from 'fast-glob'
4+
5+
const directory = path.resolve(import.meta.dirname, '..')
6+
const matches = glob
7+
.sync('**/*.test.{ts,tsx}', {
8+
cwd: directory,
9+
ignore: [
10+
'**/e2e/**',
11+
'**/node_modules/**',
12+
'**/.playwright/**',
13+
'**/lib/**',
14+
'**/dist/**',
15+
'**/lib-esm/**',
16+
'**/storybook-static/**',
17+
'**/.next/**',
18+
'**/*.types.test.{ts,tsx}',
19+
],
20+
})
21+
.map(match => {
22+
const filepath = path.resolve(directory, match)
23+
const stats = fs.statSync(filepath)
24+
return {
25+
filepath,
26+
size: stats.size,
27+
}
28+
})
29+
.sort((a, b) => {
30+
return b.size - a.size
31+
})
32+
33+
const migrated = matches.filter(({filepath}) => {
34+
const contents = fs.readFileSync(filepath, 'utf8')
35+
return contents.match(/from 'vitest'/)
36+
})
37+
38+
const notMigrated = matches.filter(({filepath}) => {
39+
const contents = fs.readFileSync(filepath, 'utf8')
40+
return !contents.match(/from 'vitest'/)
41+
})
42+
43+
let totalSize = 0
44+
45+
for (const {size} of matches) {
46+
totalSize += size
47+
}
48+
49+
let migratedSize = 0
50+
51+
for (const {size} of migrated) {
52+
migratedSize += size
53+
}
54+
55+
console.log(`
56+
# Vitest Migration
57+
58+
This report tracks our status migrating the tests in Primer React from Jest to Vitest.
59+
60+
## Status
61+
62+
**Status by file count**
63+
64+
![Status by file count](https://geps.dev/progress/${Math.floor((migrated.length / matches.length) * 100)})
65+
66+
**Status by file size**
67+
68+
![Status by file size](https://geps.dev/progress/${Math.floor((migratedSize / totalSize) * 100)})
69+
`)
70+
71+
console.log(`
72+
## Not Migrated (${notMigrated.length})
73+
74+
| Filepath | Size (kB) |
75+
| :------- | :-------- |`)
76+
77+
for (const {filepath, size} of notMigrated) {
78+
const relativePath = path.relative(directory, filepath)
79+
const link = `[\`${relativePath}\`](https://github.com/primer/react/blob/main/${relativePath})`
80+
console.log(`| ${link} | ${round(size / 1024)}kB |`)
81+
}
82+
83+
console.log(`## Migrated (${migrated.length})
84+
85+
| Filepath | Size (kB) |
86+
| :------- | :-------- |`)
87+
88+
for (const {filepath, size} of migrated) {
89+
const relativePath = path.relative(directory, filepath)
90+
const link = `[\`${relativePath}\`](https://github.com/primer/react/blob/main/${relativePath})`
91+
console.log(`| ${link} | ${round(size / 1024)}kB |`)
92+
}
93+
94+
function round(value: number): number {
95+
return Math.round((value + Number.EPSILON) * 100) / 100
96+
}

0 commit comments

Comments
 (0)