@@ -27,7 +27,7 @@ yargs(hideBin(process.argv))
27
27
} )
28
28
. option ( 'env' , {
29
29
alias : 'e' ,
30
- choices : [ 'none' , 'all' , 'combined' ] ,
30
+ choices : [ 'none' , 'all' , 'present' , ' combined'] ,
31
31
default : 'none' ,
32
32
description : 'Output environment format'
33
33
} )
@@ -50,18 +50,22 @@ async function compare({
50
50
fn : f ,
51
51
content : await fs . readFile ( f , 'utf8' )
52
52
} ) ) ) ;
53
+ //console.log(contents);
53
54
const results = contents
54
55
. map ( c => ( {
55
56
fn : c . fn ,
56
57
content : JSON . parse ( c . content ) ,
57
58
// map of test id => assertion
58
59
testMap : new Map ( )
59
60
} ) )
61
+ . map ( c => {
62
+ //console.log('C', c);
63
+ return c ;
64
+ } )
60
65
. map ( c => ( {
61
66
...c ,
62
- // FIXME process properly
63
- env : c . content [ '@included' ] [ 0 ] ,
64
- label : c . content [ '@included' ] [ 0 ] [ 'jldb:label' ]
67
+ env : c . content [ '@included' ] ?. [ 0 ] || { } ,
68
+ label : c . content [ '@included' ] ?. [ 0 ] ?. [ 'jldb:label' ]
65
69
} ) ) ;
66
70
//console.log(JSON.stringify(results, null, 2));
67
71
// order of tests found in each result set
@@ -96,14 +100,17 @@ async function compare({
96
100
hz ( r . testMap . get ( t ) ) ) )
97
101
. map ( d => relative ? d . toFixed ( 2 ) + '%' : d . toFixed ( 2 ) )
98
102
] ) ;
99
- //console.log(compared);
100
- //console.log(results);
103
+ //console.log('COMPARED', compared);
104
+ //console.log('RESULTS', results);
101
105
const fnprefixlen = commonPathPrefix ( file ) . length ;
106
+ function label ( res ) {
107
+ return res . label || res . fn . slice ( fnprefixlen ) ;
108
+ }
102
109
console . log ( '## Comparison' ) ;
103
110
console . log ( markdownTable ( [
104
111
[
105
112
'Test' ,
106
- ...results . map ( r => r . label || r . fn . slice ( fnprefixlen ) )
113
+ ...results . map ( label )
107
114
] ,
108
115
...compared
109
116
] , {
@@ -130,15 +137,58 @@ async function compare({
130
137
[ 'Comment' , 'jldb:comment' ]
131
138
] ;
132
139
140
+ // show all properites
133
141
if ( env === 'all' ) {
134
142
console . log ( ) ;
135
143
console . log ( '## Environment' ) ;
136
- console . log ( markdownTable ( [
137
- envProps . map ( p => p [ 0 ] ) ,
138
- ...results . map ( r => envProps . map ( p => r . env [ p [ 1 ] ] || '' ) )
144
+ //const data = results.map(r => envProps.map(p => {
145
+ // return (p[1] === 'jldb:label') ? label(r) : r.env[p[1]] || '';
146
+ //}));
147
+ const data = results . map ( r => [
148
+ label ( r ) ,
149
+ ...envProps . slice ( 1 ) . map ( p => r . env [ p [ 1 ] ] || '' )
150
+ ] ) ;
151
+ if ( data . length > 0 ) {
152
+ console . log ( markdownTable ( [
153
+ envProps . map ( p => p [ 0 ] ) ,
154
+ ...data
155
+ ] ) ) ;
156
+ } else {
157
+ console . log ( '*not specified*' ) ;
158
+ }
159
+ }
160
+
161
+ // show present properites
162
+ if ( env === 'present' ) {
163
+ console . log ( ) ;
164
+ console . log ( '## Environment' ) ;
165
+ // get all data
166
+ const data = results . map ( r => [
167
+ label ( r ) ,
168
+ ...envProps . slice ( 1 ) . map ( p => r . env [ p [ 1 ] ] || '' )
169
+ ] ) ;
170
+ // count present truthy fields per col
171
+ const propCounts = envProps . slice ( 1 )
172
+ . map ( p => results . reduce ( ( c , r ) => r . env [ p [ 1 ] ] ? ++ c : c , 0 ) ) ;
173
+ const presentProps = [
174
+ envProps [ 0 ] ,
175
+ ...envProps . slice ( 1 ) . filter ( ( v , i ) => propCounts [ i ] > 0 )
176
+ ] ;
177
+ const presentData = data . map ( d => ( [
178
+ d [ 0 ] ,
179
+ ...d . slice ( 1 ) . filter ( ( v , i ) => propCounts [ i ] > 0 )
139
180
] ) ) ;
181
+ if ( data . length > 0 ) {
182
+ console . log ( markdownTable ( [
183
+ presentProps . map ( p => p [ 0 ] ) ,
184
+ ...presentData
185
+ ] ) ) ;
186
+ } else {
187
+ console . log ( '*not specified*' ) ;
188
+ }
140
189
}
141
190
191
+ // show combined grouping of properties
142
192
if ( env === 'combined' ) {
143
193
console . log ( ) ;
144
194
console . log ( '## Environment' ) ;
@@ -149,11 +199,16 @@ async function compare({
149
199
) ;
150
200
return [ key , values . size ? [ ...values ] . join ( ', ' ) : [ ] ] ;
151
201
}
152
- console . log ( markdownTable ( [
153
- [ 'Key' , 'Values' ] ,
154
- ...envProps
155
- . map ( p => envline ( p [ 0 ] , p [ 1 ] ) )
156
- . filter ( p => p [ 1 ] . length )
157
- ] ) ) ;
202
+ const data = envProps
203
+ . map ( p => envline ( p [ 0 ] , p [ 1 ] ) )
204
+ . filter ( p => p [ 1 ] . length ) ;
205
+ if ( data . length > 0 ) {
206
+ console . log ( markdownTable ( [
207
+ [ 'Key' , 'Values' ] ,
208
+ ...data
209
+ ] ) ) ;
210
+ } else {
211
+ console . log ( '*not specified*' ) ;
212
+ }
158
213
}
159
214
}
0 commit comments