@@ -2,36 +2,36 @@ import * as fs from 'fs';
2
2
// import * as net from 'net';
3
3
import * as path from 'path' ;
4
4
import * as temp from 'temp' ;
5
- import { fail } from 'assert' ;
6
5
import { expect } from 'chai' ;
7
6
import { ChildProcess } from 'child_process' ;
8
7
import { safeLoad , safeDump } from 'js-yaml' ;
9
- import { DaemonError , ArduinoDaemonImpl } from '../../node/arduino-daemon-impl' ;
8
+ import { ArduinoDaemonImpl } from '../../node/arduino-daemon-impl' ;
10
9
import { spawnCommand } from '../../node/exec-util' ;
11
10
import { CLI_CONFIG } from '../../node/cli-config' ;
12
11
13
12
const track = temp . track ( ) ;
14
13
15
14
class SilentArduinoDaemonImpl extends ArduinoDaemonImpl {
16
- constructor (
17
- private port : string | number ,
18
- private logFormat : 'text' | 'json'
19
- ) {
15
+ constructor ( private logFormat : 'text' | 'json' ) {
20
16
super ( ) ;
21
17
}
22
18
23
19
onData ( data : string ) : void {
24
20
// NOOP
25
21
}
26
22
27
- async spawnDaemonProcess ( ) : Promise < ChildProcess > {
23
+ async spawnDaemonProcess ( ) : Promise < { daemon : ChildProcess ; port : string } > {
28
24
return super . spawnDaemonProcess ( ) ;
29
25
}
30
26
31
27
protected async getSpawnArgs ( ) : Promise < string [ ] > {
32
28
const cliConfigPath = await this . initCliConfig ( ) ;
33
29
return [
34
30
'daemon' ,
31
+ '--format' ,
32
+ 'jsonmini' ,
33
+ '--port' ,
34
+ '0' ,
35
35
'--config-file' ,
36
36
cliConfigPath ,
37
37
'-v' ,
@@ -53,7 +53,7 @@ class SilentArduinoDaemonImpl extends ArduinoDaemonImpl {
53
53
encoding : 'utf8' ,
54
54
} ) ;
55
55
const cliConfig = safeLoad ( content ) as any ;
56
- cliConfig . daemon . port = String ( this . port ) ;
56
+ // cliConfig.daemon.port = String(this.port);
57
57
const modifiedContent = safeDump ( cliConfig ) ;
58
58
fs . writeFileSync ( path . join ( destDir , CLI_CONFIG ) , modifiedContent , {
59
59
encoding : 'utf8' ,
@@ -113,43 +113,23 @@ describe('arduino-daemon-impl', () => {
113
113
// }
114
114
// });
115
115
116
- it ( 'should parse an error - unknown address [json]' , async ( ) => {
117
- try {
118
- await new SilentArduinoDaemonImpl ( 'foo' , 'json' ) . spawnDaemonProcess ( ) ;
119
- fail ( 'Expected a failure.' ) ;
120
- } catch ( e ) {
121
- expect ( e ) . to . be . instanceOf ( DaemonError ) ;
122
- expect ( e . code ) . to . be . equal ( DaemonError . UNKNOWN_ADDRESS ) ;
123
- }
124
- } ) ;
116
+ it ( 'should parse the port address when the log format is json' , async ( ) => {
117
+ const { daemon, port } = await new SilentArduinoDaemonImpl (
118
+ 'json'
119
+ ) . spawnDaemonProcess ( ) ;
125
120
126
- it ( 'should parse an error - unknown address [text]' , async ( ) => {
127
- try {
128
- await new SilentArduinoDaemonImpl ( 'foo' , 'text' ) . spawnDaemonProcess ( ) ;
129
- fail ( 'Expected a failure.' ) ;
130
- } catch ( e ) {
131
- expect ( e ) . to . be . instanceOf ( DaemonError ) ;
132
- expect ( e . code ) . to . be . equal ( DaemonError . UNKNOWN_ADDRESS ) ;
133
- }
121
+ expect ( port ) . not . to . be . undefined ;
122
+ expect ( port ) . not . to . be . equal ( '0' ) ;
123
+ daemon . kill ( ) ;
134
124
} ) ;
135
125
136
- it ( 'should parse an error - invalid port [json]' , async ( ) => {
137
- try {
138
- await new SilentArduinoDaemonImpl ( - 1 , 'json' ) . spawnDaemonProcess ( ) ;
139
- fail ( 'Expected a failure.' ) ;
140
- } catch ( e ) {
141
- expect ( e ) . to . be . instanceOf ( DaemonError ) ;
142
- expect ( e . code ) . to . be . equal ( DaemonError . INVALID_PORT ) ;
143
- }
144
- } ) ;
126
+ it ( 'should parse the port address when the log format is text' , async ( ) => {
127
+ const { daemon, port } = await new SilentArduinoDaemonImpl (
128
+ 'text'
129
+ ) . spawnDaemonProcess ( ) ;
145
130
146
- it ( 'should parse an error - invalid port [text]' , async ( ) => {
147
- try {
148
- await new SilentArduinoDaemonImpl ( - 1 , 'text' ) . spawnDaemonProcess ( ) ;
149
- fail ( 'Expected a failure.' ) ;
150
- } catch ( e ) {
151
- expect ( e ) . to . be . instanceOf ( DaemonError ) ;
152
- expect ( e . code ) . to . be . equal ( DaemonError . INVALID_PORT ) ;
153
- }
131
+ expect ( port ) . not . to . be . undefined ;
132
+ expect ( port ) . not . to . be . equal ( '0' ) ;
133
+ daemon . kill ( ) ;
154
134
} ) ;
155
135
} ) ;
0 commit comments