Updated main to coding standards
This commit is contained in:
parent
47e6b7c772
commit
a096e3cfb0
85
test/main.js
85
test/main.js
|
@ -1,27 +1,31 @@
|
|||
var should = require("should");
|
||||
var gutil = require("gulp-util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var sass = require("../index");
|
||||
'use strict';
|
||||
|
||||
var should = require('should');
|
||||
var gutil = require('gulp-util');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var sass = require('../index');
|
||||
var assert = require('assert');
|
||||
|
||||
function createVinyl(filename, contents) {
|
||||
var base = path.join(__dirname, "scss");
|
||||
var createVinyl = function createVinyl(filename, contents) {
|
||||
var base = path.join(__dirname, 'scss');
|
||||
var filePath = path.join(base, filename);
|
||||
|
||||
return new gutil.File({
|
||||
cwd: __dirname,
|
||||
base: base,
|
||||
path: filePath,
|
||||
contents: contents || fs.readFileSync(filePath)
|
||||
'cwd': __dirname,
|
||||
'base': base,
|
||||
'path': filePath,
|
||||
'contents': contents || fs.readFileSync(filePath)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
describe("gulp-sass", function() {
|
||||
it("should pass file when it isNull()", function(done) {
|
||||
describe('gulp-sass', function() {
|
||||
it('should pass file when it isNull()', function(done) {
|
||||
var stream = sass();
|
||||
var emptyFile = {
|
||||
isNull: function () { return true; }
|
||||
'isNull': function () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
stream.on('data', function(data) {
|
||||
data.should.equal(emptyFile);
|
||||
|
@ -33,8 +37,12 @@ describe("gulp-sass", function() {
|
|||
it('should emit error when file isStream()', function (done) {
|
||||
var stream = sass();
|
||||
var streamFile = {
|
||||
isNull: function () { return false; },
|
||||
isStream: function () { return true; }
|
||||
'isNull': function () {
|
||||
return false;
|
||||
},
|
||||
'isStream': function () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
stream.on('error', function(err) {
|
||||
err.message.should.equal('Streaming not supported');
|
||||
|
@ -43,10 +51,10 @@ describe("gulp-sass", function() {
|
|||
stream.write(streamFile);
|
||||
});
|
||||
|
||||
it("should compile a single sass file", function(done) {
|
||||
var sassFile = createVinyl("mixins.scss");
|
||||
it('should compile a single sass file', function(done) {
|
||||
var sassFile = createVinyl('mixins.scss');
|
||||
var stream = sass();
|
||||
stream.on("data", function(cssFile) {
|
||||
stream.on('data', function(cssFile) {
|
||||
should.exist(cssFile);
|
||||
should.exist(cssFile.path);
|
||||
should.exist(cssFile.relative);
|
||||
|
@ -59,21 +67,21 @@ describe("gulp-sass", function() {
|
|||
stream.write(sassFile);
|
||||
});
|
||||
|
||||
it("should compile multiple sass files", function(done) {
|
||||
it('should compile multiple sass files', function(done) {
|
||||
var files = [
|
||||
createVinyl('mixins.scss'),
|
||||
createVinyl('variables.scss')
|
||||
];
|
||||
var stream = sass();
|
||||
var mustSee = files.length;
|
||||
var expectedPath = 'expected/mixins.css';
|
||||
|
||||
stream.on("data", function(cssFile) {
|
||||
stream.on('data', function(cssFile) {
|
||||
should.exist(cssFile);
|
||||
should.exist(cssFile.path);
|
||||
should.exist(cssFile.relative);
|
||||
should.exist(cssFile.contents);
|
||||
var expectedPath = 'expected/mixins.css';
|
||||
if (cssFile.path.indexOf("variables") !== -1) {
|
||||
if (cssFile.path.indexOf('variables') !== -1) {
|
||||
expectedPath = 'expected/variables.css';
|
||||
}
|
||||
String(cssFile.contents).should.equal(
|
||||
|
@ -90,10 +98,10 @@ describe("gulp-sass", function() {
|
|||
});
|
||||
});
|
||||
|
||||
it("should compile files with partials in another folder", function(done) {
|
||||
var sassFile = createVinyl("inheritance.scss");
|
||||
it('should compile files with partials in another folder', function(done) {
|
||||
var sassFile = createVinyl('inheritance.scss');
|
||||
var stream = sass();
|
||||
stream.on("data", function(cssFile) {
|
||||
stream.on('data', function(cssFile) {
|
||||
should.exist(cssFile);
|
||||
should.exist(cssFile.path);
|
||||
should.exist(cssFile.relative);
|
||||
|
@ -106,19 +114,19 @@ describe("gulp-sass", function() {
|
|||
stream.write(sassFile);
|
||||
});
|
||||
|
||||
it("should handle sass errors", function(done) {
|
||||
var errorFile = createVinyl("error.scss");
|
||||
it('should handle sass errors', function(done) {
|
||||
var errorFile = createVinyl('error.scss');
|
||||
var stream = sass();
|
||||
|
||||
stream.on("error", function(err) {
|
||||
stream.on('error', function(err) {
|
||||
err.message.indexOf('property "font" must be followed by a \':\'').should.equal(0);
|
||||
done();
|
||||
});
|
||||
stream.write(errorFile);
|
||||
});
|
||||
|
||||
it("should work with gulp-sourcemaps", function(done) {
|
||||
var sassFile = createVinyl("inheritance.scss");
|
||||
it('should work with gulp-sourcemaps', function(done) {
|
||||
var sassFile = createVinyl('inheritance.scss');
|
||||
|
||||
// Expected sources are relative to file.base
|
||||
var expectedSources = [
|
||||
|
@ -126,22 +134,23 @@ describe("gulp-sass", function() {
|
|||
'inheritance.scss'
|
||||
];
|
||||
|
||||
var stream;
|
||||
|
||||
sassFile.sourceMap = '{' +
|
||||
'"version": 3,' +
|
||||
'"file": "scss/inheritance.scss",' +
|
||||
'"file": "scss/subdir/multilevelimport.scss",' +
|
||||
'"names": [],' +
|
||||
'"mappings": "",' +
|
||||
'"sources": [ "scss/inheritance.scss" ],' +
|
||||
'"sourcesContent": [ "@import includes/cats;" ]' +
|
||||
'"sources": [ "scss/subdir/multilevelimport.scss" ],' +
|
||||
'"sourcesContent": [ "@import ../inheritance;" ]' +
|
||||
'}';
|
||||
|
||||
var stream = sass();
|
||||
stream.on("data", function(cssFile) {
|
||||
stream = sass();
|
||||
stream.on('data', function(cssFile) {
|
||||
should.exist(cssFile.sourceMap);
|
||||
assert.deepEqual(cssFile.sourceMap.sources, expectedSources);
|
||||
done();
|
||||
});
|
||||
stream.write(sassFile);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue