Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 203f8d6

Browse files
committed
Mirror render and renderSync tests
1 parent 4310623 commit 203f8d6

File tree

1 file changed

+152
-15
lines changed

1 file changed

+152
-15
lines changed

test/api.js

Lines changed: 152 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ describe('api', function() {
8787
});
8888
});
8989

90+
it('should compile sass to css using indented syntax', function(done) {
91+
var src = read(fixture('indent/index.sass'), 'utf8');
92+
var expected = read(fixture('indent/expected.css'), 'utf8').trim();
93+
94+
sass.render({
95+
data: src,
96+
indentedSyntax: true
97+
}, function(error, result) {
98+
assert.equal(result.css.toString().trim(), expected.replace(/\r\n/g, '\n'));
99+
done();
100+
});
101+
});
102+
90103
it('should NOT compile empty data string', function(done) {
91104
sass.render({
92105
data: ''
@@ -96,27 +109,14 @@ describe('api', function() {
96109
});
97110
});
98111

99-
it('should NOT compile without parameters', function(done) {
112+
it('should NOT compile without any input', function(done) {
100113
sass.render({ }, function(error) {
101114
assert.equal(error.message, 'No input specified: provide a file name or a source string to process');
102115
done();
103116
});
104117
});
105118

106-
it('should compile sass to css using indented syntax', function(done) {
107-
var src = read(fixture('indent/index.sass'), 'utf8');
108-
var expected = read(fixture('indent/expected.css'), 'utf8').trim();
109-
110-
sass.render({
111-
data: src,
112-
indentedSyntax: true
113-
}, function(error, result) {
114-
assert.equal(result.css.toString().trim(), expected.replace(/\r\n/g, '\n'));
115-
done();
116-
});
117-
});
118-
119-
it('should throw error status 1 for bad input', function(done) {
119+
it('should returnn error status 1 for bad input', function(done) {
120120
sass.render({
121121
data: '#navbar width 80%;'
122122
}, function(error) {
@@ -1406,6 +1406,143 @@ describe('api', function() {
14061406

14071407
done();
14081408
});
1409+
1410+
it('should compile with include paths', function(done) {
1411+
var src = read(fixture('include-path/index.scss'), 'utf8');
1412+
var expected = read(fixture('include-path/expected.css'), 'utf8').trim();
1413+
var result = sass.renderSync({
1414+
data: src,
1415+
includePaths: [
1416+
fixture('include-path/functions'),
1417+
fixture('include-path/lib')
1418+
]
1419+
});
1420+
1421+
assert.equal(result.css.toString().trim(), expected.replace(/\r\n/g, '\n'));
1422+
done();
1423+
});
1424+
1425+
it('should add cwd to the front on include paths', function(done) {
1426+
var src = fixture('cwd-include-path/root/index.scss');
1427+
var expected = read(fixture('cwd-include-path/expected.css'), 'utf8').trim();
1428+
var cwd = process.cwd();
1429+
1430+
process.chdir(fixture('cwd-include-path'));
1431+
var result = sass.renderSync({
1432+
file: src,
1433+
includePaths: [
1434+
fixture('include-path/functions'),
1435+
fixture('include-path/lib')
1436+
]
1437+
});
1438+
process.chdir(cwd);
1439+
1440+
assert.equal(result.css.toString().trim(), expected.replace(/\r\n/g, '\n'));
1441+
done();
1442+
});
1443+
1444+
it('should check SASS_PATH in the specified order', function(done) {
1445+
var src = read(fixture('sass-path/index.scss'), 'utf8');
1446+
var expectedRed = read(fixture('sass-path/expected-red.css'), 'utf8').trim();
1447+
var expectedOrange = read(fixture('sass-path/expected-orange.css'), 'utf8').trim();
1448+
1449+
var envIncludes = [
1450+
fixture('sass-path/red'),
1451+
fixture('sass-path/orange')
1452+
];
1453+
1454+
process.env.SASS_PATH = envIncludes.join(path.delimiter);
1455+
var result = sass.renderSync({
1456+
data: src,
1457+
includePaths: []
1458+
});
1459+
1460+
assert.equal(result.css.toString().trim(), expectedRed.replace(/\r\n/g, '\n'));
1461+
1462+
process.env.SASS_PATH = envIncludes.reverse().join(path.delimiter);
1463+
result = sass.renderSync({
1464+
data: src,
1465+
includePaths: []
1466+
});
1467+
1468+
assert.equal(result.css.toString().trim(), expectedOrange.replace(/\r\n/g, '\n'));
1469+
done();
1470+
});
1471+
1472+
it('should prefer include path over SASS_PATH', function(done) {
1473+
var src = read(fixture('sass-path/index.scss'), 'utf8');
1474+
var expectedRed = read(fixture('sass-path/expected-red.css'), 'utf8').trim();
1475+
var expectedOrange = read(fixture('sass-path/expected-orange.css'), 'utf8').trim();
1476+
1477+
var envIncludes = [
1478+
fixture('sass-path/red')
1479+
];
1480+
process.env.SASS_PATH = envIncludes.join(path.delimiter);
1481+
1482+
var result = sass.renderSync({
1483+
data: src,
1484+
includePaths: []
1485+
});
1486+
1487+
assert.equal(result.css.toString().trim(), expectedRed.replace(/\r\n/g, '\n'));
1488+
1489+
result = sass.renderSync({
1490+
data: src,
1491+
includePaths: [fixture('sass-path/orange')]
1492+
});
1493+
1494+
assert.equal(result.css.toString().trim(), expectedOrange.replace(/\r\n/g, '\n'));
1495+
done();
1496+
});
1497+
1498+
it('should render with precision option', function(done) {
1499+
var src = read(fixture('precision/index.scss'), 'utf8');
1500+
var expected = read(fixture('precision/expected.css'), 'utf8').trim();
1501+
var result = sass.renderSync({
1502+
data: src,
1503+
precision: 10
1504+
});
1505+
1506+
assert.equal(result.css.toString().trim(), expected.replace(/\r\n/g, '\n'));
1507+
done();
1508+
});
1509+
1510+
it('should contain all included files in stats when data is passed', function(done) {
1511+
var src = read(fixture('include-files/index.scss'), 'utf8');
1512+
var expected = [
1513+
fixture('include-files/bar.scss').replace(/\\/g, '/'),
1514+
fixture('include-files/foo.scss').replace(/\\/g, '/')
1515+
];
1516+
1517+
var result = sass.renderSync({
1518+
data: src,
1519+
includePaths: [fixture('include-files')]
1520+
});
1521+
1522+
assert.deepEqual(result.stats.includedFiles, expected);
1523+
done();
1524+
});
1525+
1526+
it('should render with indentWidth and indentType options', function(done) {
1527+
var result = sass.renderSync({
1528+
data: 'div { color: transparent; }',
1529+
indentWidth: 7,
1530+
indentType: 'tab'
1531+
});
1532+
1533+
assert.equal(result.css.toString().trim(), 'div {\n\t\t\t\t\t\t\tcolor: transparent; }');
1534+
done();
1535+
});
1536+
1537+
it('should render with linefeed option', function(done) {
1538+
var result = sass.renderSync({
1539+
data: 'div { color: transparent; }',
1540+
linefeed: 'lfcr'
1541+
});
1542+
1543+
assert.equal(result.css.toString().trim(), 'div {\n\r color: transparent; }');
1544+
done();
1545+
});
14091546
});
14101547

14111548
describe('.renderSync(importer)', function() {

0 commit comments

Comments
 (0)