UNPKG

503 BJavaScriptView Raw
1'use strict';
2
3const TapConsumer = require('./tap_consumer');
4
5module.exports = class BrowserTapConsumer {
6 constructor(socket, tapConsumer) {
7 tapConsumer = tapConsumer || new TapConsumer();
8 let stream = tapConsumer.stream;
9 socket.on('tap', msg => {
10 if (!stream.writable) {
11 return;
12 }
13 stream.write(msg + '\n');
14 if (msg.match(/^#\s+ok\s*$/) ||
15 msg.match(/^#\s+fail\s+[0-9]+\s*$/)) {
16 stream.end();
17 }
18 });
19 return tapConsumer;
20 }
21};