UNPKG

4.58 kBJavaScriptView Raw
1var getAppRoot = require('../');
2var assert = require('assert');
3var extend = require('object-assign');
4
5describe('app-root', function() {
6 var options = {
7 ignoreDirectories: ['bower_components'],
8 ignoreFiles: ['index.js']
9 };
10
11 it('omits no dependency modules by default', function(done) {
12 var opts = {
13 directory: __dirname + '/apps/commonjs',
14 success: function(root) {
15 assert(!root.some(function(r) {
16 return r.indexOf('noDep.js') !== -1;
17 }));
18 done();
19 }
20 };
21
22 getAppRoot(opts);
23 });
24
25 describe('includeNoDependencyModules', function() {
26 it('includes no dependency modules if set', function(done) {
27 var opts = {
28 directory: __dirname + '/apps/commonjs',
29 includeNoDependencyModules: true,
30 success: function(root) {
31 assert(root.some(function(r) {
32 return r.indexOf('noDep.js') !== -1;
33 }));
34 done();
35 }
36 };
37
38 getAppRoot(opts);
39 });
40 });
41
42 describe('ignoreDirectories', function() {
43 it('does not ignore any directories by default', function(done) {
44 var opts = {
45 directory: __dirname + '/apps/amd',
46 success: function(root) {
47 assert(root.some(function(r) {
48 return r.indexOf('bower_components') !== -1;
49 }));
50 done();
51 }
52 };
53
54 getAppRoot(opts);
55 });
56
57 it('ignores processing files within supplied directories', function(done) {
58 var opts = {
59 directory: __dirname + '/apps/amd',
60 ignoreDirectories: options.ignoreDirectories,
61 success: function(root) {
62 assert(!root.some(function(r) {
63 return r.indexOf('bower_components') !== -1;
64 }));
65 done();
66 }
67 };
68
69 getAppRoot(opts);
70 });
71 });
72
73 it('throws if a directory is not supplied', function() {
74 assert.throws(function() {
75 getAppRoot();
76 });
77 });
78
79 it('throws if a success callback is not supplied', function() {
80 assert.throws(function() {
81 getAppRoot({
82 directory: __dirname
83 });
84 });
85 });
86
87 // There is confusion around which loader to use with files that
88 // have both a requirejs and webpack config.
89 it.skip('finds the roots of an entire directory of multiple apps', function(done) {
90 var opts = {
91 directory: __dirname + '/apps',
92 config: __dirname + '/apps/amd/config.json',
93 success: function(roots) {
94 // Equal to the number of apps within /apps/
95 assert.equal(roots.length, 4);
96 done();
97 }
98 };
99
100 extend(opts, options);
101
102 getAppRoot(opts);
103 });
104
105 describe('commonjs', function() {
106 it('finds the roots of a commonjs app', function(done) {
107 var opts = {
108 directory: __dirname + '/apps/commonjs',
109 success: function(root) {
110 assert.equal(root.length, 1);
111 assert.ok(root[0].indexOf('a2.js') !== -1);
112 done();
113 }
114 };
115
116 extend(opts, options);
117
118 getAppRoot(opts);
119 });
120 });
121
122 describe('amd', function() {
123 it('finds the roots of an amd app', function(done) {
124 var opts = {
125 directory: __dirname + '/apps/amd',
126 config: __dirname + '/apps/amd/config.json',
127 success: function(root) {
128 assert(root.length === 1);
129 assert(root[0].indexOf('a2.js') !== -1);
130 done();
131 }
132 };
133
134 extend(opts, options);
135
136 getAppRoot(opts);
137 });
138
139 it('handles aliased modules with a supplied config', function(done) {
140 var opts = {
141 directory: __dirname + '/aliased/js',
142 config: __dirname + '/aliased/config.json',
143 success: function(root) {
144 assert(root.length === 1);
145 assert(root[0].indexOf('root.js') !== -1);
146 done();
147 }
148 };
149
150 getAppRoot(opts);
151 });
152 });
153
154 describe('sass', function() {
155 it('finds the roots of a sass codebase', function(done) {
156 var opts = {
157 directory: __dirname + '/apps/sass',
158 success: function(root) {
159 assert(root.length === 1);
160 assert(root[0].indexOf('root.scss') !== -1);
161 done();
162 }
163 };
164
165 getAppRoot(opts);
166 });
167 });
168
169 describe('es6', function() {
170 it('finds the roots of an es6 codebase', function(done) {
171 var opts = {
172 directory: __dirname + '/apps/es6',
173 success: function(root) {
174 assert(root.length === 1);
175 assert(root[0].indexOf('root.js') !== -1);
176 done();
177 }
178 };
179
180 getAppRoot(opts);
181 });
182 });
183});