1
- import { RequisitionRunner } from './requisition-runners/requisition-runner' ;
2
1
import { NotificationEmitter } from './notifications/notification-emitter' ;
3
- import { EnqueuerAsNodeChildRunner } from "./enqueuer-as-node-child-runner" ;
4
- import { Notifications } from "./notifications/notifications" ;
2
+ import { EnqueuerAsNodeChildRunner } from './enqueuer-as-node-child-runner' ;
3
+ import { Notifications } from './notifications/notifications' ;
4
+ import { ChildRequisitionRunner } from './run-as-child/child-requisition-runner' ;
5
+ import { AssertDescriber } from './run-as-child/assert-describer' ;
6
+ import { ModuleAdder } from './run-as-child/module-adder' ;
7
+ import { ProtocolDescriber } from './run-as-child/protocol-describer' ;
8
+ import { StoreCleaner } from './run-as-child/store-cleaner' ;
5
9
6
10
7
- jest . mock ( './requisition-runners/requisition-runner' ) ;
8
11
jest . mock ( './notifications/notification-emitter' ) ;
12
+ jest . mock ( './run-as-child/child-requisition-runner' ) ;
13
+ jest . mock ( './run-as-child/assert-describer' ) ;
14
+ jest . mock ( './run-as-child/module-adder' ) ;
15
+ jest . mock ( './run-as-child/protocol-describer' ) ;
16
+ jest . mock ( './run-as-child/store-cleaner' ) ;
9
17
10
18
const processOnMock = jest . fn ( ) ;
11
19
process . on = processOnMock ;
12
20
13
21
const processSendMock = jest . fn ( ) ;
14
22
process . send = processSendMock ;
15
23
16
- const runMock = jest . fn ( ) ;
17
- const requisitionRunnerConstructorMock = jest . fn ( ( ) => ( { run : runMock } ) ) ;
24
+ const replierProcessMock = jest . fn ( ) ;
25
+ const replierConstructorMock = jest . fn ( ( ) => ( { process : replierProcessMock } ) ) ;
18
26
// @ts -ignore
19
- RequisitionRunner . mockImplementation ( requisitionRunnerConstructorMock ) ;
27
+ ChildRequisitionRunner . mockImplementation ( replierConstructorMock ) ;
28
+ // @ts -ignore
29
+ AssertDescriber . mockImplementation ( replierConstructorMock ) ;
30
+ // @ts -ignore
31
+ ModuleAdder . mockImplementation ( replierConstructorMock ) ;
32
+ // @ts -ignore
33
+ ProtocolDescriber . mockImplementation ( replierConstructorMock ) ;
34
+ // @ts -ignore
35
+ StoreCleaner . mockImplementation ( replierConstructorMock ) ;
20
36
21
37
let notificationEmitterOnMock = jest . fn ( ) ;
22
38
// @ts -ignore
@@ -26,21 +42,22 @@ describe('EnqueuerAsNodeChildRunner', () => {
26
42
beforeEach ( ( ) => {
27
43
processOnMock . mockClear ( ) ;
28
44
processSendMock . mockClear ( ) ;
29
- requisitionRunnerConstructorMock . mockClear ( ) ;
30
- runMock . mockClear ( ) ;
45
+ replierConstructorMock . mockClear ( ) ;
46
+ replierProcessMock . mockClear ( ) ;
31
47
notificationEmitterOnMock . mockClear ( ) ;
32
48
} ) ;
33
49
34
50
it ( 'should listen to message' , async ( ) => {
35
- const statusCode = await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
51
+ const enqueuerAsNodeChildRunner = new EnqueuerAsNodeChildRunner ( ) ;
52
+ const statusCode = await enqueuerAsNodeChildRunner . execute ( ) ;
36
53
37
54
expect ( statusCode ) . toBe ( 0 ) ;
38
55
expect ( processOnMock . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'message' ) ;
39
56
} ) ;
40
57
41
58
it ( 'should send exit message' , async ( ) => {
42
59
const statusCode = 0 ;
43
- await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
60
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
44
61
45
62
expect ( processOnMock . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'exit' ) ;
46
63
@@ -53,38 +70,73 @@ describe('EnqueuerAsNodeChildRunner', () => {
53
70
} ) ;
54
71
} ) ;
55
72
56
- it ( 'should run enqueuer runner when a message arrives' , async ( ) => {
57
- const requisition = 'value' ;
58
- await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
73
+ it ( 'should do nothing when message is unknown' , async ( ) => {
74
+ const message = { event : 'UNKNOWN' } ;
75
+
76
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
59
77
60
78
const onMessageCallback = processOnMock . mock . calls [ 0 ] [ 1 ] ;
61
- onMessageCallback ( { event : 'runRequisition' , value : requisition } ) ;
62
- expect ( requisitionRunnerConstructorMock ) . toHaveBeenCalledWith ( requisition ) ;
63
- expect ( runMock ) . toHaveBeenCalled ( ) ;
79
+ onMessageCallback ( message ) ;
80
+ expect ( replierProcessMock ) . not . toHaveBeenCalled ( ) ;
64
81
} ) ;
65
82
66
- it ( 'should not run enqueuer when a message arrives but is not a requisitions' , async ( ) => {
67
- await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
83
+ it ( 'should add modules list when requested' , async ( ) => {
84
+ const message = { event : 'ADD_MODULE' , value : 'value' } ;
85
+
86
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
87
+
88
+ const onMessageCallback = processOnMock . mock . calls [ 0 ] [ 1 ] ;
89
+ onMessageCallback ( message ) ;
90
+ expect ( replierConstructorMock ) . toHaveBeenCalled ( ) ;
91
+ expect ( replierProcessMock ) . toHaveBeenCalledWith ( message ) ;
92
+ } ) ;
93
+
94
+ it ( 'should get protocols list when requested' , async ( ) => {
95
+ const message = { event : 'GET_PROTOCOLS' , value : 'value' } ;
96
+
97
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
98
+
99
+ const onMessageCallback = processOnMock . mock . calls [ 0 ] [ 1 ] ;
100
+ onMessageCallback ( message ) ;
101
+ expect ( replierConstructorMock ) . toHaveBeenCalled ( ) ;
102
+ expect ( replierProcessMock ) . toHaveBeenCalledWith ( message ) ;
103
+ } ) ;
104
+
105
+ it ( 'should get asserters list when requested' , async ( ) => {
106
+ const message = { event : 'GET_ASSERTERS' , value : 'value' } ;
107
+
108
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
109
+
110
+ const onMessageCallback = processOnMock . mock . calls [ 0 ] [ 1 ] ;
111
+ onMessageCallback ( message ) ;
112
+ expect ( replierConstructorMock ) . toHaveBeenCalled ( ) ;
113
+ expect ( replierProcessMock ) . toHaveBeenCalledWith ( message ) ;
114
+ } ) ;
115
+
116
+ it ( 'should run enqueuer runner when a message arrives' , async ( ) => {
117
+ const message = { event : 'RUN_REQUISITION' , value : 'value' } ;
118
+
119
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
68
120
69
121
const onMessageCallback = processOnMock . mock . calls [ 0 ] [ 1 ] ;
70
- onMessageCallback ( { event : 'NOT_A REQUISITION' } ) ;
71
- expect ( requisitionRunnerConstructorMock ) . not . toHaveBeenCalled ( ) ;
72
- expect ( runMock ) . not . toHaveBeenCalled ( ) ;
122
+ onMessageCallback ( message ) ;
123
+ expect ( replierConstructorMock ) . toHaveBeenCalled ( ) ;
124
+ expect ( replierProcessMock ) . toHaveBeenCalledWith ( message ) ;
73
125
} ) ;
74
126
75
127
it ( 'should register senders to every notification' , async ( ) => {
76
- await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
128
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
77
129
78
130
const everyNotificationKey = Object . keys ( Notifications )
79
131
. map ( ( key : any ) => Notifications [ key ] )
80
- . filter ( ( key : any ) => typeof key === 'number' )
132
+ . filter ( ( key : any ) => typeof key === 'number' ) ;
81
133
82
134
expect ( notificationEmitterOnMock . mock . calls . map ( ( call : any ) => call [ 0 ] ) )
83
135
. toEqual ( everyNotificationKey ) ;
84
136
} ) ;
85
137
86
- it ( 'should send when notification is emitted' , async ( ) => {
87
- await new EnqueuerAsNodeChildRunner ( ) . execute ( true ) ;
138
+ it ( 'should proxy message when notification is emitted' , async ( ) => {
139
+ await new EnqueuerAsNodeChildRunner ( ) . execute ( ) ;
88
140
89
141
const report = { cycle : { } } ;
90
142
report . cycle = report ;
0 commit comments