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('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 |
|
18 | test('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 |
|
29 | test('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 |
|
40 | test('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 |
|
51 | test('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 |
|
62 | test('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 |
|
73 | function readStream (file) {
|
74 | return fs.createReadStream(path.join(__dirname, 'inline', file));
|
75 | }
|