Commit 7a060a76 by xzyfer

Add test coverage for existing custom importer return semantics

Custom importers are expected to return `sass.NULL` to noop.
However it appears we currently also allow `null`, `false`, and
`undefined`.

This patch adds test coverage over these caveats in case we
unintentionally break BC.
parent 08f11892
...@@ -278,7 +278,7 @@ describe('api', function() { ...@@ -278,7 +278,7 @@ describe('api', function() {
}); });
} }
}, function(error, result) { }, function(error, result) {
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
}); });
...@@ -292,7 +292,7 @@ describe('api', function() { ...@@ -292,7 +292,7 @@ describe('api', function() {
}); });
} }
}, function(error, result) { }, function(error, result) {
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
}); });
...@@ -306,7 +306,7 @@ describe('api', function() { ...@@ -306,7 +306,7 @@ describe('api', function() {
}; };
} }
}, function(error, result) { }, function(error, result) {
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
}); });
...@@ -320,7 +320,44 @@ describe('api', function() { ...@@ -320,7 +320,44 @@ describe('api', function() {
}; };
} }
}, function(error, result) { }, function(error, result) {
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});
it('should fallback to default import behaviour if importer returns null for backwards compatibility', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done(null);
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});
it('should fallback to default import behaviour if importer returns undefined for backwards compatibility', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done(undefined);
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});
it('should fallback to default import behaviour if importer returns false for backwards compatibility', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done(false);
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
}); });
...@@ -1248,7 +1285,7 @@ describe('api', function() { ...@@ -1248,7 +1285,7 @@ describe('api', function() {
} }
}); });
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
...@@ -1262,7 +1299,7 @@ describe('api', function() { ...@@ -1262,7 +1299,7 @@ describe('api', function() {
} }
}); });
assert.equal(result.css.toString().trim(), ''); assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done(); done();
}); });
...@@ -1294,6 +1331,56 @@ describe('api', function() { ...@@ -1294,6 +1331,56 @@ describe('api', function() {
done(); done();
}); });
it('should fallback to default import behaviour if importer returns sass.NULL', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function() {
return sass.NULL;
}
});
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
it('should fallback to default import behaviour if importer returns null for backwards compatibility', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function() {
return null;
}
});
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
it('should fallback to default import behaviour if importer returns undefined for backwards compatibility', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function() {
return undefined;
}
});
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
it('should fallback to default import behaviour if importer returns false for backwards compatibility', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function() {
return false;
}
});
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
it('should accept arrays of importers and return respect the order', function(done) { it('should accept arrays of importers and return respect the order', function(done) {
var result = sass.renderSync({ var result = sass.renderSync({
file: fixture('include-files/index.scss'), file: fixture('include-files/index.scss'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment