UNPKG

2.2 kBJavaScriptView Raw
1var test = require('tape');
2var concat = require('concat-stream');
3var staticModule = require('../');
4var fs = require('fs');
5var path = require('path');
6
7test('inline object', function (t) {
8 t.plan(1);
9 var sm = staticModule({
10 beep: { f: function (n) { return n * 111 } }
11 });
12 readStream('obj.js').pipe(sm).pipe(concat(function (body) {
13 Function(['console'],body)({ log: log });
14 function log (msg) { t.equal(msg, 555) }
15 }));
16});
17
18test('inline object call', function (t) {
19 t.plan(1);
20 var sm = staticModule({
21 beep: { f: function (n) { return n * 111 } }
22 });
23 readStream('obj_call.js').pipe(sm).pipe(concat(function (body) {
24 Function(['console'],body)({ log: log });
25 function log (msg) { t.equal(msg, 555) }
26 }));
27});
28
29test('inline object expression', function (t) {
30 t.plan(1);
31 var sm = staticModule({
32 beep: { f: function (n) { return n * 111 } }
33 });
34 readStream('obj_expr.js').pipe(sm).pipe(concat(function (body) {
35 Function(['console'],body)({ log: log });
36 function log (msg) { t.equal(msg, 1110) }
37 }));
38});
39
40test('inline function', function (t) {
41 t.plan(1);
42 var sm = staticModule({
43 beep: function (n) { return n * 111 }
44 });
45 readStream('fn.js').pipe(sm).pipe(concat(function (body) {
46 Function(['console'],body)({ log: log });
47 function log (msg) { t.equal(msg, 555) }
48 }));
49});
50
51test('inline function call', function (t) {
52 t.plan(1);
53 var sm = staticModule({
54 beep: function (n) { return n * 111 }
55 });
56 readStream('fn_call.js').pipe(sm).pipe(concat(function (body) {
57 Function(['console'],body)({ log: log });
58 function log (msg) { t.equal(msg, 555) }
59 }));
60});
61
62test('inline function expression', function (t) {
63 t.plan(1);
64 var sm = staticModule({
65 beep: function (n) { return n * 111 }
66 });
67 readStream('fn_expr.js').pipe(sm).pipe(concat(function (body) {
68 Function(['console'],body)({ log: log });
69 function log (msg) { t.equal(msg, 1665) }
70 }));
71});
72
73function readStream (file) {
74 return fs.createReadStream(path.join(__dirname, 'inline', file));
75}