Skip to content
This repository has been archived by the owner on Dec 2, 2018. It is now read-only.

Commit

Permalink
More tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-eb committed Aug 3, 2015
1 parent fb7392c commit fdfae00
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 85 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ can be mixed and matched:
var gulp = require('gulp');
var uncss = require('gulp-uncss');

gulp.task('default', function() {
gulp.task('default', function () {
return gulp.src('site.css')
.pipe(uncss({
html: ['index.html', 'posts/**/*.html', 'http://example.com']
Expand All @@ -39,16 +39,16 @@ var gulp = require('gulp');
var uncss = require('gulp-uncss');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var csso = require('gulp-csso');
var nano = require('gulp-cssnano');

gulp.task('default', function() {
gulp.task('default', function () {
return gulp.src('styles/**/*.scss')
.pipe(sass())
.pipe(concat('main.css'))
.pipe(uncss({
html: ['index.html', 'posts/**/*.html', 'http://example.com']
}))
.pipe(csso())
.pipe(nano())
.pipe(gulp.dest('./out'));
});
```
Expand Down
17 changes: 0 additions & 17 deletions gulpfile.js

This file was deleted.

18 changes: 5 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
"homepage": "https://github.com/ben-eb/gulp-uncss",
"author": {
"name": "Ben Briggs",
"email": "therealbenbriggs@hotmail.com",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git://github.com/ben-eb/gulp-uncss.git"
"test": "tape test.js | tap-spec"
},
"repository": "ben-eb/gulp-uncss",
"keywords": [
"unused",
"css",
Expand All @@ -27,13 +24,8 @@
"uncss": "^0.12.1"
},
"devDependencies": {
"chai": "~3.0.0",
"event-stream": "~3.3.1",
"gulp": "~3.9.0",
"gulp-jshint": "~1.11.2",
"jshint-stylish": "~2.0.1",
"mocha": "~2.2.5",
"mocha-silent-reporter": "^1.0.0"
"tap-spec": "^4.0.2",
"tape": "^4.0.1"
},
"main": "index.js"
}
96 changes: 45 additions & 51 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,63 @@
/* global describe, it */

'use strict';

var expect = require('chai').expect,
var test = require('tape'),
gutil = require('gulp-util'),
uncss = require('./'),
Stream = require('stream'),
es = require('event-stream'),

html = '<html><body><h1>hello</h1></body></html>',
css = 'h2 { color:blue; } h1 { color:red }',
output = 'h1 {\n color: red;\n}\n';

describe('gulp-uncss', function() {
it('should remove unused css selectors', function(cb) {
var stream = uncss({
html: html
});
stream.on('data', function(data) {
expect(String(data.contents)).to.equal(output);
cb();
});
stream.write(new gutil.File({
contents: new Buffer(css)
}));
function fixture (contents) {
return new gutil.File({
contents: contents,
cwd: __dirname,
base: __dirname,
path: __dirname + '/fixture.css'
});
}

it('in stream mode should throw an error', function(cb) {
var stream = uncss({
html: html
});

var fakeFile = new gutil.File({
contents: new Stream()
});
test('should remove unused css selectors', function (t) {
t.plan(1);

var doWrite = function() {
stream.write(fakeFile);
fakeFile.contents.write(css);
fakeFile.contents.end();
};
var stream = uncss({html: html});

expect(doWrite).to.throw(/Streaming not supported/);
cb();
stream.on('data', function (data) {
t.equal(String(data.contents), output);
});

it('should let null files pass through', function(cb) {
var n = 0,
stream = uncss({
html: html
});

stream.pipe(es.through(function(file) {
expect(file.path).to.equal('null.md');
expect(file.contents).to.equal(null);
n++;
}, function() {
expect(n).to.equal(1);
cb();
}));

stream.write(new gutil.File({
path: 'null.md',
contents: null
}));
stream.end();
var file = fixture(new Buffer(css));

stream.write(file);
});

test('should throw an error in stream mode', function (t) {
t.plan(1);

var stream = uncss({html: html});

var file = fixture(new Stream());

var write = function () {
stream.write(file);
file.contents.write(css);
file.contents.end();
};

t.throws(write, 'should not support streaming contents');
});

test('should let null files pass through', function (t) {
t.plan(1);

var stream = uncss({html: html});

stream.on('data', function (data) {
t.equal(data.contents, null, 'should not transform null in any way');
});

var file = fixture(null);

stream.write(file);
});

0 comments on commit fdfae00

Please sign in to comment.