Made tests better
This commit is contained in:
parent
52e7d845ee
commit
d537454052
10
test/ref/inheritance.css
Normal file
10
test/ref/inheritance.css
Normal file
|
@ -0,0 +1,10 @@
|
|||
.error, .badError {
|
||||
border: #f00;
|
||||
background: #fdd; }
|
||||
|
||||
.error.intrusion {
|
||||
font-size: 1.3em;
|
||||
font-weight: bold; }
|
||||
|
||||
.badError {
|
||||
border-width: 3px; }
|
8
test/ref/mixins.css
Normal file
8
test/ref/mixins.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
#data {
|
||||
float: left;
|
||||
margin-left: 10px; }
|
||||
#data th {
|
||||
text-align: center;
|
||||
font-weight: bold; }
|
||||
#data td, #data th {
|
||||
padding: 2px; }
|
9
test/ref/nesting.css
Normal file
9
test/ref/nesting.css
Normal file
|
@ -0,0 +1,9 @@
|
|||
table.hl {
|
||||
margin: 2em 0; }
|
||||
table.hl td.ln {
|
||||
text-align: right; }
|
||||
|
||||
li {
|
||||
font-family: serif;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em; }
|
8
test/ref/variables.css
Normal file
8
test/ref/variables.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
.content-navigation {
|
||||
border-color: #3bbfce;
|
||||
color: #2ca2af; }
|
||||
|
||||
.border {
|
||||
padding: 8px;
|
||||
margin: 8px;
|
||||
border-color: #3bbfce; }
|
2
test/scss/includes/_cats.scss
Normal file
2
test/scss/includes/_cats.scss
Normal file
|
@ -0,0 +1,2 @@
|
|||
$blue: #3bbfce;
|
||||
$margin: 16px;
|
|
@ -1,7 +1,10 @@
|
|||
@import "cats";
|
||||
|
||||
.error {
|
||||
border: 1px #f00;
|
||||
border: #f00;
|
||||
background: #fdd;
|
||||
}
|
||||
|
||||
.error.intrusion {
|
||||
font-size: 1.3em;
|
||||
font-weight: bold;
|
||||
|
|
115
test/test.js
115
test/test.js
|
@ -1,27 +1,98 @@
|
|||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
var gsass = require('../');
|
||||
var gutil = require('gulp-util');
|
||||
var fs = require('fs');
|
||||
|
||||
var path = require('path');
|
||||
var test = require('tape');
|
||||
|
||||
var gulp = require('gulp')
|
||||
, util = require('gulp-util')
|
||||
, gulpSass = require('../')
|
||||
, nodeSass = require('node-sass');
|
||||
;
|
||||
function createVinyl(sassFileName, contents) {
|
||||
var base = path.join(__dirname, 'scss');
|
||||
var filePath = path.join(base, sassFileName);
|
||||
|
||||
gulp.src('./scss/*.scss')
|
||||
.pipe(gulpSass())
|
||||
.pipe(util.buffer(tapeTester));
|
||||
|
||||
function tapeTester(err, files) {
|
||||
files.forEach(function (item) {
|
||||
var fileBaseName = path.basename(item.path, '.css');
|
||||
test('Testing: ' + fileBaseName, function (t) {
|
||||
var ref = nodeSass.renderSync({
|
||||
data: fs.readFileSync('./scss/' + fileBaseName + '.scss').toString()
|
||||
})
|
||||
t.equal(item.contents.toString(), ref);
|
||||
t.end();
|
||||
})
|
||||
return new gutil.File({
|
||||
cwd: __dirname,
|
||||
base: base,
|
||||
path: filePath,
|
||||
contents: contents || fs.readFileSync(filePath)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test('pass file when isNull()', function (t) {
|
||||
var stream = gsass();
|
||||
var emptyFile = {
|
||||
isNull: function () { return true; }
|
||||
};
|
||||
stream.on('data', function (data) {
|
||||
t.equal(data, emptyFile);
|
||||
t.end();
|
||||
});
|
||||
stream.write(emptyFile);
|
||||
});
|
||||
|
||||
// test('emit error when file isStream()', function (t) {
|
||||
// var stream = gsass();
|
||||
// var streamFile = {
|
||||
// isNull: function () { return false; },
|
||||
// isStream: function () { return true; }
|
||||
// };
|
||||
// stream.on()
|
||||
// });
|
||||
|
||||
test('compile a single sass file', function (t) {
|
||||
var sassFile = createVinyl('mixins.scss');
|
||||
|
||||
var stream = gsass();
|
||||
stream.on('data', function (cssFile) {
|
||||
t.ok(cssFile, 'cssFile should exist');
|
||||
t.ok(cssFile.path, 'cssFile.path should exist');
|
||||
t.ok(cssFile.relative, 'cssFile.relative should exist');
|
||||
t.ok(cssFile.contents, 'cssFile.contents should exist');
|
||||
t.equal(cssFile.path, path.join(__dirname, 'scss', 'mixins.css'));
|
||||
t.equal(
|
||||
fs.readFileSync(path.join(__dirname, 'ref/mixins.css'), 'utf8'),
|
||||
cssFile.contents.toString(),
|
||||
'file compiles correctly to css'
|
||||
);
|
||||
t.end();
|
||||
})
|
||||
stream.write(sassFile);
|
||||
});
|
||||
|
||||
test('compile multiple sass files', function (t) {
|
||||
var files = [
|
||||
createVinyl('inheritance.scss'),
|
||||
createVinyl('mixins.scss'),
|
||||
createVinyl('nesting.scss'),
|
||||
createVinyl('variables.scss')
|
||||
];
|
||||
|
||||
t.plan(files.length * 4);
|
||||
var stream = gsass({
|
||||
includePaths: [path.join(__dirname, 'scss'),
|
||||
path.join(__dirname, 'scss/includes')]
|
||||
});
|
||||
|
||||
stream.on('data', function (cssFile) {
|
||||
t.ok(cssFile, 'cssFile exists');
|
||||
t.ok(cssFile.path, 'cssFile.path exists');
|
||||
t.ok(cssFile.relative, 'cssFile.relative exists');
|
||||
t.ok(cssFile.contents, 'cssFile.contents exists');
|
||||
});
|
||||
|
||||
files.forEach(function (file) {
|
||||
stream.write(file);
|
||||
});
|
||||
});
|
||||
|
||||
test('emit error on sass errors', function (t) {
|
||||
var stream = gsass();
|
||||
var errorFile = createVinyl('somefile.sass',
|
||||
new Buffer('body { font \'Comic Sans\'; }'));
|
||||
stream.on('error', function (err) {
|
||||
t.equal(err.message,
|
||||
'source string:1: error: property "font" must be followed by a \':\'\n'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
stream.write(errorFile);
|
||||
});
|
Loading…
Reference in a new issue