UNPKG

813 BJavaScriptView Raw
1var test = require('tape');
2var concat = require('concat-stream');
3var staticModule = require('../');
4var fs = require('fs');
5var path = require('path');
6
7test('nested object', function (t) {
8 t.plan(3);
9
10 var expected = [ 12, 555 ];
11 var sm = staticModule({
12 beep: {
13 x: { y: { z: 4 } },
14 f: { g: { h: function (n) { return n * 111 } } }
15 }
16 });
17 readStream('source.js').pipe(sm).pipe(concat(function (body) {
18 Function(['console'],body)({ log: log });
19 t.equal(
20 body.toString('utf8'),
21 '\nconsole.log(4 * 3);\nconsole.log(555);\n'
22 );
23 function log (msg) { t.equal(msg, expected.shift()) }
24 }));
25});
26
27function readStream (file) {
28 return fs.createReadStream(path.join(__dirname, 'nested', file));
29}