Skip to content

Commit

Permalink
Added unit tests for source comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aphex committed Jun 26, 2015
1 parent d8015f8 commit 59f49fd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
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);
});
});

0 comments on commit 59f49fd

Please sign in to comment.