Skip to content

Commit

Permalink
Unit tests now work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
phawxby authored and xzyfer committed Mar 11, 2018
1 parent e45e200 commit 5c3ead2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 50 deletions.
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ platform:

environment:
matrix:
- nodejs_version: 0.10
- nodejs_version: 0.12
- nodejs_version: 4
- nodejs_version: 6
- nodejs_version: 8
# - nodejs_version: 0.10
# - nodejs_version: 0.12
# - nodejs_version: 4
# - nodejs_version: 6
# - nodejs_version: 8
- nodejs_version: 9

install:
Expand Down
109 changes: 64 additions & 45 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ var createVinyl = function createVinyl(filename, contents) {
});
};

var normaliseEOL = function(str) {
if (typeof(str) === 'object') {
str = str.toString('utf8');
}

return str.replace(/\r\n/g, '\n');
}

describe('test helpers', function() {
it('should normalise EOL', function(done) {
should.equal(normaliseEOL('foo\r\nbar'), 'foo\nbar');
should.equal(normaliseEOL('foo\nbar'), 'foo\nbar');
done();
});
});

describe('gulp-sass -- async compile', function() {
it('should pass file when it isNull()', function(done) {
var stream = sass();
Expand Down Expand Up @@ -66,8 +82,8 @@ describe('gulp-sass -- async compile', function() {
should.exist(cssFile.relative);
should.exist(cssFile.contents);
should.equal(path.basename(cssFile.path), 'empty.css');
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/empty.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'empty.css'), 'utf8'))
);
done();
});
Expand All @@ -82,8 +98,8 @@ describe('gulp-sass -- async compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
);
done();
});
Expand All @@ -97,18 +113,18 @@ describe('gulp-sass -- async compile', function() {
];
var stream = sass();
var mustSee = files.length;
var expectedPath = 'expected/mixins.css';
var expectedPath = path.join('expected', 'mixins.css');

stream.on('data', function(cssFile) {
should.exist(cssFile);
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
if (cssFile.path.indexOf('variables') !== -1) {
expectedPath = 'expected/variables.css';
expectedPath = path.join('expected', 'variables.css');
}
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
);
mustSee--;
if (mustSee <= 0) {
Expand All @@ -129,8 +145,8 @@ describe('gulp-sass -- async compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/inheritance.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'))
);
done();
});
Expand All @@ -145,11 +161,11 @@ describe('gulp-sass -- async compile', function() {
// Error must include message body
err.message.indexOf('property "font" must be followed by a \':\'').should.not.equal(-1);
// Error must include file error occurs in
err.message.indexOf('test/scss/error.scss').should.not.equal(-1);
err.message.indexOf('test', 'scss', 'error.scss').should.not.equal(-1);
// Error must include line and column error occurs on
err.message.indexOf('on line 2').should.not.equal(-1);
// Error must include relativePath property
err.relativePath.should.equal('test/scss/error.scss');
err.relativePath.should.equal(path.join('test', 'scss', 'error.scss'));
done();
});
stream.write(errorFile);
Expand Down Expand Up @@ -180,11 +196,11 @@ describe('gulp-sass -- async compile', function() {
stream.on('data', function(cssFile) {
should.exist(cssFile);
should.exist(cssFile.path);
cssFile.path.split('/').pop().should.equal('mixin--changed.css');
cssFile.path.split(path.sep).pop().should.equal('mixin--changed.css');
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
);
done();
});
Expand All @@ -204,8 +220,8 @@ describe('gulp-sass -- async compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal('/* Added Dynamically */\n' +
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal('/* Added Dynamically */\n' +
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
);
done();
});
Expand Down Expand Up @@ -250,8 +266,8 @@ describe('gulp-sass -- async compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/indent.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'indent.css'), 'utf8'))
);
done();
});
Expand All @@ -265,18 +281,18 @@ describe('gulp-sass -- async compile', function() {
];
var stream = sass();
var mustSee = files.length;
var expectedPath = 'expected/mixins.css';
var expectedPath = path.join('expected', 'mixins.css');

stream.on('data', function(cssFile) {
should.exist(cssFile);
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
if (cssFile.path.indexOf('indent') !== -1) {
expectedPath = 'expected/indent.css';
expectedPath = path.join('expected', 'indent.css');
}
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
);
mustSee--;
if (mustSee <= 0) {
Expand All @@ -292,7 +308,7 @@ describe('gulp-sass -- async compile', function() {

describe('gulp-sass -- sync compile', function() {
beforeEach(function(done) {
rimraf(path.join(__dirname, '/results/'), done);
rimraf(path.join(__dirname, 'results'), done);
});

it('should pass file when it isNull()', function(done) {
Expand Down Expand Up @@ -334,8 +350,8 @@ describe('gulp-sass -- sync compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
);
done();
});
Expand All @@ -349,18 +365,18 @@ describe('gulp-sass -- sync compile', function() {
];
var stream = sass.sync();
var mustSee = files.length;
var expectedPath = 'expected/mixins.css';
var expectedPath = path.join('expected', 'mixins.css');

stream.on('data', function(cssFile) {
should.exist(cssFile);
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
if (cssFile.path.indexOf('variables') !== -1) {
expectedPath = 'expected/variables.css';
expectedPath = path.join('expected', 'variables.css');
}
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
);
mustSee--;
if (mustSee <= 0) {
Expand All @@ -381,8 +397,8 @@ describe('gulp-sass -- sync compile', function() {
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/inheritance.css'), 'utf8')
String(normaliseEOL(cssFile.contents)).should.equal(
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'))
);
done();
});
Expand All @@ -395,7 +411,7 @@ describe('gulp-sass -- sync compile', function() {

stream.on('error', function(err) {
err.message.indexOf('property "font" must be followed by a \':\'').should.not.equal(-1);
err.relativePath.should.equal('test/scss/error.scss');
err.relativePath.should.equal(path.join('test', 'scss', 'error.scss'));
done();
});
stream.write(errorFile);
Expand Down Expand Up @@ -444,7 +460,7 @@ describe('gulp-sass -- sync compile', function() {
'inheritance.scss',
];

gulp.src(path.join(__dirname, '/scss/inheritance.scss'))
gulp.src(path.join(__dirname, 'scss', 'inheritance.scss'))
.pipe(sourcemaps.init())
.pipe(sass.sync())
.pipe(tap(function(file) {
Expand All @@ -453,7 +469,7 @@ describe('gulp-sass -- sync compile', function() {
}))
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.join(__dirname, '/results/')))
.pipe(gulp.dest(path.join(__dirname, 'results')))
.pipe(tap(function(file) {
should.exist(file.sourceMap);
file.sourceMap.sources.should.eql(expectedSourcesAfter);
Expand All @@ -463,19 +479,22 @@ describe('gulp-sass -- sync compile', function() {

it('should work with gulp-sourcemaps and a globbed source', function(done) {
var files, filesContent, actualContent, expectedContent, globPath;
files = globule.find(path.join(__dirname, '/scss/globbed/**/*.scss'));
globPath = path.join(__dirname, 'scss', 'globbed');
files = globule.find(path.join(__dirname, 'scss', 'globbed', '**', '*.scss'));
filesContent = {};

files.forEach(function(file) {
globPath = file.replace(path.join(__dirname, '/scss/globbed/'), '');
filesContent[globPath] = fs.readFileSync(file, 'utf8');
var source = path.normalize(path.relative(globPath, file));
filesContent[source] = fs.readFileSync(file, 'utf8');
});
gulp.src(path.join(__dirname, '/scss/globbed/**/*.scss'))

gulp.src(path.join(__dirname, 'scss', 'globbed', '**', '*.scss'))
.pipe(sourcemaps.init())
.pipe(sass.sync())
.pipe(tap(function(file) {
should.exist(file.sourceMap);
actualContent = file.sourceMap.sourcesContent[0];
expectedContent = filesContent[file.sourceMap.sources[0]];
actualContent = normaliseEOL(file.sourceMap.sourcesContent[0]);
expectedContent = normaliseEOL(filesContent[path.normalize(file.sourceMap.sources[0])]);
actualContent.should.eql(expectedContent);
}))
.on('end', done);
Expand All @@ -494,7 +513,7 @@ describe('gulp-sass -- sync compile', function() {
'scss/inheritance.scss'
];

gulp.src(path.join(__dirname, '/scss/inheritance.scss'), { 'base': 'test' })
gulp.src(path.join(__dirname, 'scss', 'inheritance.scss'), { 'base': 'test' })
.pipe(sourcemaps.init())
.pipe(sass.sync())
.pipe(tap(function(file) {
Expand All @@ -510,12 +529,12 @@ describe('gulp-sass -- sync compile', function() {
});

it('should work with empty files', function(done) {
gulp.src(path.join(__dirname, '/scss/empty.scss'))
gulp.src(path.join(__dirname, 'scss', 'empty.scss'))
.pipe(sass.sync())
.pipe(gulp.dest(path.join(__dirname, '/results/')))
.pipe(gulp.dest(path.join(__dirname, 'results')))
.pipe(tap(function() {
try {
fs.statSync(path.join(__dirname, '/results/empty.css'));
fs.statSync(path.join(__dirname, 'results', 'empty.css'));
}
catch (e) {
should.fail(false, true, 'Empty file was produced');
Expand Down

0 comments on commit 5c3ead2

Please sign in to comment.