Skip to content

Commit

Permalink
Add parse API unit tests
Browse files Browse the repository at this point in the history
- Refs #338
  • Loading branch information
pascalduez committed Jan 29, 2015
1 parent 9467577 commit 133057d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 30 deletions.
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/annotations/envMock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
logger : {
warn: function(){},
log: function(){},
error: function(){}
logger: {
warn: function () {},
log: function () {},
error: function () {},
}
};
36 changes: 30 additions & 6 deletions test/api/documentize.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
'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'));
assert.ok(fs.existsSync('sassdoc/assets'));
});

});

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));
});

});
42 changes: 34 additions & 8 deletions test/api/stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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));
});

});
13 changes: 8 additions & 5 deletions test/env/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
});

});

0 comments on commit 133057d

Please sign in to comment.