diff --git a/Makefile b/Makefile index 29f30f62..f1521bdc 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,11 @@ dist: lint: .jshintrc jshint bin/sassdoc index.js src test +.jshintrc: .jshintrc.yaml + js-yaml $< > $@ + test: test/data/expected.stream.json dist - mocha test/annotations/*.test.js - mocha test/env/*.test.js test/utils/*.test.js - rm -rf sassdoc && $(MOCHA) test/api/*.test.js + $(MOCHA) test/**/*.test.js $(SASSDOC) --parse test/data/test.scss | diff - test/data/expected.json $(SASSDOC) --parse < test/data/test.scss | diff - test/data/expected.stream.json rm -rf sassdoc && $(SASSDOC) test/data/test.scss && [ -d sassdoc ] @@ -30,9 +31,6 @@ test: test/data/expected.stream.json dist test/data/expected.stream.json: test/data/expected.json test/data/stream $< > $@ -.jshintrc: .jshintrc.yaml - js-yaml $< > $@ - cover: dist rm -rf coverage istanbul cover --report none --print detail $(MOCHA) test/**/*.test.js @@ -42,7 +40,7 @@ cover-browse: dist istanbul cover --report html $(MOCHA) test/**/*.test.js open coverage/index.html -travis: cover +travis: lint cover istanbul report lcovonly (cat coverage/lcov.info | coveralls) || exit 0 rm -rf coverage diff --git a/test/annotations/envMock.js b/test/annotations/envMock.js index 6066d437..0c7a1321 100644 --- a/test/annotations/envMock.js +++ b/test/annotations/envMock.js @@ -1,7 +1,7 @@ module.exports = { - logger : { - warn: function(){}, - log: function(){}, - error: function(){} + logger: { + warn: function () {}, + log: function () {}, + error: function () {}, } }; diff --git a/test/api/documentize.test.js b/test/api/documentize.test.js index 128ed703..b9c8fcb3 100644 --- a/test/api/documentize.test.js +++ b/test/api/documentize.test.js @@ -1,20 +1,26 @@ 'use strict'; -var assert = require('assert'); var fs = require('fs'); +var assert = require('assert'); var rimraf = require('rimraf'); var sassdoc = require('../../'); +function clean(done) { + rimraf('sassdoc', done); +} + +function read(filePath) { + return fs.readFileSync(filePath, 'utf8'); +} + describe('#documentize', function () { + before(clean); + after(clean); - before(function () { + beforeEach(function () { return sassdoc('./test/data'); }); - after(function (done) { - rimraf('sassdoc', done); - }); - it('should produce documentation files', function () { assert.ok(fs.existsSync('sassdoc')); assert.ok(fs.existsSync('sassdoc/index.html')); @@ -22,3 +28,21 @@ describe('#documentize', function () { }); }); + +describe('#documentize-parse', function () { + var expected = read('test/data/expected.json').trim(); + var result; + + before(function () { + return sassdoc.parse('test/data/test.scss') + .then(function (data) { + result = data; + }); + }); + + it('should return a proper data Array', function () { + assert.ok(Array.isArray(result)); + assert.strictEqual(expected, JSON.stringify(result, null, 2)); + }); + +}); diff --git a/test/api/stream.test.js b/test/api/stream.test.js index 93693f7d..2552e288 100644 --- a/test/api/stream.test.js +++ b/test/api/stream.test.js @@ -6,19 +6,25 @@ var vfs = require('vinyl-fs'); var rimraf = require('rimraf'); var sassdoc = require('../../'); +function clean(done) { + rimraf('sassdoc', done); +} + +function read(filePath) { + return fs.readFileSync(filePath, 'utf8'); +} + describe('#stream', function () { + before(clean); + after(clean); - before(function () { - var parse = sassdoc(); + beforeEach(function () { + var stream = sassdoc(); vfs.src('./test/data/**/*.scss') - .pipe(parse); - - return parse.promise; - }); + .pipe(stream); - after(function (done) { - rimraf('sassdoc', done); + return stream.promise; }); it('should produce documentation files', function () { @@ -28,3 +34,23 @@ describe('#stream', function () { }); }); + +describe('#stream-parse', function () { + var expected = read('test/data/expected.json').trim(); + var result; + + before(function (done) { + vfs.src('./test/data/**/*.scss') + .pipe(sassdoc.parse()) + .on('data', function (data) { + result = data; + done(); + }); + }); + + it('should return a proper data Array', function () { + assert.ok(Array.isArray(result)); + assert.strictEqual(expected, JSON.stringify(result, null, 2)); + }); + +}); diff --git a/test/env/logger.test.js b/test/env/logger.test.js index 04845ad6..b53d70f4 100644 --- a/test/env/logger.test.js +++ b/test/env/logger.test.js @@ -17,6 +17,8 @@ function debug(str) { return '\u001b[90m\xBB [DEBUG] ' + str + ' \u001b[39m\n'; } +var noop = function () {}; + describe('#logger', function () { var logger; var stderrWrite; @@ -53,7 +55,7 @@ describe('#logger', function () { logger.debug('foo'); logger.debug('foo', 'bar'); logger.debug('%s %s', 'foo', 'bar', 'hop'); - logger.debug(function(){return 'foo bar hop hop';}); + logger.debug(function () { return 'foo bar hop hop'; }); // test logger.timeEnd() logger.time('label'); @@ -119,18 +121,19 @@ describe('#logger', function () { assert.deepEqual(Logger.empty.debug(), undefined); }); - it('should have a function to check if a object is a logger', function () { + it('should have a function to check if an object is a valid logger', function () { assert.ok(Logger.checkLogger(Logger.empty)); assert.throws(function () { - Logger.checkLogger({ log : function() {} }); + Logger.checkLogger({ log: noop }); }); assert.throws(function () { - Logger.checkLogger({ log : function() {}, warn : function(){} }); + Logger.checkLogger({ log: noop, warn: noop }); }); - assert.ok(Logger.checkLogger({ log : function() {}, warn : function(){}, error : function(){} })); + assert.ok(Logger.checkLogger({ log: noop, warn: noop, error: noop })); }); after(function () { global.process.stderr.write = stderrWrite; }); + });