This repository has been archived by the owner on Dec 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |