FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sim/scripts/check-script-test-coverage.ts at main · simstudioai/sim · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
simstudioai
/
sim
Public
Notifications
You must be signed in to change notification settings
Fork
3.8k
Star
29.5k
Code
Issues
119
Pull requests
194
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sim
/
scripts
/
check-script-test-coverage.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (60 loc) · 2.59 KB
Breadcrumbs
sim
/
scripts
/
check-script-test-coverage.ts
Copy path
File metadata and controls
71 lines (60 loc) · 2.59 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
#!/usr/bin/env bun
/**
* Asserts every `scripts/*.test.ts` file is reachable from the root `test` script.
*
* The root `test` script chains a hand-maintained list of `test:*` entries, and a hand-maintained
* list silently drifts from the files on disk: a test added without a matching entry never runs,
* in CI or locally, and nothing reports it. `scripts/check-migrations-safety.test.ts` sat
* unreferenced and green for exactly that reason.
*
* `run-audits.ts` derives its own list from the `check:*` namespace precisely so a new audit is
* picked up by default, so this guard registers itself simply by being named `check:*` — it cannot
* drift out of the runner it belongs to.
*/
import
{
readdirSync
}
from
'node:fs'
import
path
from
'node:path'
const
ROOT
=
path
.
resolve
(
import
.
meta
.
dir
,
'..'
)
const
TEST_FILE_PATTERN
=
/
s
c
r
i
p
t
s
\/
[
\w
.
-
]
+
\.
t
e
s
t
\.
t
s
/
g
const
SUB_SCRIPT_PATTERN
=
/
b
u
n
r
u
n
(
[
\w
:
-
]
+
)
/
g
const
manifest
=
await
Bun
.
file
(
path
.
join
(
ROOT
,
'package.json'
)
)
.
json
(
)
const
commands
=
manifest
.
scripts
as
Record
<
string
,
string
>
/** Walks the `test` script and every `test:*` entry it chains, collecting referenced test files. */
function
reachableTestFiles
(
entry
:
string
)
:
Set
<
string
>
{
const
referenced
=
new
Set
<
string
>
(
)
const
seen
=
new
Set
<
string
>
(
)
const
queue
=
[
entry
]
while
(
queue
.
length
>
0
)
{
const
name
=
queue
.
pop
(
)
as
string
if
(
seen
.
has
(
name
)
)
continue
seen
.
add
(
name
)
const
command
=
commands
[
name
]
if
(
command
===
undefined
)
continue
for
(
const
match
of
command
.
matchAll
(
TEST_FILE_PATTERN
)
)
referenced
.
add
(
match
[
0
]
)
for
(
const
match
of
command
.
matchAll
(
SUB_SCRIPT_PATTERN
)
)
queue
.
push
(
match
[
1
]
)
}
return
referenced
}
const
onDisk
=
readdirSync
(
path
.
join
(
ROOT
,
'scripts'
)
)
.
filter
(
(
file
)
=>
file
.
endsWith
(
'.test.ts'
)
)
.
map
(
(
file
)
=>
`scripts/
${
file
}
`
)
.
sort
(
)
const
reachable
=
reachableTestFiles
(
'test'
)
const
orphaned
=
onDisk
.
filter
(
(
file
)
=>
!
reachable
.
has
(
file
)
)
const
missing
=
[
...
reachable
]
.
filter
(
(
file
)
=>
!
onDisk
.
includes
(
file
)
)
.
sort
(
)
if
(
orphaned
.
length
>
0
||
missing
.
length
>
0
)
{
if
(
orphaned
.
length
>
0
)
{
console
.
error
(
`Script tests never run by \`bun run test\`:\n
${
orphaned
.
map
(
(
file
)
=>
` -
${
file
}
`
)
.
join
(
'\n'
)
}
\n`
+
'Add a `test:*` entry for each and chain it into the root `test` script.'
)
}
if
(
missing
.
length
>
0
)
{
console
.
error
(
`Root \`test\` script references script tests that do not exist:\n
${
missing
.
map
(
(
file
)
=>
` -
${
file
}
`
)
.
join
(
'\n'
)
}
`
)
}
process
.
exit
(
1
)
}
console
.
log
(
`Script test coverage passed:
${
onDisk
.
length
}
script tests reachable from \`bun run test\`.`
)
Back
|
FazBrowse Home
|
New Git URL