Skip to content

Commit 5c3ead2

Browse files
phawxbyxzyfer
authored andcommitted
Unit tests now work on windows
1 parent e45e200 commit 5c3ead2

File tree

2 files changed

+69
-50
lines changed

2 files changed

+69
-50
lines changed

appveyor.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ platform:
1111

1212
environment:
1313
matrix:
14-
- nodejs_version: 0.10
15-
- nodejs_version: 0.12
16-
- nodejs_version: 4
17-
- nodejs_version: 6
18-
- nodejs_version: 8
14+
# - nodejs_version: 0.10
15+
# - nodejs_version: 0.12
16+
# - nodejs_version: 4
17+
# - nodejs_version: 6
18+
# - nodejs_version: 8
1919
- nodejs_version: 9
2020

2121
install:

test/main.js

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ var createVinyl = function createVinyl(filename, contents) {
2525
});
2626
};
2727

28+
var normaliseEOL = function(str) {
29+
if (typeof(str) === 'object') {
30+
str = str.toString('utf8');
31+
}
32+
33+
return str.replace(/\r\n/g, '\n');
34+
}
35+
36+
describe('test helpers', function() {
37+
it('should normalise EOL', function(done) {
38+
should.equal(normaliseEOL('foo\r\nbar'), 'foo\nbar');
39+
should.equal(normaliseEOL('foo\nbar'), 'foo\nbar');
40+
done();
41+
});
42+
});
43+
2844
describe('gulp-sass -- async compile', function() {
2945
it('should pass file when it isNull()', function(done) {
3046
var stream = sass();
@@ -66,8 +82,8 @@ describe('gulp-sass -- async compile', function() {
6682
should.exist(cssFile.relative);
6783
should.exist(cssFile.contents);
6884
should.equal(path.basename(cssFile.path), 'empty.css');
69-
String(cssFile.contents).should.equal(
70-
fs.readFileSync(path.join(__dirname, 'expected/empty.css'), 'utf8')
85+
String(normaliseEOL(cssFile.contents)).should.equal(
86+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'empty.css'), 'utf8'))
7187
);
7288
done();
7389
});
@@ -82,8 +98,8 @@ describe('gulp-sass -- async compile', function() {
8298
should.exist(cssFile.path);
8399
should.exist(cssFile.relative);
84100
should.exist(cssFile.contents);
85-
String(cssFile.contents).should.equal(
86-
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
101+
String(normaliseEOL(cssFile.contents)).should.equal(
102+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
87103
);
88104
done();
89105
});
@@ -97,18 +113,18 @@ describe('gulp-sass -- async compile', function() {
97113
];
98114
var stream = sass();
99115
var mustSee = files.length;
100-
var expectedPath = 'expected/mixins.css';
116+
var expectedPath = path.join('expected', 'mixins.css');
101117

102118
stream.on('data', function(cssFile) {
103119
should.exist(cssFile);
104120
should.exist(cssFile.path);
105121
should.exist(cssFile.relative);
106122
should.exist(cssFile.contents);
107123
if (cssFile.path.indexOf('variables') !== -1) {
108-
expectedPath = 'expected/variables.css';
124+
expectedPath = path.join('expected', 'variables.css');
109125
}
110-
String(cssFile.contents).should.equal(
111-
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
126+
String(normaliseEOL(cssFile.contents)).should.equal(
127+
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
112128
);
113129
mustSee--;
114130
if (mustSee <= 0) {
@@ -129,8 +145,8 @@ describe('gulp-sass -- async compile', function() {
129145
should.exist(cssFile.path);
130146
should.exist(cssFile.relative);
131147
should.exist(cssFile.contents);
132-
String(cssFile.contents).should.equal(
133-
fs.readFileSync(path.join(__dirname, 'expected/inheritance.css'), 'utf8')
148+
String(normaliseEOL(cssFile.contents)).should.equal(
149+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'))
134150
);
135151
done();
136152
});
@@ -145,11 +161,11 @@ describe('gulp-sass -- async compile', function() {
145161
// Error must include message body
146162
err.message.indexOf('property "font" must be followed by a \':\'').should.not.equal(-1);
147163
// Error must include file error occurs in
148-
err.message.indexOf('test/scss/error.scss').should.not.equal(-1);
164+
err.message.indexOf('test', 'scss', 'error.scss').should.not.equal(-1);
149165
// Error must include line and column error occurs on
150166
err.message.indexOf('on line 2').should.not.equal(-1);
151167
// Error must include relativePath property
152-
err.relativePath.should.equal('test/scss/error.scss');
168+
err.relativePath.should.equal(path.join('test', 'scss', 'error.scss'));
153169
done();
154170
});
155171
stream.write(errorFile);
@@ -180,11 +196,11 @@ describe('gulp-sass -- async compile', function() {
180196
stream.on('data', function(cssFile) {
181197
should.exist(cssFile);
182198
should.exist(cssFile.path);
183-
cssFile.path.split('/').pop().should.equal('mixin--changed.css');
199+
cssFile.path.split(path.sep).pop().should.equal('mixin--changed.css');
184200
should.exist(cssFile.relative);
185201
should.exist(cssFile.contents);
186-
String(cssFile.contents).should.equal(
187-
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
202+
String(normaliseEOL(cssFile.contents)).should.equal(
203+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
188204
);
189205
done();
190206
});
@@ -204,8 +220,8 @@ describe('gulp-sass -- async compile', function() {
204220
should.exist(cssFile.path);
205221
should.exist(cssFile.relative);
206222
should.exist(cssFile.contents);
207-
String(cssFile.contents).should.equal('/* Added Dynamically */\n' +
208-
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
223+
String(normaliseEOL(cssFile.contents)).should.equal('/* Added Dynamically */\n' +
224+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
209225
);
210226
done();
211227
});
@@ -250,8 +266,8 @@ describe('gulp-sass -- async compile', function() {
250266
should.exist(cssFile.path);
251267
should.exist(cssFile.relative);
252268
should.exist(cssFile.contents);
253-
String(cssFile.contents).should.equal(
254-
fs.readFileSync(path.join(__dirname, 'expected/indent.css'), 'utf8')
269+
String(normaliseEOL(cssFile.contents)).should.equal(
270+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'indent.css'), 'utf8'))
255271
);
256272
done();
257273
});
@@ -265,18 +281,18 @@ describe('gulp-sass -- async compile', function() {
265281
];
266282
var stream = sass();
267283
var mustSee = files.length;
268-
var expectedPath = 'expected/mixins.css';
284+
var expectedPath = path.join('expected', 'mixins.css');
269285

270286
stream.on('data', function(cssFile) {
271287
should.exist(cssFile);
272288
should.exist(cssFile.path);
273289
should.exist(cssFile.relative);
274290
should.exist(cssFile.contents);
275291
if (cssFile.path.indexOf('indent') !== -1) {
276-
expectedPath = 'expected/indent.css';
292+
expectedPath = path.join('expected', 'indent.css');
277293
}
278-
String(cssFile.contents).should.equal(
279-
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
294+
String(normaliseEOL(cssFile.contents)).should.equal(
295+
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
280296
);
281297
mustSee--;
282298
if (mustSee <= 0) {
@@ -292,7 +308,7 @@ describe('gulp-sass -- async compile', function() {
292308

293309
describe('gulp-sass -- sync compile', function() {
294310
beforeEach(function(done) {
295-
rimraf(path.join(__dirname, '/results/'), done);
311+
rimraf(path.join(__dirname, 'results'), done);
296312
});
297313

298314
it('should pass file when it isNull()', function(done) {
@@ -334,8 +350,8 @@ describe('gulp-sass -- sync compile', function() {
334350
should.exist(cssFile.path);
335351
should.exist(cssFile.relative);
336352
should.exist(cssFile.contents);
337-
String(cssFile.contents).should.equal(
338-
fs.readFileSync(path.join(__dirname, 'expected/mixins.css'), 'utf8')
353+
String(normaliseEOL(cssFile.contents)).should.equal(
354+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'))
339355
);
340356
done();
341357
});
@@ -349,18 +365,18 @@ describe('gulp-sass -- sync compile', function() {
349365
];
350366
var stream = sass.sync();
351367
var mustSee = files.length;
352-
var expectedPath = 'expected/mixins.css';
368+
var expectedPath = path.join('expected', 'mixins.css');
353369

354370
stream.on('data', function(cssFile) {
355371
should.exist(cssFile);
356372
should.exist(cssFile.path);
357373
should.exist(cssFile.relative);
358374
should.exist(cssFile.contents);
359375
if (cssFile.path.indexOf('variables') !== -1) {
360-
expectedPath = 'expected/variables.css';
376+
expectedPath = path.join('expected', 'variables.css');
361377
}
362-
String(cssFile.contents).should.equal(
363-
fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')
378+
String(normaliseEOL(cssFile.contents)).should.equal(
379+
normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'))
364380
);
365381
mustSee--;
366382
if (mustSee <= 0) {
@@ -381,8 +397,8 @@ describe('gulp-sass -- sync compile', function() {
381397
should.exist(cssFile.path);
382398
should.exist(cssFile.relative);
383399
should.exist(cssFile.contents);
384-
String(cssFile.contents).should.equal(
385-
fs.readFileSync(path.join(__dirname, 'expected/inheritance.css'), 'utf8')
400+
String(normaliseEOL(cssFile.contents)).should.equal(
401+
normaliseEOL(fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'))
386402
);
387403
done();
388404
});
@@ -395,7 +411,7 @@ describe('gulp-sass -- sync compile', function() {
395411

396412
stream.on('error', function(err) {
397413
err.message.indexOf('property "font" must be followed by a \':\'').should.not.equal(-1);
398-
err.relativePath.should.equal('test/scss/error.scss');
414+
err.relativePath.should.equal(path.join('test', 'scss', 'error.scss'));
399415
done();
400416
});
401417
stream.write(errorFile);
@@ -444,7 +460,7 @@ describe('gulp-sass -- sync compile', function() {
444460
'inheritance.scss',
445461
];
446462

447-
gulp.src(path.join(__dirname, '/scss/inheritance.scss'))
463+
gulp.src(path.join(__dirname, 'scss', 'inheritance.scss'))
448464
.pipe(sourcemaps.init())
449465
.pipe(sass.sync())
450466
.pipe(tap(function(file) {
@@ -453,7 +469,7 @@ describe('gulp-sass -- sync compile', function() {
453469
}))
454470
.pipe(postcss([autoprefixer()]))
455471
.pipe(sourcemaps.write())
456-
.pipe(gulp.dest(path.join(__dirname, '/results/')))
472+
.pipe(gulp.dest(path.join(__dirname, 'results')))
457473
.pipe(tap(function(file) {
458474
should.exist(file.sourceMap);
459475
file.sourceMap.sources.should.eql(expectedSourcesAfter);
@@ -463,19 +479,22 @@ describe('gulp-sass -- sync compile', function() {
463479

464480
it('should work with gulp-sourcemaps and a globbed source', function(done) {
465481
var files, filesContent, actualContent, expectedContent, globPath;
466-
files = globule.find(path.join(__dirname, '/scss/globbed/**/*.scss'));
482+
globPath = path.join(__dirname, 'scss', 'globbed');
483+
files = globule.find(path.join(__dirname, 'scss', 'globbed', '**', '*.scss'));
467484
filesContent = {};
485+
468486
files.forEach(function(file) {
469-
globPath = file.replace(path.join(__dirname, '/scss/globbed/'), '');
470-
filesContent[globPath] = fs.readFileSync(file, 'utf8');
487+
var source = path.normalize(path.relative(globPath, file));
488+
filesContent[source] = fs.readFileSync(file, 'utf8');
471489
});
472-
gulp.src(path.join(__dirname, '/scss/globbed/**/*.scss'))
490+
491+
gulp.src(path.join(__dirname, 'scss', 'globbed', '**', '*.scss'))
473492
.pipe(sourcemaps.init())
474493
.pipe(sass.sync())
475494
.pipe(tap(function(file) {
476495
should.exist(file.sourceMap);
477-
actualContent = file.sourceMap.sourcesContent[0];
478-
expectedContent = filesContent[file.sourceMap.sources[0]];
496+
actualContent = normaliseEOL(file.sourceMap.sourcesContent[0]);
497+
expectedContent = normaliseEOL(filesContent[path.normalize(file.sourceMap.sources[0])]);
479498
actualContent.should.eql(expectedContent);
480499
}))
481500
.on('end', done);
@@ -494,7 +513,7 @@ describe('gulp-sass -- sync compile', function() {
494513
'scss/inheritance.scss'
495514
];
496515

497-
gulp.src(path.join(__dirname, '/scss/inheritance.scss'), { 'base': 'test' })
516+
gulp.src(path.join(__dirname, 'scss', 'inheritance.scss'), { 'base': 'test' })
498517
.pipe(sourcemaps.init())
499518
.pipe(sass.sync())
500519
.pipe(tap(function(file) {
@@ -510,12 +529,12 @@ describe('gulp-sass -- sync compile', function() {
510529
});
511530

512531
it('should work with empty files', function(done) {
513-
gulp.src(path.join(__dirname, '/scss/empty.scss'))
532+
gulp.src(path.join(__dirname, 'scss', 'empty.scss'))
514533
.pipe(sass.sync())
515-
.pipe(gulp.dest(path.join(__dirname, '/results/')))
534+
.pipe(gulp.dest(path.join(__dirname, 'results')))
516535
.pipe(tap(function() {
517536
try {
518-
fs.statSync(path.join(__dirname, '/results/empty.css'));
537+
fs.statSync(path.join(__dirname, 'results', 'empty.css'));
519538
}
520539
catch (e) {
521540
should.fail(false, true, 'Empty file was produced');

0 commit comments

Comments
 (0)