1 | var _ = require('underscore'),
|
2 | lib = require('./lib'),
|
3 | lumbar = require('../lib/lumbar'),
|
4 | stateMachine = require('../lib/state-machine');
|
5 |
|
6 | describe('file output', function() {
|
7 | it('should output a single dir', lib.runTest('test/artifacts/single-directory.json', 'test/expected/js-dir'));
|
8 | it('should output multiple files', lib.runTest('test/artifacts/multiple-files.json', 'test/expected/js-dir'));
|
9 | it('should output files in multiple modules', lib.runTest('test/artifacts/file-modules.json', 'test/expected/file-modules'));
|
10 | it('should handle multiple platforms', lib.runTest('test/artifacts/multiple-platforms.json', 'test/expected/multiple-platforms'));
|
11 | it('should handle multiple packages', lib.runTest('test/artifacts/multiple-packages.json', 'test/expected/multiple-packages'));
|
12 |
|
13 | it('should output styles', lib.runTest('test/artifacts/styles.json', 'test/expected/styles'));
|
14 | it('should output static', lib.runTest('test/artifacts/static.json', 'test/expected/static', undefined, '/**/*.*'));
|
15 | });
|
16 |
|
17 | describe('integration', function() {
|
18 | it('should output stylus', lib.runTest('test/artifacts/stylus.json', 'test/expected/stylus'));
|
19 | it('should output inline-styles', lib.runTest('test/artifacts/inline-styles.json', 'test/expected/inline-styles'));
|
20 | it('should output json-plugins', lib.runTest('test/artifacts/json-plugins.json', 'test/expected/json-plugin'));
|
21 |
|
22 | });
|
23 |
|
24 | describe('#moduleMap', function() {
|
25 | var arise;
|
26 | beforeEach(function() {
|
27 | arise = lumbar.init({
|
28 | platforms: ['web', 'webview'],
|
29 | packages: {
|
30 | map: true,
|
31 | store: {
|
32 | platforms: ['web'],
|
33 | modules: ['foo']
|
34 | }
|
35 | },
|
36 | modules: {
|
37 | 'foo': {
|
38 | routes: {
|
39 | 'bat/:baz': 'bat',
|
40 | 'foo': 'bar'
|
41 | }
|
42 | },
|
43 | 'bar': {
|
44 | routes: {
|
45 | 'bar/bat/:baz': 'bat',
|
46 | 'bar/foo': 'bar'
|
47 | }
|
48 | }
|
49 | },
|
50 | loadPrefix: 'prefix!'
|
51 | }, {});
|
52 | });
|
53 |
|
54 | it('should collect map', function(done) {
|
55 | arise.moduleMap(function(err, map) {
|
56 | map.should.eql({
|
57 | "map": {
|
58 | "web": {
|
59 | "isMap": true,
|
60 | "loadPrefix": "prefix!web/",
|
61 | "modules": {
|
62 | "foo": {
|
63 | "js": "foo.js",
|
64 | "css": undefined
|
65 | },
|
66 | "bar": {
|
67 | "js": "bar.js",
|
68 | "css": undefined
|
69 | }
|
70 | },
|
71 | "routes": {
|
72 | "bat/:baz": "foo",
|
73 | "foo": "foo",
|
74 | "bar/bat/:baz": "bar",
|
75 | "bar/foo": "bar"
|
76 | }
|
77 | },
|
78 | "webview": {
|
79 | "isMap": true,
|
80 | "loadPrefix": "prefix!webview/",
|
81 | "modules": {
|
82 | "foo": {
|
83 | "js": "foo.js",
|
84 | "css": undefined
|
85 | },
|
86 | "bar": {
|
87 | "js": "bar.js",
|
88 | "css": undefined
|
89 | }
|
90 | },
|
91 | "routes": {
|
92 | "bat/:baz": "foo",
|
93 | "foo": "foo",
|
94 | "bar/bat/:baz": "bar",
|
95 | "bar/foo": "bar"
|
96 | }
|
97 | }
|
98 | },
|
99 | "store": {
|
100 | "web": {
|
101 | "isMap": true,
|
102 | "loadPrefix": "prefix!web/",
|
103 | "modules": {
|
104 | "foo": {
|
105 | "js": "foo.js",
|
106 | "css": undefined
|
107 | }
|
108 | },
|
109 | "routes": {
|
110 | "bat/:baz": "foo",
|
111 | "foo": "foo"
|
112 | }
|
113 | }
|
114 | }
|
115 | });
|
116 | done();
|
117 | });
|
118 | });
|
119 |
|
120 | it('should collect map with local path', function(done) {
|
121 | arise.moduleMap(undefined, {localPath: true}, function(err, map) {
|
122 | map.should.eql({
|
123 | "map": {
|
124 | "web": {
|
125 | "isMap": true,
|
126 | "loadPrefix": "prefix!web/",
|
127 | "modules": {
|
128 | "foo": {
|
129 | "js": "web/foo.js",
|
130 | "css": undefined
|
131 | },
|
132 | "bar": {
|
133 | "js": "web/bar.js",
|
134 | "css": undefined
|
135 | }
|
136 | },
|
137 | "routes": {
|
138 | "bat/:baz": "foo",
|
139 | "foo": "foo",
|
140 | "bar/bat/:baz": "bar",
|
141 | "bar/foo": "bar"
|
142 | }
|
143 | },
|
144 | "webview": {
|
145 | "isMap": true,
|
146 | "loadPrefix": "prefix!webview/",
|
147 | "modules": {
|
148 | "foo": {
|
149 | "js": "webview/foo.js",
|
150 | "css": undefined
|
151 | },
|
152 | "bar": {
|
153 | "js": "webview/bar.js",
|
154 | "css": undefined
|
155 | }
|
156 | },
|
157 | "routes": {
|
158 | "bat/:baz": "foo",
|
159 | "foo": "foo",
|
160 | "bar/bat/:baz": "bar",
|
161 | "bar/foo": "bar"
|
162 | }
|
163 | }
|
164 | },
|
165 | "store": {
|
166 | "web": {
|
167 | "isMap": true,
|
168 | "loadPrefix": "prefix!web/",
|
169 | "modules": {
|
170 | "foo": {
|
171 | "js": "web/foo.js",
|
172 | "css": undefined
|
173 | }
|
174 | },
|
175 | "routes": {
|
176 | "bat/:baz": "foo",
|
177 | "foo": "foo"
|
178 | }
|
179 | }
|
180 | }
|
181 | });
|
182 | done();
|
183 | });
|
184 | });
|
185 |
|
186 | it('should collect map for specific packages', function(done) {
|
187 | arise.moduleMap('store', function(err, map) {
|
188 | map.should.eql({
|
189 | "store": {
|
190 | "web": {
|
191 | "isMap": true,
|
192 | "loadPrefix": "prefix!web/",
|
193 | "modules": {
|
194 | "foo": {
|
195 | "js": "foo.js",
|
196 | "css": undefined
|
197 | }
|
198 | },
|
199 | "routes": {
|
200 | "bat/:baz": "foo",
|
201 | "foo": "foo"
|
202 | }
|
203 | }
|
204 | }
|
205 | });
|
206 | done();
|
207 | });
|
208 | });
|
209 |
|
210 | it('should collect map for missing packages', function(done) {
|
211 | arise.moduleMap('not found!', function(err, map) {
|
212 | map.should.eql({});
|
213 | done();
|
214 | });
|
215 | });
|
216 |
|
217 | it('should handle config errors', function(done) {
|
218 | var error = new Error('Error!');
|
219 | this.stub(stateMachine, 'loadConfig', function(file, event, options, callback) {
|
220 | callback(error);
|
221 | });
|
222 | arise.moduleMap('not found!', function(err, map) {
|
223 | err.should.equal(error);
|
224 | done();
|
225 | });
|
226 | });
|
227 | it('should handle package errors', function(done) {
|
228 | var error = new Error('Error!');
|
229 | this.stub(stateMachine, 'loadPackages', function(context, packageName, callback) {
|
230 | callback(error);
|
231 | });
|
232 | arise.moduleMap('not found!', function(err, map) {
|
233 | err.should.equal(error);
|
234 | done();
|
235 | });
|
236 | });
|
237 | });
|