UNPKG

4.67 kBJavaScriptView Raw
1var _ = require('underscore'),
2 lib = require('./lib'),
3 lumbar = require('../lib/lumbar'),
4 stateMachine = require('../lib/state-machine');
5
6describe('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
17describe('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 // TODO : Test file not found and other cases
22});
23
24describe('#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 }, {});
51 });
52
53 it('should collect map', function(done) {
54 arise.moduleMap(function(err, map) {
55 map.should.eql({
56 "map": {
57 "web": {
58 "modules": {
59 "foo": {
60 "js": "foo.js",
61 "css": undefined
62 },
63 "bar": {
64 "js": "bar.js",
65 "css": undefined
66 }
67 },
68 "routes": {
69 "bat/:baz": "foo",
70 "foo": "foo",
71 "bar/bat/:baz": "bar",
72 "bar/foo": "bar"
73 }
74 },
75 "webview": {
76 "modules": {
77 "foo": {
78 "js": "foo.js",
79 "css": undefined
80 },
81 "bar": {
82 "js": "bar.js",
83 "css": undefined
84 }
85 },
86 "routes": {
87 "bat/:baz": "foo",
88 "foo": "foo",
89 "bar/bat/:baz": "bar",
90 "bar/foo": "bar"
91 }
92 }
93 },
94 "store": {
95 "web": {
96 "modules": {
97 "foo": {
98 "js": "foo.js",
99 "css": undefined
100 }
101 },
102 "routes": {
103 "bat/:baz": "foo",
104 "foo": "foo"
105 }
106 }
107 }
108 });
109 done();
110 });
111 });
112
113 it('should collect map for specific packages', function(done) {
114 arise.moduleMap('store', function(err, map) {
115 map.should.eql({
116 "store": {
117 "web": {
118 "modules": {
119 "foo": {
120 "js": "foo.js",
121 "css": undefined
122 }
123 },
124 "routes": {
125 "bat/:baz": "foo",
126 "foo": "foo"
127 }
128 }
129 }
130 });
131 done();
132 });
133 });
134
135 it('should collect map for missing packages', function(done) {
136 arise.moduleMap('not found!', function(err, map) {
137 map.should.eql({});
138 done();
139 });
140 });
141
142 it('should handle config errors', function(done) {
143 var error = new Error('Error!');
144 this.stub(stateMachine, 'loadConfig', function(file, event, options, callback) {
145 callback(error);
146 });
147 arise.moduleMap('not found!', function(err, map) {
148 err.should.equal(error);
149 done();
150 });
151 });
152 it('should handle package errors', function(done) {
153 var error = new Error('Error!');
154 this.stub(stateMachine, 'loadPackages', function(context, packageName, callback) {
155 callback(error);
156 });
157 arise.moduleMap('not found!', function(err, map) {
158 err.should.equal(error);
159 done();
160 });
161 });
162});