33 * Physics, network and SVG generation are mocked out; only input wiring is asserted.
44 */
55
6- import { afterEach , beforeEach , describe , expect , it , mock } from 'bun:test'
6+ import {
7+ afterEach ,
8+ beforeEach ,
9+ describe ,
10+ expect ,
11+ it ,
12+ mock ,
13+ spyOn
14+ } from 'bun:test'
715import { mkdtempSync , readFileSync , writeFileSync } from 'node:fs'
816import { tmpdir } from 'node:os'
917import { join } from 'node:path'
18+ import * as gensvgModule from '../src/gensvg'
1019import { run } from '../src/main'
1120
1221let captured : Record < string , unknown > | null = null
1322
14- mock . module ( '../src/gensvg.ts' , ( ) => ( {
15- gensvg : async ( options : Record < string , unknown > ) => {
16- captured = options
17- return '<svg />'
18- }
19- } ) )
20-
2123/** main.ts 读取的全部输入(@actions/core 按 INPUT_<NAME> 大写读取) */
2224const INPUT_NAMES = [
2325 'USERNAME' ,
@@ -48,6 +50,11 @@ let workDir = ''
4850beforeEach ( ( ) => {
4951 for ( const name of INPUT_NAMES ) delete process . env [ `INPUT_${ name } ` ]
5052 captured = null
53+ // 只替换 gensvg,避免跑真实物理与网络;spyOn 可被 restore,不会泄漏到其他测试文件
54+ spyOn ( gensvgModule , 'gensvg' ) . mockImplementation ( async ( options ) => {
55+ captured = options as Record < string , unknown >
56+ return '<svg />'
57+ } )
5158 process . exitCode = 0
5259 workDir = mkdtempSync ( join ( tmpdir ( ) , 'github-gravity-' ) )
5360 process . env . GITHUB_OUTPUT = join ( workDir , 'output.txt' )
@@ -60,6 +67,7 @@ beforeEach(() => {
6067
6168afterEach ( ( ) => {
6269 for ( const name of INPUT_NAMES ) delete process . env [ `INPUT_${ name } ` ]
70+ mock . restore ( )
6371 process . exitCode = 0
6472} )
6573
0 commit comments