UNPKG

1.95 kBJavaScriptView Raw
1var test = require('tape');
2var concat = require('concat-stream');
3var quote = require('quote-stream');
4var staticModule = require('../');
5var fs = require('fs');
6var path = require('path');
7
8test('mixed nested objects and streams', function (t) {
9 t.plan(4);
10
11 var expected = [ 12, 'oh hello\n', 555 ];
12 var sm = staticModule({
13 beep: {
14 x: { y: { z: 4 } },
15 quote: {
16 read: function (file) {
17 return fs.createReadStream(file).pipe(quote());
18 }
19 },
20 f: { g: { h: function (n) { return n * 111 } } }
21 }
22 }, { vars: { __dirname: path.join(__dirname, 'mixed') } });
23 readStream('source.js').pipe(sm).pipe(concat(function (body) {
24 Function(['console'],body)({ log: log });
25 t.equal(
26 body.toString('utf8'),
27 '\nconsole.log(4 * 3);'
28 + '\nconsole.log("oh hello\\n");'
29 + '\nconsole.log(555);\n'
30 );
31 function log (msg) { t.equal(msg, expected.shift()) }
32 }));
33});
34
35test('mixed objects and streams', function (t) {
36 t.plan(4);
37
38 var expected = [ 12, 'oh hello\n', 555 ];
39 var sm = staticModule({
40 beep: {
41 x: 4,
42 quote: function (file) {
43 return fs.createReadStream(file).pipe(quote());
44 },
45 f: function (n) { return n * 111 }
46 }
47 }, { vars: { __dirname: path.join(__dirname, 'mixed') } });
48 readStream('unmixed.js').pipe(sm).pipe(concat(function (body) {
49 Function(['console'],body)({ log: log });
50 t.equal(
51 body.toString('utf8'),
52 '\nconsole.log(4 * 3);'
53 + '\nconsole.log("oh hello\\n");'
54 + '\nconsole.log(555);\n'
55 );
56 function log (msg) { t.equal(msg, expected.shift()) }
57 }));
58});
59
60function readStream (file) {
61 return fs.createReadStream(path.join(__dirname, 'mixed', file));
62}