Commit 4d00b340 by Adeel

Tests: Adds more importer tests.

parent 471a0759
...@@ -117,14 +117,14 @@ describe('api', function() { ...@@ -117,14 +117,14 @@ describe('api', function() {
}); });
it('should contain all included files in stats when data is passed', function(done) { it('should contain all included files in stats when data is passed', function(done) {
var src = fixture('include-files/index.scss'); var src = read(fixture('include-files/index.scss'), 'utf8');
var expected = [ var expected = [
fixture('include-files/bar.scss').replace(/\\/g, '/'), fixture('include-files/bar.scss').replace(/\\/g, '/'),
fixture('include-files/foo.scss').replace(/\\/g, '/') fixture('include-files/foo.scss').replace(/\\/g, '/')
]; ];
sass.render({ sass.render({
data: read(src, 'utf8'), data: src,
includePaths: [fixture('include-files')], includePaths: [fixture('include-files')],
success: function(result) { success: function(result) {
assert.deepEqual(result.stats.includedFiles, expected); assert.deepEqual(result.stats.includedFiles, expected);
...@@ -132,10 +132,12 @@ describe('api', function() { ...@@ -132,10 +132,12 @@ describe('api', function() {
} }
}); });
}); });
});
it('should override imports with custom importer with "data" as input and uses callback', function(done) { describe('.render(importer)', function() {
var src = read(fixture('include-files/index.scss'), 'utf8'); var src = read(fixture('include-files/index.scss'), 'utf8');
it('should override imports with "data" as input and fires callback with file and contents', function(done) {
sass.render({ sass.render({
data: src, data: src,
success: function(result) { success: function(result) {
...@@ -151,7 +153,7 @@ describe('api', function() { ...@@ -151,7 +153,7 @@ describe('api', function() {
}); });
}); });
it('should override imports with custom importer with "file" as input and uses callback', function(done) { it('should override imports with "file" as input and fires callback with file and contents', function(done) {
sass.render({ sass.render({
file: fixture('include-files/index.scss'), file: fixture('include-files/index.scss'),
success: function(result) { success: function(result) {
...@@ -167,9 +169,7 @@ describe('api', function() { ...@@ -167,9 +169,7 @@ describe('api', function() {
}); });
}); });
it('should override imports with custom importer with "data" as input and returns value', function(done) { it('should override imports with "data" as input and returns file and contents', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
sass.render({ sass.render({
data: src, data: src,
success: function(result) { success: function(result) {
...@@ -185,7 +185,7 @@ describe('api', function() { ...@@ -185,7 +185,7 @@ describe('api', function() {
}); });
}); });
it('should override imports with custom importer with "file" as input and returns value', function(done) { it('should override imports with "file" as input and returns file and contents', function(done) {
sass.render({ sass.render({
file: fixture('include-files/index.scss'), file: fixture('include-files/index.scss'),
success: function(result) { success: function(result) {
...@@ -200,6 +200,126 @@ describe('api', function() { ...@@ -200,6 +200,126 @@ describe('api', function() {
} }
}); });
}); });
it('should override imports with "data" as input and fires callback with file', function(done) {
sass.render({
data: src,
success: function(result) {
assert.equal(result.css.trim(), '');
done();
},
importer: function(url, /* jshint unused:false */ prev, done) {
done({
file: path.resolve(path.dirname(fixture('include-files/index.scss')), url + (path.extname(url) ? '' : '.scss'))
});
}
});
});
it('should override imports with "file" as input and fires callback with file', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
assert.equal(result.css.trim(), '');
done();
},
importer: function(url, prev, done) {
done({
file: path.resolve(path.dirname(prev), url + (path.extname(url) ? '' : '.scss'))
});
}
});
});
it('should override imports with "data" as input and returns file', function(done) {
sass.render({
data: src,
success: function(result) {
assert.equal(result.css.trim(), '');
done();
},
importer: function(url, /* jshint unused:false */ prev) {
return {
file: path.resolve(path.dirname(fixture('include-files/index.scss')), url + (path.extname(url) ? '' : '.scss'))
};
}
});
});
it('should override imports with "file" as input and returns file', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
assert.equal(result.css.trim(), '');
done();
},
importer: function(url, prev) {
return {
file: path.resolve(path.dirname(prev), url + (path.extname(url) ? '' : '.scss'))
};
}
});
});
it('should override imports with "data" as input and fires callback with contents', function(done) {
sass.render({
data: src,
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function(url, prev, done) {
done({
contents: 'div {color: yellow;}'
});
}
});
});
it('should override imports with "file" as input and fires callback with contents', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function(url, prev, done) {
done({
contents: 'div {color: yellow;}'
});
}
});
});
it('should override imports with "data" as input and returns contents', function(done) {
sass.render({
data: src,
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function() {
return {
contents: 'div {color: yellow;}'
};
}
});
});
it('should override imports with "file" as input and returns contents', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function() {
return {
contents: 'div {color: yellow;}'
};
}
});
});
}); });
describe('.renderSync(options)', function() { describe('.renderSync(options)', function() {
...@@ -239,14 +359,16 @@ describe('api', function() { ...@@ -239,14 +359,16 @@ describe('api', function() {
done(); done();
}); });
});
it('should override imports with custom importer with "data" as input and uses callback', function(done) { describe('.renderSync(importer)', function() {
var src = read(fixture('include-files/index.scss'), 'utf8'); var src = read(fixture('include-files/index.scss'), 'utf8');
it('should override imports with "data" as input and fires callback with file and contents', function(done) {
var result = sass.renderSync({ var result = sass.renderSync({
data: src, data: src,
importer: function(url, prev, finish) { importer: function(url, prev, done) {
finish({ done({
file: '/some/other/path.scss', file: '/some/other/path.scss',
contents: 'div {color: yellow;}' contents: 'div {color: yellow;}'
}); });
...@@ -257,11 +379,11 @@ describe('api', function() { ...@@ -257,11 +379,11 @@ describe('api', function() {
done(); done();
}); });
it('should override imports with custom importer with "file" as input and uses callback', function(done) { it('should override imports with "file" as input and fires callback with file and contents', function(done) {
var result = sass.renderSync({ var result = sass.renderSync({
file: fixture('include-files/index.scss'), file: fixture('include-files/index.scss'),
importer: function(url, prev, finish) { importer: function(url, prev, done) {
finish({ done({
file: '/some/other/path.scss', file: '/some/other/path.scss',
contents: 'div {color: yellow;}' contents: 'div {color: yellow;}'
}); });
...@@ -272,9 +394,7 @@ describe('api', function() { ...@@ -272,9 +394,7 @@ describe('api', function() {
done(); done();
}); });
it('should override imports with custom importer with "data" as input and returns value', function(done) { it('should override imports with "data" as input and returns file and contents', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
var result = sass.renderSync({ var result = sass.renderSync({
data: src, data: src,
importer: function(url, prev) { importer: function(url, prev) {
...@@ -289,7 +409,7 @@ describe('api', function() { ...@@ -289,7 +409,7 @@ describe('api', function() {
done(); done();
}); });
it('should override imports with custom importer with "file" as input and returns value', function(done) { it('should override imports with "file" as input and returns file and contents', function(done) {
var result = sass.renderSync({ var result = sass.renderSync({
file: fixture('include-files/index.scss'), file: fixture('include-files/index.scss'),
importer: function(url, prev) { importer: function(url, prev) {
...@@ -303,6 +423,118 @@ describe('api', function() { ...@@ -303,6 +423,118 @@ describe('api', function() {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }'); assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done(); done();
}); });
it('should override imports with "data" as input and fires callback with file', function(done) {
var result = sass.renderSync({
data: src,
importer: function(url, /* jshint unused:false */ prev, done) {
done({
file: path.resolve(path.dirname(fixture('include-files/index.scss')), url + (path.extname(url) ? '' : '.scss'))
});
}
});
assert.equal(result.css.trim(), '');
done();
});
it('should override imports with "file" as input and fires callback with file', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done({
file: path.resolve(path.dirname(prev), url + (path.extname(url) ? '' : '.scss'))
});
}
});
assert.equal(result.css.trim(), '');
done();
});
it('should override imports with "data" as input and returns file', function(done) {
var result = sass.renderSync({
data: src,
importer: function(url, /* jshint unused:false */ prev) {
return {
file: path.resolve(path.dirname(fixture('include-files/index.scss')), url + (path.extname(url) ? '' : '.scss'))
};
}
});
assert.equal(result.css.trim(), '');
done();
});
it('should override imports with "file" as input and returns file', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function(url, prev) {
return {
file: path.resolve(path.dirname(prev), url + (path.extname(url) ? '' : '.scss'))
};
}
});
assert.equal(result.css.trim(), '');
done();
});
it('should override imports with "data" as input and fires callback with contents', function(done) {
var result = sass.renderSync({
data: src,
importer: function(url, prev, done) {
done({
contents: 'div {color: yellow;}'
});
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
it('should override imports with "file" as input and fires callback with contents', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done({
contents: 'div {color: yellow;}'
});
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
it('should override imports with "data" as input and returns contents', function(done) {
var result = sass.renderSync({
data: src,
importer: function() {
return {
contents: 'div {color: yellow;}'
};
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
it('should override imports with "file" as input and returns contents', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function() {
return {
contents: 'div {color: yellow;}'
};
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
}); });
describe('.render({stats: {}})', function() { describe('.render({stats: {}})', function() {
......
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