1 | 'use strict'
|
2 | var test = require('tape')
|
3 | var freeze = require('deep-freeze')
|
4 |
|
5 | var combine = require('../')
|
6 |
|
7 | test('nested combine', function (t) {
|
8 | var modules = {
|
9 | a: {
|
10 | b: {
|
11 | c: {
|
12 | gives: 'yes',
|
13 | create: function () {
|
14 | return function () {
|
15 | return true
|
16 | }
|
17 | }
|
18 | }
|
19 | },
|
20 | d: {
|
21 | e: {
|
22 | needs: {
|
23 | yes: 'first'
|
24 | },
|
25 | gives: 'no',
|
26 | create: function (api) {
|
27 | return function () {
|
28 | return !api.yes()
|
29 | }
|
30 | }
|
31 | }
|
32 | }
|
33 | }
|
34 | }
|
35 | var sockets = combine(modules)
|
36 | t.equal(sockets.yes[0](), true)
|
37 | t.equal(sockets.no[0](), false)
|
38 | t.end()
|
39 | })
|
40 |
|
41 | test('nested combine with mulitple args passed to combine', function (t) {
|
42 | var module1 = {
|
43 | a: {
|
44 | b: {
|
45 | c: {
|
46 | gives: 'yes',
|
47 | create: function () {
|
48 | return function () {
|
49 | return true
|
50 | }
|
51 | }
|
52 | }
|
53 | }
|
54 | }
|
55 | }
|
56 | var module2 = {
|
57 | d: {
|
58 | e: {
|
59 | needs: {
|
60 | yes: 'first'
|
61 | },
|
62 | gives: 'no',
|
63 | create: function (api) {
|
64 | return function () {
|
65 | return !api.yes()
|
66 | }
|
67 | }
|
68 | }
|
69 | }
|
70 | }
|
71 | var sockets = combine(module1, module2)
|
72 | t.equal(sockets.yes[0](), true)
|
73 | t.equal(sockets.no[0](), false)
|
74 | t.end()
|
75 | })
|
76 |
|
77 | test('nested combine with other keys and values in surrounding objects', function (t) {
|
78 | var modules = {
|
79 | a: {
|
80 | z: null,
|
81 | x: true,
|
82 | y: {},
|
83 | b: {
|
84 | c: {
|
85 | z: null,
|
86 | x: true,
|
87 | y: {},
|
88 | gives: 'yes',
|
89 | create: function () {
|
90 | return function () {
|
91 | return true
|
92 | }
|
93 | }
|
94 | }
|
95 | },
|
96 | d: {
|
97 | z: null,
|
98 | x: true,
|
99 | y: {},
|
100 | e: {
|
101 | z: null,
|
102 | x: true,
|
103 | y: {},
|
104 | needs: {
|
105 | yes: 'first'
|
106 | },
|
107 | gives: 'no',
|
108 | create: function (api) {
|
109 | return function () {
|
110 | return !api.yes()
|
111 | }
|
112 | }
|
113 | }
|
114 | }
|
115 | }
|
116 | }
|
117 | var sockets = combine(modules)
|
118 | t.equal(sockets.yes[0](), true)
|
119 | t.equal(sockets.no[0](), false)
|
120 | t.end()
|
121 | })
|
122 |
|
123 | test('nested combine with other keys and values in surrounding objects will not modify object passed in', function (t) {
|
124 | var modules = {
|
125 | a: {
|
126 | z: null,
|
127 | x: true,
|
128 | y: {},
|
129 | b: {
|
130 | c: {
|
131 | z: null,
|
132 | x: true,
|
133 | y: {},
|
134 | gives: 'yes',
|
135 | create: function () {
|
136 | return function () {
|
137 | return true
|
138 | }
|
139 | }
|
140 | }
|
141 | },
|
142 | d: {
|
143 | z: null,
|
144 | x: true,
|
145 | y: {},
|
146 | e: {
|
147 | z: null,
|
148 | x: true,
|
149 | y: {},
|
150 | needs: {
|
151 | yes: 'first'
|
152 | },
|
153 | gives: 'no',
|
154 | create: function (api) {
|
155 | return function () {
|
156 | return !api.yes()
|
157 | }
|
158 | }
|
159 | }
|
160 | }
|
161 | }
|
162 | }
|
163 | freeze(modules)
|
164 | var sockets = combine(modules)
|
165 | t.equal(sockets.yes[0](), true)
|
166 | t.equal(sockets.no[0](), false)
|
167 | t.end()
|
168 | })
|