UNPKG

1.27 kBJavaScriptView Raw
1var test = require('tape');
2var concat = require('concat-stream');
3var staticModule = require('../');
4var fs = require('fs');
5var path = require('path');
6
7test('assign', function (t) {
8 t.plan(3);
9
10 var expected = [ 12, 555 ];
11 var sm = staticModule({
12 beep: { x: 4, f: function (n) { return n * 111 } }
13 });
14 readStream('source.js').pipe(sm).pipe(concat(function (body) {
15 t.equal(body.toString('utf8'),
16 '\nconsole.log(4 * 3);'
17 + '\nconsole.log(555);\n'
18 );
19 Function(['console'],body)({ log: log });
20 function log (msg) { t.equal(msg, expected.shift()) }
21 }));
22});
23
24test('assign comma', function (t) {
25 t.plan(3);
26
27 var expected = [ 12, 555 ];
28 var sm = staticModule({
29 beep: { x: 4, f: function (n) { return n * 111 } }
30 });
31 readStream('comma.js').pipe(sm).pipe(concat(function (body) {
32 t.equal(body.toString('utf8'),
33 'x = 5;\n'
34 + 'console.log(4 * 3);\n'
35 + 'console.log(555);\n'
36 );
37 Function(['console'],body)({ log: log });
38 function log (msg) { t.equal(msg, expected.shift()) }
39 }));
40});
41
42function readStream (file) {
43 return fs.createReadStream(path.join(__dirname, 'assign', file));
44}