From bf9efcd4eeed40e0605b8cf440b42e131866692c Mon Sep 17 00:00:00 2001 From: vseventer Date: Mon, 20 Jul 2015 15:45:20 +1000 Subject: [PATCH] Added tests. --- CHANGELOG.md | 5 +++- index.js | 2 +- package.json | 2 +- test/filter.test.js | 73 ++++++++++++++++++++++++++++++++++++++++++--- test/fixture.html | 2 ++ test/mocha.opts | 2 +- 6 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 test/fixture.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f9e74..a97599f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. \ No newline at end of file diff --git a/index.js b/index.js index e203154..cceb184 100644 --- a/index.js +++ b/index.js @@ -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, diff --git a/package.json b/package.json index c203c42..ddbd4c3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/filter.test.js b/test/filter.test.js index 2569ef8..c215c97 100644 --- a/test/filter.test.js +++ b/test/filter.test.js @@ -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); + }); }); \ No newline at end of file diff --git a/test/fixture.html b/test/fixture.html new file mode 100644 index 0000000..226085d --- /dev/null +++ b/test/fixture.html @@ -0,0 +1,2 @@ + +
Hello World
\ No newline at end of file diff --git a/test/mocha.opts b/test/mocha.opts index 2b7a2da..6d35156 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,5 +1,5 @@ --check-leaks --no-exit --reporter spec ---timeout 100 +--timeout 3000 --ui bdd \ No newline at end of file