UNPKG

1.42 kBJavaScriptView Raw
1var staticModule = require('../');
2var test = require('tape');
3var concat = require('concat-stream');
4var quote = require('quote-stream');
5var fs = require('fs');
6var path = require('path');
7
8test('stream into a console.log', function (t) {
9 t.plan(1);
10 var sm = staticModule({
11 beep: function () {
12 var q = quote();
13 q.end('eek');
14 return q;
15 }
16 }, { vars: { __dirname: path.join(__dirname, 'brfs') } });
17 readStream('source.js').pipe(sm).pipe(concat(function (body) {
18 t.equal(body.toString('utf8'), 'console.log("eek");\n');
19 }));
20});
21
22test('trickle stream into a console.log', function (t) {
23 t.plan(1);
24 var sm = staticModule({
25 beep: function () {
26 var q = quote();
27 var chunks = [ 'beep', ' boop', ' robots' ];
28 var iv = setInterval(function () {
29 if (chunks.length === 0) {
30 clearInterval(iv);
31 q.end();
32 }
33 else q.write(chunks.shift());
34 }, 10);
35 return q;
36 }
37 }, { vars: { __dirname: path.join(__dirname, 'brfs') } });
38 readStream('source.js').pipe(sm).pipe(concat(function (body) {
39 t.equal(body.toString('utf8'), 'console.log("beep boop robots");\n');
40 }));
41});
42
43function readStream (file) {
44 return fs.createReadStream(path.join(__dirname, 'log', file));
45}