diff --git a/test/expected/source-comments/inheritance.css b/test/expected/source-comments/inheritance.css new file mode 100644 index 00000000..90781ce1 --- /dev/null +++ b/test/expected/source-comments/inheritance.css @@ -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; } diff --git a/test/expected/source-comments/variables.css b/test/expected/source-comments/variables.css new file mode 100644 index 00000000..aa76fefa --- /dev/null +++ b/test/expected/source-comments/variables.css @@ -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; } diff --git a/test/main.js b/test/main.js index 5c2ba607..dfa58bee 100644 --- a/test/main.js +++ b/test/main.js @@ -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); + }); +});