Commit 535b5249 by Kevin Martensson

Cleanup tests

parent 4c65f3ad
This diff is collapsed. Click to expand it.
#navbar{width:80%;height:23px}#navbar ul{list-style-type:none}#navbar li{float:left}#navbar li a{font-weight:bold}
......@@ -2,11 +2,14 @@
width: 80%;
height: 23px;
}
#navbar ul {
list-style-type: none;
}
#navbar li {
float: left;
a {
font-weight: bold;
}
......
body {
background-image: url("/path/to/images/image.png"); }
body {
background-image: image-url('image.png');
background-image: image-url('image.png');
}
@import 'foo';
@import 'bar';
body {
background: red;
color: #0000fe; }
@import 'vars';
@import 'colorBlue';
body {
background: $color;
color: colorBlue();
}
foo + bar {
color: red; }
.foo {
margin: 1.23456789 px; }
.foo {
margin: 1.23456789 px;
}
#navbar {
width: 80%;
height: 23px; }
#navbar ul {
list-style-type: none; }
#navbar li {
float: left; }
#navbar li a {
font-weight: bold; }
#navbar {
width: 80%;
height: 23px;
}
#navbar ul {
list-style-type: none;
}
#navbar li {
float: left;
a {
font-weight: bold;
}
}
/* line 1, stdin */
#navbar {
width: 80%;
height: 23px; }
/* line 6, stdin */
#navbar ul {
list-style-type: none; }
/* line 10, stdin */
#navbar li {
float: left; }
/* line 13, stdin */
#navbar li a {
font-weight: bold; }
#navbar {
width: 80%;
height: 23px;
}
#navbar ul {
list-style-type: none;
}
#navbar li {
float: left;
a {
font-weight: bold;
}
}
#navbar {
width: 80%;
height: 23px; }
#navbar ul {
list-style-type: none; }
#navbar li {
float: left; }
#navbar li a {
font-weight: bold; }
/*# sourceMappingURL=index.map */
#navbar {
width: 80%;
height: 23px;
}
#navbar ul {
list-style-type: none;
}
#navbar li {
float: left;
a {
font-weight: bold;
}
}
@import "vars";
@import "colorBlue";
body { background: $color; color: colorBlue(); }
@import "sample.scss";
@import "image_path.scss";
This source diff could not be displayed because it is too large. You can view the blob instead.
// var util = require('util');
// var sass = require('../sass');
// var fs = require('fs');
//
// var bigScssStr = fs.readFileSync(require('path').resolve(__dirname,'large_test.scss'));
// var numTestCases = 1000;
// var numCompiled = 0;
// console.log(util.inspect(process.memoryUsage()));
// for (var i = 0; i < numTestCases; i++) {
// sass.render({
// data: bigScssStr,
// success: function() {
// numCompiled++;
// if (numCompiled === numTestCases) {
// console.log(util.inspect(process.memoryUsage()));
// }
// }
// });
// }
// var util = require('util');
// var sass = require('../sass');
// var fs = require('fs');
//
// var bigScssStr = fs.readFileSync(require('path').resolve(__dirname,'./large_test.scss'));
// var numTestCases = 1000;
// var numCompiled = 0;
// console.log(util.inspect(process.memoryUsage()));
// for (var i = 0; i < numTestCases; i++) {
// sass.renderSync({data: bigScssStr});
// }
// console.log(util.inspect(process.memoryUsage()));
exports.input = '#navbar {\
width: 80%;\
height: 23px; }\
#navbar ul {\
list-style-type: none; }\
#navbar li {\
float: left;\
a {\
font-weight: bold; }}\
@mixin keyAnimation($name, $attr, $value) {\
@-webkit-keyframes #{$name} {\
0% { #{$attr}: $value; }\
}\
}';
// Note that the bad
exports.badInput = '#navbar \n\
width: 80%';
exports.expectedRender = '#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
#navbar li {\n\
float: left; }\n\
#navbar li a {\n\
font-weight: bold; }\n';
\ No newline at end of file
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
sass = require('../sass');
var normalize = function(text) {
return text.replace(/\s+/g, '').replace('{', '{\n').replace(';', ';\n');
};
describe('sass-spec', function() {
var sassSpecPath = path.join(__dirname, 'sass-spec'),
sassSpecDirExists = fs.existsSync(sassSpecPath);
describe('spec directory', function() {
it('should be a cloned into place', function() {
try {
assert.ok(sassSpecDirExists);
} catch (e) {
console.log([
'test/sass-spec directory missing. Please clone it into place by',
'executing `git submodule update --init --recursive test/sass-spec`',
'from the project\'s root directory.'
].join(' '));
throw e;
}
});
});
if (sassSpecDirExists) {
var suitesPath = path.join(sassSpecPath, 'spec');
var suites = fs.readdirSync(suitesPath);
var ignoreSuites = ['libsass-todo-issues', 'libsass-todo-tests'];
suites.forEach(function(suite) {
if (ignoreSuites.indexOf(suite) !== -1) {
return;
}
describe(suite, function() {
var suitePath = path.join(suitesPath, suite);
var tests = fs.readdirSync(suitePath);
tests.forEach(function(test) {
var testPath = path.join(suitePath, test);
var inputFilePath = path.join(testPath, 'input.scss');
if (fs.existsSync(inputFilePath)) {
it(test, function(done) {
sass.render({
file: inputFilePath,
includePaths: [testPath, path.join(testPath, 'sub')],
success: function(css) {
var expected = fs.readFileSync(path.join(testPath, 'expected_output.css'), 'utf-8');
assert.equal(normalize(css), normalize(expected));
done();
},
error: function(error) {
done(new Error(error));
}
});
});
} else {
it(test);
}
});
});
});
}
});
var sass = require('../sass');
var assert = require('assert');
var sampleFilename = require('path').resolve(__dirname, 'sample.scss').replace(/\\/g, '/');
var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\
#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
/* line 5, ' + sampleFilename + ' */\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
/* line 8, ' + sampleFilename + ' */\n\
#navbar li {\n\
float: left; }\n\
/* line 10, ' + sampleFilename + ' */\n\
#navbar li a {\n\
font-weight: bold; }\n';
describe('compile file with source comments', function() {
it('should compile with render and comment outputs', function(done) {
sass.render({
file: sampleFilename,
source_comments: 'map',
success: function (css) {
done(assert.equal(css, expectedCommentsScssStr));
},
error: function (error) {
done(error);
}
});
});
});
var sass = require('../sass');
var assert = require('assert');
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
describe('compile source maps', function() {
it('should compile file with source map URL', function(done) {
var mapFileName = 'sample.css.map';
sass.render({
file: sampleFilename,
sourceComments: 'map',
sourceMap: mapFileName,
success: function (css, map) {
assert.ok(css.indexOf('sourceMappingURL=' + mapFileName) !== -1);
assert.ok(map.indexOf('sample.scss') !== -1);
done();
},
error: function (error) {
done(error);
}
});
});
});
var assert = require('assert'),
fs = require('fs'),
exists = fs.existsSync,
path = require('path'),
read = fs.readFileSync,
sass = require('../sass'),
util = require('./util');
describe('spec', function () {
var suites = util.getSuites();
describe('test/sass-spec directory', function() {
it('should be a cloned into place', function(done) {
fs.exists(path.join(__dirname, 'sass-spec'), function (exists) {
if (!exists) {
throw new Error([
'test/sass-spec directory missing. Please clone it into place by',
'executing `git submodule update --init --recursive test/sass-spec`',
'from the project\'s root directory.'
].join(' '));
}
assert(exists);
done();
});
});
});
Object.keys(suites).forEach(function(suite) {
var tests = Object.keys(suites[suite]);
describe(suite, function () {
tests.forEach(function(test) {
var t = suites[suite][test];
if (exists(t.src)) {
it(test, function(done) {
var expected = util.normalize(read(t.expected, 'utf8'));
sass.render({
file: t.src,
includePaths: t.paths,
success: function(css) {
assert.equal(util.normalize(css), expected);
done();
},
error: function(err) {
assert(!err);
done();
}
});
});
}
});
});
});
});
'use strict';
var path = require('path');
var assert = require('assert');
var sass = process.env.NODESASS_COVERAGE ? require('../sass-coverage') : require('../sass');
var includedFilesFile = path.resolve(__dirname, 'included_files.scss').replace(/\\/g, '/');
var sampleFile = path.resolve(__dirname, 'sample.scss').replace(/\\/g, '/');
var imagePathFile = path.resolve(__dirname, 'image_path.scss').replace(/\\/g, '/');
var sample = require('./sample.js');
describe('stats', function() {
var start = Date.now();
var stats;
function checkTimingStats() {
it('should provide a start timestamp', function() {
assert.ok(typeof stats.start === 'number');
assert.ok(stats.start >= start);
});
it('should provide an end timestamp', function() {
assert.ok(typeof stats.end === 'number');
assert.ok(stats.end >= stats.start);
});
it('should provide a duration', function() {
assert.ok(typeof stats.duration === 'number');
assert.equal(stats.end - stats.start, stats.duration);
});
}
describe('using renderSync()', function() {
describe('and file-context', function() {
before(function() {
sass.renderSync({
file: includedFilesFile,
stats: stats = {}
});
});
checkTimingStats();
it('should contain the given entry file', function() {
assert.equal(stats.entry, includedFilesFile);
});
it('should contain an array of all included files', function() {
// the included_files aren't sorted by libsass in any way
assert.deepEqual(
stats.includedFiles.sort(),
[includedFilesFile, sampleFile, imagePathFile].sort()
);
});
it('should contain an array with the entry-file if the there are no import statements', function () {
sass.renderSync({
file: sampleFile,
stats: stats = {}
});
assert.deepEqual(stats.includedFiles, [sampleFile]);
});
});
describe('and data-context', function() {
before(function() {
sass.renderSync({
data: sample.input,
stats: stats = {}
});
});
checkTimingStats();
it('should state "data" as entry file', function() {
assert.equal(stats.entry, 'data');
});
it('should contain an empty array as includedFiles in the data-context', function() {
assert.deepEqual(stats.includedFiles, []);
});
});
});
describe('using render()', function () {
describe('and file-context', function() {
before(function(done) {
sass.render({
file: includedFilesFile,
stats: stats = {},
success: function() {
done();
},
error: done
});
});
checkTimingStats();
it('should contain the given entry file', function() {
assert.equal(stats.entry, includedFilesFile);
});
it('should contain an array of all included files', function() {
// the included_files aren't sorted by libsass in any way
assert.deepEqual(
stats.includedFiles.sort(),
[includedFilesFile, sampleFile, imagePathFile].sort()
);
});
it('should contain an array with the entry-file if the there are no import statements', function(done) {
sass.render({
file: sampleFile,
stats: stats = {},
success: function() {
assert.deepEqual(stats.includedFiles, [sampleFile]);
done();
},
error: done
});
});
});
describe('and data-context', function() {
before(function(done) {
sass.render({
data: sample.input,
stats: stats = {},
success: function() {
done();
},
error: done
});
});
checkTimingStats();
it('should state "data" as entry file', function() {
assert.equal(stats.entry, 'data');
});
it('should contain an empty array as includedFiles in the data-context', function() {
assert.deepEqual(stats.includedFiles, []);
});
});
});
});
var sass = process.env.NODESASS_COVERAGE ? require('../sass-coverage') : require('../sass');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var sinon = require('sinon');
var badSampleFilename = 'sample.scss';
var sampleFilename = path.resolve(__dirname, 'sample.scss');
var sample = require('./sample.js');
describe('DEPRECATED: compile scss', function() {
it('should compile with render', function(done) {
sass.render(sample.input, function(err) {
done(err);
});
});
it('should compile with renderSync', function(done) {
done(assert.ok(sass.renderSync(sample.input)));
});
it('should match compiled string with render', function(done) {
sass.render(sample.input, function(err, css) {
if (!err) {
done(assert.equal(css, sample.expectedRender));
} else {
done(err);
}
});
});
it('should match compiled string with renderSync', function(done) {
done(assert.equal(sass.renderSync(sample.input), sample.expectedRender));
});
it('should throw an exception for bad input', function(done) {
done(assert.throws(function() {
sass.renderSync(sample.badInput);
}));
});
});
describe('compile scss', function() {
it('should compile with render', function(done) {
sass.render({
data: sample.input,
success: function(css) {
done(assert.ok(css));
}
});
});
it('should compile with renderSync', function(done) {
done(assert.ok(sass.renderSync({data: sample.input})));
});
it('should match compiled string with render', function(done) {
sass.render({
data: sample.input,
success: function(css) {
done(assert.equal(css, sample.expectedRender));
},
error: function(error) {
done(error);
}
});
});
it('should have a error status of 1 for bad css', function(done) {
sass.render({
data: '{zzz}',
success: function(css) {
console.log(css);
},
error: function(error, status) {
assert.equal(status, 1);
done();
}
});
});
it('should match compiled string with renderSync', function(done) {
done(assert.equal(sass.renderSync({data: sample.input}), sample.expectedRender));
});
it('should throw an exception for bad input', function(done) {
done(assert.throws(function() {
sass.renderSync({data: sample.badInput});
}));
});
});
describe('compile file with include paths', function(){
it('should compile with render', function(done) {
sass.render({
file: path.resolve(__dirname, 'include_path.scss'),
includePaths: [path.resolve(__dirname, 'lib'), path.resolve(__dirname, 'functions')],
success: function (css) {
done(assert.equal(css, 'body {\n background: red;\n color: #0000fe; }\n'));
},
error: function (error) {
done(error);
}
});
});
it('should compile with renderFile', function(done) {
var testFile = path.resolve(__dirname, 'tmp-include-path.css');
sass.renderFile({
file: path.resolve(__dirname, 'include_path.scss'),
outFile: testFile,
includePaths: [path.resolve(__dirname, 'lib'), path.resolve(__dirname, 'functions')],
success: function () {
done(assert.equal(fs.readFileSync(testFile, 'utf8'), 'body {\n background: red;\n color: #0000fe; }\n'));
fs.unlinkSync(testFile);
},
error: function (error) {
done(error);
}
});
});
});
describe('compile file with image path', function(){
it('should compile with render', function(done) {
sass.render({
file: path.resolve(__dirname, 'image_path.scss'),
imagePath: '/path/to/images',
success: function (css) {
done(assert.equal(css, 'body {\n background-image: url("/path/to/images/image.png"); }\n'));
},
error: function (error) {
done(error);
}
});
});
it('should throw on non-string path', function(done) {
try {
sass.render({
file: path.resolve(__dirname, 'image_path.scss'),
imagePath: ['/path/to/images'],
success: function () {},
error: function () {}
});
} catch(err) {
assert(err);
return done();
}
done(new Error('did not throw'));
});
});
describe('compile file', function() {
it('should compile with render', function(done) {
sass.render({
file: sampleFilename,
success: function (css) {
done(assert.equal(css, sample.expectedRender));
},
error: function (error) {
done(error);
}
});
});
it('should compile with renderSync', function(done) {
done(assert.ok(sass.renderSync({file: sampleFilename})));
});
it('should match compiled string with render', function(done) {
sass.render({
file: sampleFilename,
success: function(css) {
done(assert.equal(css, sample.expectedRender));
},
error: function(error) {
done(error);
}
});
});
it('should match compiled string with renderSync', function(done) {
done(assert.equal(sass.renderSync({file: sampleFilename}), sample.expectedRender));
});
it('should throw an exception for bad input', function(done) {
done(assert.throws(function() {
sass.renderSync({file: badSampleFilename});
}));
});
});
describe('render to file', function() {
var outFile = path.resolve(__dirname, 'out.css'),
filesWritten;
beforeEach(function() {
filesWritten = {};
sinon.stub(fs, 'writeFile', function(path, contents, cb) {
filesWritten[path] = contents;
cb();
});
});
afterEach(function() {
fs.writeFile.restore();
});
it('should compile with renderFile', function(done) {
sass.renderFile({
file: sampleFilename,
outFile: outFile,
success: function () {
var contents = filesWritten[outFile];
done(assert.equal(contents, sample.expectedRender));
},
error: function (error) {
done(error);
}
});
});
it('should raise an error for bad input', function(done) {
sass.renderFile({
file: badSampleFilename,
outFile: outFile,
success: function() {
assert(false, 'success() should not be called');
done();
},
error: function() {
assert(true, 'error() called');
done();
}
});
});
it('should save the sourceMap to the default file name', function(done) {
sass.renderFile({
file: sampleFilename,
outFile: outFile,
sourceMap: true,
success: function (cssFile, sourceMapFile) {
var css = filesWritten[cssFile];
var map = filesWritten[sourceMapFile];
var mapFileName = 'out.css.map';
assert.equal(path.basename(sourceMapFile), mapFileName);
assert.ok(css.indexOf('sourceMappingURL=' + mapFileName) !== -1);
assert.ok(map.indexOf('sample.scss') !== -1);
done();
},
error: function (error) {
done(error);
}
});
});
it('should save the sourceMap to a specified file name', function(done) {
var mapFileName = 'foo.css.map';
sass.renderFile({
file: sampleFilename,
outFile: outFile,
sourceMap: mapFileName,
success: function (cssFile, sourceMapFile) {
var css = filesWritten[cssFile];
var map = filesWritten[sourceMapFile];
assert.equal(path.basename(sourceMapFile), mapFileName);
assert.ok(css.indexOf('sourceMappingURL=' + mapFileName) !== -1);
assert.ok(map.indexOf('sample.scss') !== -1);
done();
},
error: function (error) {
done(error);
}
});
});
it('should save source paths relative to the sourceMap file', function(done) {
var includedFilesFile = path.resolve(__dirname, 'included_files.scss');
var relativeOutFile = path.resolve(__dirname, 'some_path/out.scss');
sass.renderFile({
file: includedFilesFile,
outFile: relativeOutFile,
sourceMap: true,
success: function (cssFile, sourceMapFile) {
var mapObject = JSON.parse(filesWritten[sourceMapFile]);
assert.ok(mapObject.sources.indexOf('../included_files.scss') > -1);
assert.ok(mapObject.sources.indexOf('../sample.scss') > -1);
assert.ok(mapObject.sources.indexOf('../image_path.scss') > -1);
done();
},
error: function (error) {
done(error);
}
});
});
});
describe('precision support', function() {
it('should render when precision is specified', function(done) {
sass.render({
data: '.test { margin: 1.23456789 px; }',
precision: 10,
success: function(css) {
done(assert.equal(css, '.test {\n margin: 1.23456789 px; }\n'));
},
error: function(error) {
done(error);
}
});
});
});
describe('compile with stats', function() {
it('should report correct sourceMap in stats with renderSync', function(done) {
var stats = {};
sass.renderSync({
file: sampleFilename,
stats: stats,
sourceMap: true
});
done(assert.ok(stats.sourceMap.indexOf('sample.scss') !== -1));
});
});
var fs = require('fs'),
join = require('path').join,
spec = join(__dirname, '..', 'sass-spec', 'spec');
/**
* Normalize CSS
*
* @param {String} css
* @api public
*/
module.exports.normalize = function(str) {
return str.replace(/\s+/g, '').replace('{', '{\n').replace(';', ';\n');
};
/**
* Get test suites
*
* @api public
*/
module.exports.getSuites = function() {
var ret = {};
var suites = fs.readdirSync(spec);
var ignoreSuites = [
'libsass-todo-issues',
'libsass-todo-tests'
];
suites.forEach(function(suite) {
if (ignoreSuites.indexOf(suite) !== -1) {
return;
}
var suitePath = join(spec, suite);
var tests = fs.readdirSync(suitePath);
ret[suite] = {};
tests.forEach(function(test) {
var testPath = join(suitePath, test);
ret[suite][test] = {};
ret[suite][test].src = join(testPath, 'input.scss');
ret[suite][test].expected = join(testPath, 'expected_output.css');
ret[suite][test].paths = [
testPath,
join(testPath, 'sub')
];
});
});
return ret;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment