Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var gulpSass = function gulpSass(options, sync) {

opts = assign({}, options);
opts.data = file.contents.toString();
opts.file = opts.file || file.path;

// Ensure `indentedSyntax` is true if a `.sass` file
if (path.extname(file.path) === '.sass') {
Expand Down
21 changes: 21 additions & 0 deletions test/expected/source-comments/inheritance.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* line 4, /test/path/_cats.scss */
body {
background: pink; }

/* line 4, /test/path/_dogs.sass */
footer {
background: red; }

/* line 4, /test/path/inheritance.scss */
.error, .badError {
border: #f00;
background: #fdd; }

/* line 9, /test/path/inheritance.scss */
.error.intrusion, .intrusion.badError {
font-size: 1.3em;
font-weight: bold; }

/* line 14, /test/path/inheritance.scss */
.badError {
border-width: 3px; }
10 changes: 10 additions & 0 deletions test/expected/source-comments/variables.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* line 4, /test/path/variables.scss */
.content-navigation {
border-color: #3bbfce;
color: #2ca2af; }

/* line 10, /test/path/variables.scss */
.border {
padding: 8px;
margin: 8px;
border-color: #3bbfce; }
39 changes: 39 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,42 @@ describe('gulp-sass -- sync compile', function() {
.on('end', done);
});
});

describe('gulp-sass -- source comments', function() {
var testPath = '/test/path/';

// Replace comment path from current users filesystem to something we can test consistently
var swapPathForTesting = function (contents) {
return contents.replace(/(.*)(, )(.*?)(\w+\.(?:scss|sass))( \*\/)/g, '$1$2' + testPath + '$4$5');
};

it('should properly add file path comment', function(done) {
var sassFile = createVinyl('variables.scss');
var stream = sass({ 'sourceComments': true });
stream.on('data', function(cssFile) {
var contents;
should.exist(cssFile.contents);
contents = swapPathForTesting(cssFile.contents.toString());
contents.should.equal(
fs.readFileSync(path.join(__dirname, 'expected/source-comments/variables.css'), 'utf8')
);
done();
});
stream.write(sassFile);
});

it('should properly add file path comment with includes', function(done) {
var sassFile = createVinyl('inheritance.scss');
var stream = sass({ 'sourceComments': true });
stream.on('data', function(cssFile) {
var contents;
should.exist(cssFile.contents);
contents = swapPathForTesting(cssFile.contents.toString());
contents.should.equal(
fs.readFileSync(path.join(__dirname, 'expected/source-comments/inheritance.css'), 'utf8')
);
done();
});
stream.write(sassFile);
});
});