@@ -2,36 +2,36 @@ import * as fs from 'fs';
22// import * as net from 'net';
33import * as path from 'path' ;
44import * as temp from 'temp' ;
5- import { fail } from 'assert' ;
65import { expect } from 'chai' ;
76import { ChildProcess } from 'child_process' ;
87import { safeLoad , safeDump } from 'js-yaml' ;
9- import { DaemonError , ArduinoDaemonImpl } from '../../node/arduino-daemon-impl' ;
8+ import { ArduinoDaemonImpl } from '../../node/arduino-daemon-impl' ;
109import { spawnCommand } from '../../node/exec-util' ;
1110import { CLI_CONFIG } from '../../node/cli-config' ;
1211
1312const track = temp . track ( ) ;
1413
1514class SilentArduinoDaemonImpl extends ArduinoDaemonImpl {
16- constructor (
17- private port : string | number ,
18- private logFormat : 'text' | 'json'
19- ) {
15+ constructor ( private logFormat : 'text' | 'json' ) {
2016 super ( ) ;
2117 }
2218
2319 onData ( data : string ) : void {
2420 // NOOP
2521 }
2622
27- async spawnDaemonProcess ( ) : Promise < ChildProcess > {
23+ async spawnDaemonProcess ( ) : Promise < { daemon : ChildProcess ; port : string } > {
2824 return super . spawnDaemonProcess ( ) ;
2925 }
3026
3127 protected async getSpawnArgs ( ) : Promise < string [ ] > {
3228 const cliConfigPath = await this . initCliConfig ( ) ;
3329 return [
3430 'daemon' ,
31+ '--format' ,
32+ 'jsonmini' ,
33+ '--port' ,
34+ '0' ,
3535 '--config-file' ,
3636 cliConfigPath ,
3737 '-v' ,
@@ -53,7 +53,7 @@ class SilentArduinoDaemonImpl extends ArduinoDaemonImpl {
5353 encoding : 'utf8' ,
5454 } ) ;
5555 const cliConfig = safeLoad ( content ) as any ;
56- cliConfig . daemon . port = String ( this . port ) ;
56+ // cliConfig.daemon.port = String(this.port);
5757 const modifiedContent = safeDump ( cliConfig ) ;
5858 fs . writeFileSync ( path . join ( destDir , CLI_CONFIG ) , modifiedContent , {
5959 encoding : 'utf8' ,
@@ -113,43 +113,23 @@ describe('arduino-daemon-impl', () => {
113113 // }
114114 // });
115115
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 ( ) ;
125120
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 ( ) ;
134124 } ) ;
135125
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 ( ) ;
145130
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 ( ) ;
154134 } ) ;
155135} ) ;
0 commit comments