1 | var gulp = require('gulp')
|
2 | , expect = require('chai').expect
|
3 | , minifyHTML = require('../')
|
4 | , Minimize = require('minimize')
|
5 | , through = require('through2')
|
6 | , fs = require('fs');
|
7 |
|
8 | describe('gulp-minify-html', function() {
|
9 | var filename = __dirname + '/fixture/index.html';
|
10 | it('should minify my files when given options', function(done) {
|
11 | gulp.src(filename)
|
12 | .pipe(minifyHTML())
|
13 | .pipe(through.obj(function(file, encoding, callback){
|
14 | var source = fs.readFileSync(filename)
|
15 | , minimize = new Minimize();
|
16 |
|
17 | minimize.parse(source.toString(), function (err, data) {
|
18 | if (err) throw err;
|
19 |
|
20 | expect(data).to.be.equal(file.contents.toString());
|
21 | done();
|
22 | });
|
23 | }));
|
24 | });
|
25 |
|
26 | it('should minify my files when not given options', function(done) {
|
27 | var opt = {comments:true,spare:true};
|
28 | gulp.src(filename)
|
29 | .pipe(minifyHTML(opt))
|
30 | .pipe(through.obj(function(file, encoding, callback){
|
31 | var source = fs.readFileSync(filename)
|
32 | , minimize = new Minimize(opt);
|
33 |
|
34 | minimize.parse(source.toString(), function (err, data) {
|
35 | if (err) throw err;
|
36 |
|
37 | expect(data).to.be.equal(file.contents.toString());
|
38 | done();
|
39 | });
|
40 | }));
|
41 | });
|
42 |
|
43 | it('should return file.contents as a buffer', function(done) {
|
44 | gulp.src(filename)
|
45 | .pipe(minifyHTML())
|
46 | .pipe(through.obj(function(file, encoding, callback) {
|
47 | expect(file.contents).to.be.an.instanceof(Buffer);
|
48 | done();
|
49 | }));
|
50 | });
|
51 |
|
52 | it('should do nothing when given nothing', function(done) {
|
53 | gulp.src('')
|
54 | .pipe(minifyHTML())
|
55 | .pipe(through.obj(function(file, encoding, callback) {
|
56 | done();
|
57 | }));
|
58 | });
|
59 | }); |
\ | No newline at end of file |