Debian Codegraph @

test/assign.js

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