forked from xzyfer/sass-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-file.js
174 lines (160 loc) · 5.45 KB
/
parse-file.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
var assert = require('chai').assert;
var path = require('path');
var sassGraph = require('..');
var fixture = require('./util').fixture;
var graph = require('./util').graph;
describe('sass-graph', function(){
describe('parseFile', function () {
describe('with a simple graph', function() {
it('should return a graph', function() {
graph().fromFixtureFile('simple')
.assertDecendents([
'b.scss',
'_c.scss',
path.join('nested', '_d.scss'),
path.join('nested', '_e.scss'),
])
.assertAncestors(path.join('nested', '_e.scss'), [
path.join('nested', '_d.scss'),
'_c.scss',
'b.scss',
'index.scss',
])
.assertAncestors(path.join('nested', '_d.scss'), [
'_c.scss',
'b.scss',
'index.scss',
])
.assertAncestors('_c.scss', [
'b.scss',
'index.scss',
])
.assertAncestors('b.scss', [
'index.scss',
])
.assertAncestors('index.scss', []);
});
});
describe('with a simple graph in indented syntax', function() {
it('should return a graph', function() {
graph().indented().fromFixtureFile('indented-syntax')
.assertDecendents([
'b.sass',
'_c.sass',
path.join('nested', '_d.sass'),
path.join('nested', '_e.sass'),
])
.assertAncestors(path.join('nested', '_e.sass'), [
path.join('nested', '_d.sass'),
'_c.sass',
'b.sass',
'index.sass',
])
.assertAncestors(path.join('nested', '_d.sass'), [
'_c.sass',
'b.sass',
'index.sass',
])
.assertAncestors('_c.sass', [
'b.sass',
'index.sass',
])
.assertAncestors('b.sass', [
'index.sass',
])
.assertAncestors('index.sass', []);
});
});
describe('with a graph with loadPaths', function() {
it('should return a graph', function() {
var includeFolder = 'inside-load-path';
var excludeFolder = 'outside-load-path';
var rootFolder = path.dirname(fixture('load-path')());
var opts = { loadPaths: [ rootFolder, fixture('load-path')(includeFolder) ] };
graph(opts).fromFixtureFile('load-path')
.assertDecendents([
path.join(includeFolder, '_b.scss'),
path.join(includeFolder, '_c.scss'),
'_d.scss',
])
.assertAncestors(path.join('_d.scss'), [
path.join(includeFolder, '_c.scss'),
path.join(includeFolder, '_b.scss'),
'index.scss',
])
.assertAncestors(path.join(includeFolder, '_c.scss'), [
path.join(includeFolder, '_b.scss'),
'index.scss',
])
.assertAncestors(path.join(includeFolder, '_b.scss'), [
'index.scss',
])
.assertAncestors('index.scss', [])
.assertAncestors(path.join(excludeFolder, '_b.scss'), [])
.assertAncestors(path.join(excludeFolder, '_c.scss'), []);
});
it('should prioritize cwd', function() {
var includeFolder = 'inside-load-path';
var excludeFolder = 'outside-load-path';
var opts = { loadPaths: [ fixture('load-path-cwd')(includeFolder) ] };
graph(opts).fromFixtureFile('load-path-cwd').assertDecendents([
'_b.scss',
path.join(includeFolder, '_c.scss'),
])
.assertAncestors(path.join(includeFolder, '_c.scss'), [
'_b.scss',
'index.scss',
])
.assertAncestors('_b.scss', [
'index.scss',
])
.assertAncestors('index.scss', [])
.assertAncestors(path.join(includeFolder, '_b.scss'), [])
.assertAncestors(path.join(excludeFolder, '_b.scss'), [])
.assertAncestors(path.join(excludeFolder, '_c.scss'), []);
});
});
describe('with a folder that has an extension', function() {
it('should return a graph', function () {
var leaf = path.join('_nested.scss', '_leaf.scss');
graph().fromFixtureFile('folder-with-extension')
.assertDecendents([leaf])
.assertAncestors(leaf, ['index.scss']);
});
});
describe('with no imports', function() {
it('should return a graph', function () {
graph().fromFixtureFile('no-imports').assertDecendents([]);
});
});
describe('when the file is inaccessible', function() {
it('should thow an error', function () {
assert.throws(function() {
graph().fromFixtureFile('no-such-path');
});
});
});
describe('with options', function() {
it('should not use inherited propterties', function() {
before(function() {
Array.prototype.foo = function() {};
});
after(function() {
delete Array.prototype.foo;
});
assert.doesNotThrow(function() {
graph().fromFixtureFile('no-imports').assertDecendents([]);
});
});
});
describe('with exclusion pattern', function() {
it('should exclude all files matching the regular expression', function() {
graph({ exclude: /exclude-/ })
.fromFixtureFile('exclusion-pattern')
.assertDecendents([
'dont-exclude.scss',
]);
});
});
});
});