|
| 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 | + * 100)}) |
| 65 | +
|
| 66 | +**Status by file size** |
| 67 | +
|
| 68 | + * 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