1
- import { record } from 'type-plus'
1
+ import { compile } from 'handlebars'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import { AwaitedProp , record } from 'type-plus'
2
5
import { CompileResult , PackageCompileResults , compileProject } from './logic/compile'
3
6
import { getTestSubjects , toImportMap } from './logic/project'
4
7
import { RuntimeResult , runProject } from './logic/runtime'
@@ -19,45 +22,94 @@ export function getTestResults(ctx: {
19
22
compileResults : compileResults [ moduleType ] ,
20
23
runtimeResults
21
24
} ) ) ) )
22
- ) . then ( collectTestResults )
25
+ )
23
26
}
24
27
}
25
28
26
- function collectTestResults ( results : Array < {
27
- moduleType : string
28
- compileResults : PackageCompileResults ,
29
- runtimeResults : Array < RuntimeResult >
30
- } > ) {
29
+ type TestSubjectsContext = ReturnType < typeof getTestSubjects >
30
+ type TestResultsContext = AwaitedProp < ReturnType < typeof getTestResults > , 'results' >
31
+
32
+ export function genTestResults (
33
+ ctx : TestSubjectsContext & TestResultsContext ) {
34
+ const results = collectTestResults ( ctx )
35
+ const template = compile ( fs . readFileSync ( path . join ( __dirname , '../templates/test-results.hbs' ) , 'utf8' ) )
36
+ return template ( results )
37
+ }
38
+
39
+ function collectTestResults ( { subjects, results } : TestSubjectsContext & TestResultsContext ) {
31
40
const errors = toErrorRecord ( results )
32
41
return {
33
42
results : results . flatMap ( ( { moduleType, compileResults, runtimeResults } ) => {
34
- return runtimeResults . flatMap ( ( r , i ) => {
43
+ return subjects . flatMap ( ( s , i ) => {
44
+ const compileResult = compileResults [ s . name ]
45
+ const runtimeResult = runtimeResults . find ( r => r . name === s . name )
35
46
return [ {
36
47
moduleType : i === 0 ? moduleType : undefined ,
37
- package : r . package ,
48
+ package : s . name ,
38
49
type : '💻 compile' ,
39
- ...toImportMap ( compileResults [ r . package ] ? .map ( c => {
50
+ ...toImportMap ( compileResult ? compileResult . map ( c => {
40
51
const error = errors . compile . find ( e => e . message === c . messageText )
41
52
return {
42
53
importType : c . importType ,
43
54
transient : c . transient ,
44
55
value : error ?. key ?? ''
45
56
}
46
- } ) )
57
+ } ) : ( s . files . length === 0 ? [
58
+ { importType : 'default' , notApply : true } ,
59
+ { importType : 'default-as' , notApply : true } ,
60
+ { importType : 'star' , notApply : true } ,
61
+ ] : [
62
+ { importType : 'default' , } ,
63
+ { importType : 'default-as' } ,
64
+ { importType : 'star' } ,
65
+ ] ) )
47
66
} , {
48
- moduleType : undefined ,
49
- package : r . package ,
50
67
type : '🏃 runtime' ,
51
- ...toImportMap ( r . results . map ( r => {
68
+ ...toImportMap ( runtimeResult ? runtimeResult . results . map ( r => {
52
69
const error = errors . runtime . find ( e => e . message === extractRuntimeErrorMessage ( r . error ) )
53
70
return {
54
71
importType : r . importType ,
55
72
transient : false ,
56
73
value : error ?. key ?? ''
57
74
}
58
- } ) )
75
+ } ) : ( s . files . length === 0 ? [
76
+ { importType : 'default' , notApply : true } ,
77
+ { importType : 'default-as' , notApply : true } ,
78
+ { importType : 'star' , notApply : true } ,
79
+ ] : [
80
+ { importType : 'default' , } ,
81
+ { importType : 'default-as' } ,
82
+ { importType : 'star' } ,
83
+ ] ) )
59
84
} ]
60
85
} )
86
+ // return runtimeResults.flatMap((r, i) => {
87
+ // return [{
88
+ // moduleType: i === 0 ? moduleType : undefined,
89
+ // package: r.name,
90
+ // type: '💻 compile',
91
+ // ...toImportMap(compileResults[r.name]?.map(c => {
92
+ // const error = errors.compile.find(e => e.message === c.messageText)
93
+ // return {
94
+ // importType: c.importType,
95
+ // transient: c.transient,
96
+ // value: error?.key ?? ''
97
+ // }
98
+ // }))
99
+ // }, {
100
+ // moduleType: undefined,
101
+ // package: r.name,
102
+ // type: '🏃 runtime',
103
+ // ...toImportMap(r.results.map(r => {
104
+ // const error = errors.runtime.find(e => e.message === extractRuntimeErrorMessage(r.error))
105
+ // return {
106
+ // importType: r.importType,
107
+ // transient: false,
108
+ // value: error?.key ?? ''
109
+ // }
110
+ // }))
111
+ // }]
112
+ // })
61
113
} ) ,
62
114
errors : [ ...errors . compile , ...errors . runtime ]
63
115
}
0 commit comments