Skip to content

Commit

Permalink
Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Jul 20, 2015
1 parent 4b8bf2a commit bf9efcd
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

## 0.1.0 (July 19, 2015)
## 0.1.0 (July 20, 2015)
* Initial version, with tests.

## 0.1.0-rc1 (July 19, 2015)
* Initial version.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var assign = require('object-assign');
var filter = require('./lib/filter.js');

// Configure.
hexo.config.ucss = assign({
hexo.config.uncss = assign({
enable : true,
ignore : [ ],
media : null,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "hexo-uncss",
"version" : "0.1.0-rc1",
"version" : "0.1.0",
"description" : "uncss plugin for Hexo.",
"keywords" : [ "hexo", "hexo-plugin", "hexo-filter", "uncss", "css", "html" ],
"homepage" : "https://github.com/vseventer/hexo-uncss",
Expand Down
73 changes: 69 additions & 4 deletions test/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,79 @@
// Strict mode.
'use strict';

// Standard lib.
var fs = require('fs'),
path = require('path');

// Local modules.
var subject = require('../lib/filter.js');

// Configure.
var fixture = path.join(__dirname, 'fixture.html');

// Stub hexo.route.
var hexoRoute = {
get: function(name) {
return fs.createReadStream(name, { encoding: 'utf8' });
},
list: function() {
return [ fixture ];
}
};

// Test suite.
describe('hexo-uncss', function() {

// Tests.
it('should remove unused styles from CSS.');
it('should support uncss options.');
it('should do nothing if disabled.');
it('should remove unused styles from CSS.', function() {
// Configure.
var data = 'div { color: black; } span { color: white; }';
var hexo = {
config: {
uncss: { }
},
route: hexoRoute
};

// Filter and test.
var promise = subject.call(hexo, data);
return promise.then(function(result) {
result = result.replace(/\s/g, ''); // Perform a whitespace ..
var expected = 'div{color:black;}'; // insensitive comparison.
console.assert(result === expected);
});
});

it('should support uncss options.', function() {
// Configure.
var data = 'div { color: black; } span { color: white; }';
var hexo = {
config: {
uncss: { ignore: [ 'span' ] }
},
route: hexoRoute
};

// Filter and test.
var promise = subject.call(hexo, data);
return promise.then(function(result) {
result = result.replace(/\s/g, ''); // Perform a whitespace ..
var expected = data.replace(/\s/g, ''); // insensitive comparison.
console.assert(result === expected);
});
});

it('should do nothing if disabled.', function() {
// Configure.
var data = 'div { color: black }; span { color: white }';
var hexo = {
config: {
uncss: { enable: false }
},
route: hexoRoute
};

// Filter and test.
var result = subject.call(hexo, data);
console.assert(result === data);
});
});
2 changes: 2 additions & 0 deletions test/fixture.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html>
<div>Hello World</div>
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--check-leaks
--no-exit
--reporter spec
--timeout 100
--timeout 3000
--ui bdd

0 comments on commit bf9efcd

Please sign in to comment.