@@ -7,41 +7,48 @@ const fs = require('fs-extra');
77const net = require ( 'net' ) ;
88const which = require ( 'which' ) ;
99const kill = require ( 'tree-kill' ) ;
10- const { Given, When, Then, Before, After } = require ( 'cucumber' ) ;
10+ const {
11+ Given,
12+ When,
13+ Then,
14+ Before,
15+ After,
16+ } = require ( 'cucumber' ) ;
1117
12- DREDD_BIN = path . join ( process . cwd ( ) , 'node_modules' , '.bin' , 'dredd' ) ;
1318
19+ const DREDD_BIN = path . join ( process . cwd ( ) , 'node_modules' , '.bin' , 'dredd' ) ;
1420
15- Before ( function ( ) {
21+
22+ Before ( function hook ( ) {
1623 this . dir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'dredd-hooks-template-' ) ) ;
1724 this . env = { ...process . env } ;
1825 this . commands = [ ] ;
1926 this . dataSent = '' ;
2027} ) ;
2128
22- After ( async function ( ) {
29+ After ( async function hook ( ) {
2330 fs . remove ( this . dir ) ;
2431 await util . promisify ( kill ) ( this . proc . pid ) ;
2532} ) ;
2633
2734
28- Given ( / ^ I h a v e " ( [ ^ " ] + ) " c o m m a n d i n s t a l l e d $ / , function ( match ) {
35+ Given ( / ^ I h a v e " ( [ ^ " ] + ) " c o m m a n d i n s t a l l e d $ / , ( match ) => {
2936 const command = match === 'dredd'
3037 ? DREDD_BIN
3138 : match ;
3239 which . sync ( command ) ; // throws if the command is not found
3340} ) ;
3441
35- Given ( / ^ a f i l e n a m e d " ( [ ^ " ] + ) " w i t h : $ / , function ( filename , content ) {
42+ Given ( / ^ a f i l e n a m e d " ( [ ^ " ] + ) " w i t h : $ / , function step ( filename , content ) {
3643 fs . writeFileSync ( path . join ( this . dir , filename ) , content ) ;
3744} ) ;
3845
39- Given ( / ^ I s e t t h e e n v i r o n m e n t v a r i a b l e s t o : $ / , function ( env ) {
46+ Given ( / ^ I s e t t h e e n v i r o n m e n t v a r i a b l e s t o : $ / , function step ( env ) {
4047 this . env = { ...this . env , ...env . rowsHash ( ) } ;
4148} ) ;
4249
4350
44- When ( / ^ I r u n ` ( [ ^ ` ] + ) ` $ / , function ( match ) {
51+ When ( / ^ I r u n ` ( [ ^ ` ] + ) ` $ / , function step ( match ) {
4552 const command = match . replace ( / ^ d r e d d (? = ) / , DREDD_BIN ) ;
4653 this . proc = childProcess . spawnSync ( command , [ ] , {
4754 shell : true ,
@@ -50,16 +57,16 @@ When(/^I run `([^`]+)`$/, function (match) {
5057 } ) ;
5158} ) ;
5259
53- When ( / ^ I r u n ` ( [ ^ ` ] + ) ` i n t e r a c t i v e l y $ / , function ( command ) {
60+ When ( / ^ I r u n ` ( [ ^ ` ] + ) ` i n t e r a c t i v e l y $ / , function step ( command ) {
5461 this . proc = childProcess . spawn ( command , [ ] , {
5562 shell : true ,
5663 cwd : this . dir ,
5764 env : this . env ,
5865 } ) ;
5966} ) ;
6067
61- When ( 'I wait for output to contain {string}' , function ( output , callback ) {
62- const proc = this . proc ;
68+ When ( 'I wait for output to contain {string}' , function step ( output , callback ) {
69+ const { proc } = this ;
6370
6471 function read ( data ) {
6572 if ( data . toString ( ) . includes ( output ) ) {
@@ -73,38 +80,38 @@ When('I wait for output to contain {string}', function (output, callback) {
7380 proc . stderr . on ( 'data' , read ) ;
7481} ) ;
7582
76- When ( 'I connect to the server' , async function ( ) {
83+ When ( 'I connect to the server' , async function step ( ) {
7784 this . socket = new net . Socket ( ) ;
7885 const connect = util . promisify ( this . socket . connect . bind ( this . socket ) ) ;
7986 await connect ( 61321 , '127.0.0.1' ) ;
8087} ) ;
8188
82- When ( 'I send a JSON message to the socket:' , function ( message ) {
89+ When ( 'I send a JSON message to the socket:' , function step ( message ) {
8390 this . socket . write ( message ) ;
8491 this . dataSent += message ;
8592} ) ;
8693
87- When ( 'I send a newline character as a message delimiter to the socket' , function ( ) {
94+ When ( 'I send a newline character as a message delimiter to the socket' , function step ( ) {
8895 this . socket . write ( '\n' ) ;
8996} ) ;
9097
9198
92- Then ( 'the exit status should be {int}' , function ( status ) {
99+ Then ( 'the exit status should be {int}' , function step ( status ) {
93100 expect ( this . proc . status ) . to . equal ( status ) ;
94101} ) ;
95102
96- Then ( 'the output should contain:' , function ( output ) {
103+ Then ( 'the output should contain:' , function step ( output ) {
97104 expect ( this . proc . stdout . toString ( ) + this . proc . stderr . toString ( ) ) . to . contain ( output ) ;
98105} ) ;
99106
100- Then ( 'it should start listening on localhost port {int}' , async function ( port ) {
107+ Then ( 'it should start listening on localhost port {int}' , async function step ( port ) {
101108 this . socket = new net . Socket ( ) ;
102109 const connect = util . promisify ( this . socket . connect . bind ( this . socket ) ) ;
103110 await connect ( port , '127.0.0.1' ) ; // throws if there's an issue
104111 this . socket . end ( ) ;
105112} ) ;
106113
107- Then ( 'I should receive the same response' , function ( callback ) {
114+ Then ( 'I should receive the same response' , function step ( callback ) {
108115 this . socket . on ( 'data' , ( data ) => {
109116 const dataReceived = JSON . parse ( data . toString ( ) ) ;
110117 const dataSent = JSON . parse ( this . dataSent ) ;
@@ -113,6 +120,6 @@ Then('I should receive the same response', function (callback) {
113120 } ) ;
114121} ) ;
115122
116- Then ( 'I should be able to gracefully disconnect' , function ( ) {
123+ Then ( 'I should be able to gracefully disconnect' , function step ( ) {
117124 this . socket . end ( ) ;
118125} ) ;
0 commit comments