-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
149 lines (131 loc) · 5.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var mocha = require('mocha'),
chai = require('chai').should(),
path = require('path'),
fixturesDir = path.resolve('fixtures'),
standardDir = fixturesDir + '/standard';
ambiguousDir = fixturesDir + '/ambiguous';
describe('Finder', function () {
var finder = require('./src/finder');
it('should find files correctly', function (done) {
finder.findAll(standardDir, function (err, files) {
files.length.should.equal(10);
done();
});
});
it('should get basic imported files from file', function (done) {
finder.getImportedFiles(standardDir + '/main.scss', function (err, files) {
files.length.should.equal(2);
files[0].should.equal('./utils/tool.scss');
files[1].should.equal('page1');
done();
});
});
it('should get imported files anywhere in the file', function (done) {
finder.getImportedFiles(standardDir + '/_page1.scss', function (err, files) {
files.length.should.equal(3);
files[0].should.equal('partials/page1/banner');
files[1].should.equal('partials/page1/content');
files[2].should.equal('partials/page1/footer');
done();
});
});
it('should find existing paths for sass imports', function () {
path = finder.normaliseSassPath('global', './utils/_tool.scss', standardDir);
path.should.equal('utils/global.scss');
path = finder.normaliseSassPath('../global', './utils/_tool.scss', standardDir);
path.should.equal('global.scss');
});
it('should throw an error for ambiguous matches', function () {
(function () {
path = finder.normaliseSassPath('somestuff', './main.scss', ambiguousDir);
path.should.equal('utils/global.scss');
}).should.throw();
});
});
describe('Import Paths', function () {
var sassPath = require('./src/sass-path');
it('should return possible variants of a simple file name', function () {
paths = sassPath.getPaths('allTypes', 'main.scss', standardDir);
paths.length.should.equal(4);
paths.should.contain('allTypes.scss');
paths.should.contain('allTypes.sass');
paths.should.contain('_allTypes.scss');
paths.should.contain('_allTypes.sass');
});
it('should respect existing extensions', function () {
paths = sassPath.getPaths('scssOnly.scss', 'main.scss', standardDir);
paths.length.should.equal(2);
paths.should.contain('scssOnly.scss');
paths.should.contain('_scssOnly.scss');
});
it('should respect existing underscores', function () {
paths = sassPath.getPaths('_underscored', 'main.scss', standardDir);
paths.length.should.equal(2);
paths.should.contain('_underscored.scss');
paths.should.contain('_underscored.sass');
});
it('should respect whole file names', function () {
paths = sassPath.getPaths('_simpleFile.scss', 'main.scss', standardDir);
paths.length.should.equal(1);
paths[0].should.equal('_simpleFile.scss');
});
it ('should return all paths relative to the base directory', function () {
paths = sassPath.getPaths('../_component.scss', 'partials/page1/main.scss', standardDir);
paths.length.should.equal(1);
paths[0].should.equal('partials/_component.scss');
paths = sassPath.getPaths('../../other-project/someOtherProject.scss', 'partials/main.scss', standardDir);
paths.length.should.equal(2);
paths[0].should.equal('../other-project/someOtherProject.scss');
paths[1].should.equal('../other-project/_someOtherProject.scss');
paths = sassPath.getPaths('../page2/_thing.scss', 'partials/page1/main.scss', standardDir);
paths.length.should.equal(1);
paths[0].should.equal('partials/page2/_thing.scss');
});
});
describe('Mapper', function () {
it('should return each file relative to the base directory', function (done) {
var mapper = require('./src/mapper');
mapper.getFiles(standardDir, function (err, files) {
files.length.should.equal(10);
files.should.contain(standardDir + '/_page1.scss');
files.should.contain(standardDir + '/global.scss');
files.should.contain(standardDir + '/main.scss');
files.should.contain(standardDir + '/utils/_tool.scss');
done();
});
});
it('should get individual file dependencies', function (done) {
var mapper = require('./src/mapper');
mapper.getDependencies(standardDir + '/utils/_tool.scss', standardDir, function (err, files) {
files.length.should.equal(2);
files[0].should.equal('utils/_common.scss');
files[1].should.equal('utils/global.scss');
done();
});
});
it('should get file dependencies outside of the base dir', function (done) {
var mapper = require('./src/mapper');
mapper.getDependencies('_content.scss', standardDir + '/partials/page1', function (err, files) {
files.length.should.equal(1);
files[0].should.equal('../list/_main.scss');
done();
});
});
it('should get dependency tree of files', function (done) {
var mapper = require('./src/mapper');
mapper.getDependencyTree(standardDir, function (err, map) {
Object.keys(map).length.should.equal(10);
map['main.scss'].length.should.equal(2);
done();
});
});
it('dependencies should include those outside the base directory', function (done) {
var mapper = require('./src/mapper');
mapper.getDependencyTree(standardDir + '/partials/page1', function (err, map) {
Object.keys(map).length.should.equal(3);
map['_content.scss'].length.should.equal(1);
map['_content.scss'][0].should.equal('../list/_main.scss');
done();
});
});
});