1 | var fs = require('fs'),
|
2 | Libraries = require('../lib/libraries');
|
3 |
|
4 | describe('Libraries', function() {
|
5 | describe('#initialize', function() {
|
6 | it('should remove duplicates', function() {
|
7 | var library = new Libraries({libraries: ['bower_components/foo', 'baz']}),
|
8 | paths = [];
|
9 | library.load = function(context, path, callback) {
|
10 | paths.push(path);
|
11 | callback();
|
12 | };
|
13 | library.bowerLibraries = function() {
|
14 | return ['bower_components/foo', 'bower_components/baz'];
|
15 | };
|
16 |
|
17 | library.initialize({config: {attributes: {libraries: ['bower_components/foo', 'bar', 'foo/../baz']}}});
|
18 | paths.should.eql(['bower_components/foo', 'baz', 'bar', 'bower_components/baz']);
|
19 | });
|
20 | });
|
21 | describe('#bowerLibraries', function() {
|
22 | beforeEach(function() {
|
23 | require('bower').config.directory = 'bower_components';
|
24 | });
|
25 |
|
26 | var readdirSync = fs.readdirSync,
|
27 | statSync = fs.statSync,
|
28 |
|
29 | context = {
|
30 | event: {emit: function() {}}
|
31 | };
|
32 | beforeEach(function() {
|
33 | this.stub(fs, 'statSync', function(path) {
|
34 | if (/bar\//.test(path)) {
|
35 | throw new Error();
|
36 | } else if (!/bower(.json|_components)/.test(path)) {
|
37 | return statSync.call(this, path);
|
38 | }
|
39 | });
|
40 | });
|
41 |
|
42 | it('should return all modules in bower directory', function() {
|
43 | this.stub(fs, 'readdirSync', function(path) {
|
44 | return ['foo', 'bar', 'baz'];
|
45 | });
|
46 |
|
47 | var library = new Libraries();
|
48 | library.bowerLibraries(context).should.eql(['bower_components/foo', 'bower_components/baz']);
|
49 | });
|
50 | it('should not error on fs error', function() {
|
51 | this.stub(fs, 'readdirSync', function(path) {
|
52 | throw new Error();
|
53 | });
|
54 |
|
55 | var library = new Libraries();
|
56 | should.not.exist(library.bowerLibraries(context));
|
57 | });
|
58 | });
|
59 | });
|