-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
55 lines (46 loc) · 1.52 KB
/
index.spec.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
const fs = require( 'fs' ),
gonzales = require( 'gonzales-pe' ),
lessVariableResolver = require( 'less-variable-resolver' ),
fixtureFolder = __dirname + '/fixtures',
fixtureEncoding = 'utf8';
lessVariableResolver.log.level = 'silent';
function getExpected( fixture ) {
return fs.readFileSync( fixtureFolder + '/' + fixture + '/expected.less', fixtureEncoding );
}
function getGivenGonzalesTree( fixture ) {
return gonzales.parse(
fs.readFileSync( fixtureFolder + '/' + fixture + '/given.less', fixtureEncoding ),
{ syntax: 'less' }
);
}
describe( 'resolves variable declarations', () => {
it.each( [
[ 'multiple_var_in_one_value' ],
[ 'simple_var_lookup' ],
[ 'variable_declared_after_use' ],
[ 'variable_referencing_two_variables' ],
[ 'variable_referencing_variable_declared_after_use' ]
] )(
'%s',
( fixture ) => {
const lessTree = getGivenGonzalesTree( fixture );
lessVariableResolver.resolveVariablesInTree( lessTree );
expect( lessTree.toString() ).toBe( getExpected( fixture ) );
}
);
} );
describe( 'resolves things which are not considered a feature but a known side effect', () => {
it.each( [
[ 'variable_declaration_breaking_out_of_scope' ],
[ 'variable_declared_inside_selector' ],
[ 'variable_used_in_property' ],
[ 'variable_used_in_property_declared_after_use' ]
] )(
'%s',
( fixture ) => {
const lessTree = getGivenGonzalesTree( fixture );
lessVariableResolver.resolveVariablesInTree( lessTree );
expect( lessTree.toString() ).toBe( getExpected( fixture ) );
}
);
} );