File tree 2 files changed +45
-8
lines changed
site/src/components/WorkspaceBuildLogs
2 files changed +45
-8
lines changed Original file line number Diff line number Diff line change
1
+ import { ProvisionerJobLog } from "api/typesGenerated"
2
+ import { groupLogsByStage } from "./WorkspaceBuildLogs"
3
+
4
+ describe ( "groupLogsByStage" , ( ) => {
5
+ it ( "should group them by stage" , ( ) => {
6
+ const input : ProvisionerJobLog [ ] = [
7
+ {
8
+ id : "1" ,
9
+ created_at : "oct 13" ,
10
+ log_source : "provisioner" ,
11
+ log_level : "debug" ,
12
+ stage : "build" ,
13
+ output : "test" ,
14
+ } ,
15
+ {
16
+ id : "2" ,
17
+ created_at : "oct 13" ,
18
+ log_source : "provisioner" ,
19
+ log_level : "debug" ,
20
+ stage : "cleanup" ,
21
+ output : "test" ,
22
+ } ,
23
+ {
24
+ id : "3" ,
25
+ created_at : "oct 13" ,
26
+ log_source : "provisioner" ,
27
+ log_level : "debug" ,
28
+ stage : "cleanup" ,
29
+ output : "done" ,
30
+ } ,
31
+ ]
32
+
33
+ const actual = groupLogsByStage ( input )
34
+
35
+ expect ( actual [ "cleanup" ] . length ) . toBe ( 2 )
36
+ } )
37
+ } )
Original file line number Diff line number Diff line change @@ -10,18 +10,18 @@ const Language = {
10
10
}
11
11
12
12
type Stage = ProvisionerJobLog [ "stage" ]
13
+ type LogsGroupedByStage = Record < Stage , ProvisionerJobLog [ ] >
14
+ type GroupLogsByStageFn = ( logs : ProvisionerJobLog [ ] ) => LogsGroupedByStage
13
15
14
- const groupLogsByStage = ( logs : ProvisionerJobLog [ ] ) => {
15
- const logsByStage : Record < Stage , ProvisionerJobLog [ ] > = { }
16
+ export const groupLogsByStage : GroupLogsByStageFn = ( logs ) => {
17
+ const logsByStage : LogsGroupedByStage = { }
16
18
17
19
for ( const log of logs ) {
18
- // If there is no log in the stage record, add an empty array
19
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
20
- if ( logsByStage [ log . stage ] === undefined ) {
21
- logsByStage [ log . stage ] = [ ]
20
+ if ( log . stage in logsByStage ) {
21
+ logsByStage [ log . stage ] . push ( log )
22
+ } else {
23
+ logsByStage [ log . stage ] = [ log ]
22
24
}
23
-
24
- logsByStage [ log . stage ] . push ( log )
25
25
}
26
26
27
27
return logsByStage
You can’t perform that action at this time.
0 commit comments