Skip to content

Commit f09d209

Browse files
committed
Use mocks
Behavior for REPL tests has been inconsistent across the board. For example, see https://ci.appveyor.com/project/kgryte/stdlib/build/2659/job/bi7n1aynmty3yhvr In short, `close` events would often not fire and the process would die, causing downstream events, such as subsequent tests would never run. The main aim of the REPL tests is to ensure that a REPL starts, with an eye toward ensuring that all dependencies are capable of being loaded into the REPL (i.e., no broken requires). Using mocks still satisfies these concerns, as the REPL context is still populated on the mock REPL dependency.
1 parent 697b5a7 commit f09d209

File tree

1 file changed

+41
-22
lines changed
  • lib/node_modules/@stdlib/repl/test

1 file changed

+41
-22
lines changed

lib/node_modules/@stdlib/repl/test/test.js

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// MODULES //
44

55
var tape = require( 'tape' );
6+
var proxyquire = require( 'proxyquire' );
67
var noop = require( '@stdlib/utils/noop' );
78
var repl = require( './../lib' );
89

@@ -100,45 +101,63 @@ tape( 'the function throws an error if provided a callback argument which is not
100101
});
101102

102103
tape( 'the function starts a REPL environment', function test( t ) {
104+
var repl;
105+
var mock;
106+
107+
mock = {
108+
'start': start
109+
};
110+
111+
repl = proxyquire( './../lib/repl.js', {
112+
'repl': mock
113+
});
114+
103115
repl( onStart );
104116

117+
function start() {
118+
return {
119+
'context': {}
120+
};
121+
}
122+
105123
function onStart( error, server ) {
106124
if ( error ) {
107125
t.ok( false, error.message );
108-
return t.end();
126+
} else {
127+
t.ok( true, 'starts a REPL' );
128+
t.ok( server, 'returns a REPL server' );
109129
}
110-
t.ok( true, 'starts a REPL' );
111-
server.rli.on( 'close', onClose );
112-
server.rli.write( '.exit\n' );
113-
}
114-
115-
function onClose() {
116-
setTimeout( onEnd, 1000 );
117-
}
118-
119-
function onEnd() {
120130
t.end();
121131
}
122132
});
123133

124134
tape( 'the function starts a REPL environment (options)', function test( t ) {
135+
var repl;
136+
var mock;
137+
138+
mock = {
139+
'start': start
140+
};
141+
142+
repl = proxyquire( './../lib/repl.js', {
143+
'repl': mock
144+
});
145+
125146
repl( {}, onStart );
126147

148+
function start() {
149+
return {
150+
'context': {}
151+
};
152+
}
153+
127154
function onStart( error, server ) {
128155
if ( error ) {
129156
t.ok( false, error.message );
130-
return t.end();
157+
} else {
158+
t.ok( true, 'starts a REPL' );
159+
t.ok( server, 'returns a REPL server' );
131160
}
132-
t.ok( true, 'starts a REPL' );
133-
server.rli.on( 'close', onClose );
134-
server.rli.write( '.exit\n' );
135-
}
136-
137-
function onClose() {
138-
setTimeout( onEnd, 1000 );
139-
}
140-
141-
function onEnd() {
142161
t.end();
143162
}
144163
});

0 commit comments

Comments
 (0)