1 | var staticModule = require('../');
|
2 | var test = require('tape');
|
3 | var concat = require('concat-stream');
|
4 | var quote = require('quote-stream');
|
5 | var fs = require('fs');
|
6 | var path = require('path');
|
7 |
|
8 | test('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 |
|
22 | test('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 |
|
43 | function readStream (file) {
|
44 | return fs.createReadStream(path.join(__dirname, 'log', file));
|
45 | }
|