UNPKG

2.79 kBJavaScriptView Raw
1/*
2 * gulp-prettify
3 * https://github.com/jonschlinkert/gulp-prettify
4 *
5 * Copyright (c) 2013 Jon Schlinkert
6 * Licensed under the MIT license.
7 */
8
9/* globals describe, it */
10
11'use strict';
12
13var fs = require('fs');
14var path = require('path');
15var gutil = require('gulp-util');
16var expect = require('chai').expect;
17var prettify = require('../');
18
19var fixtureFile = fs.readFileSync(path.join(__dirname, './fixtures/index.html'));
20
21
22describe('prettify HTML', function () {
23 describe('gulp-prettify', function () {
24
25 it('should prettify HTML files', function (done) {
26
27 var prettyStream = prettify();
28 var fakeFile = new gutil.File({
29 base: 'test/fixtures',
30 cwd: 'test/',
31 path: 'test/fixtures/index.html',
32 contents: fixtureFile
33 });
34 prettyStream.once('data', function(newFile){
35 expect(String(newFile.contents)).to.equal(String(fs.readFileSync(path.join(__dirname, './expected/normal.html'))));
36 done();
37 });
38 prettyStream.write(fakeFile);
39 });
40
41 it('should indent inner HTML', function (done) {
42
43 var prettyStream = prettify({indent_inner_html: true});
44 var fakeFile = new gutil.File({
45 base: 'test/fixtures',
46 cwd: 'test/',
47 path: 'test/fixtures/index.html',
48 contents: fixtureFile
49 });
50 prettyStream.once('data', function(newFile){
51 expect(String(newFile.contents)).to.equal(String(fs.readFileSync(path.join(__dirname, './expected/indent.html'))));
52 done();
53 });
54 prettyStream.write(fakeFile);
55 });
56
57 it('should indent a specified tab size', function (done) {
58
59 var prettyStream = prettify({indent_size: 2});
60 var fakeFile = new gutil.File({
61 base: 'test/fixtures',
62 cwd: 'test/',
63 path: 'test/fixtures/index.html',
64 contents: fixtureFile
65 });
66 prettyStream.once('data', function(newFile){
67 expect(String(newFile.contents)).to.equal(String(fs.readFileSync(path.join(__dirname, './expected/indent_tab_2.html'))));
68 done();
69 });
70 prettyStream.write(fakeFile);
71 });
72
73 it('should not prettify pre or code tags', function (done) {
74
75 var prettyStream = prettify({unformatted: ['pre', 'code'] });
76 var fakeFile = new gutil.File({
77 base: 'test/fixtures',
78 cwd: 'test/',
79 path: 'test/fixtures/index.html',
80 contents: fixtureFile
81 });
82 prettyStream.once('data', function(newFile){
83 expect(String(newFile.contents)).to.equal(String(fs.readFileSync(path.join(__dirname, './expected/unformatted_pre.html'))));
84 done();
85 });
86 prettyStream.write(fakeFile);
87 });
88 });
89});
\No newline at end of file