1 |
|
2 |
|
3 | 'use strict';
|
4 | require('should');
|
5 | var path = require('path'),
|
6 | fs = require('fs'),
|
7 | Stringify = require('../index');
|
8 |
|
9 | function requireHtml(filename) {
|
10 | return fs.readFileSync(path.join(path.dirname('.'), 'test', filename), 'utf8');
|
11 | }
|
12 |
|
13 | describe('the "minify" function', function () {
|
14 | before(function () {
|
15 | this.givenHtml = requireHtml('minify.given.html');
|
16 | this.expectedHtml = requireHtml('minify.expected.html').replace(/\r?\n|\r/, '');
|
17 | });
|
18 |
|
19 | it('should return a function', function () {
|
20 | Stringify.minify.should.be.a.Function;
|
21 | });
|
22 |
|
23 | it('should have default minifier extensions', function () {
|
24 | var extensions = Stringify.MINIFY_TRANSFORM_OPTIONS;
|
25 | extensions.should.be.an.Object;
|
26 | extensions.includeExtensions.should.be.an.Array;
|
27 | extensions.includeExtensions.length.should.be.exactly(5);
|
28 | });
|
29 |
|
30 | it('should minify html content', function () {
|
31 | Stringify.minify('some.html', this.givenHtml, {
|
32 | minify: true
|
33 | }).should.be.exactly(this.expectedHtml);
|
34 | });
|
35 |
|
36 | it('should not minify html content when minification is not requested', function () {
|
37 | Stringify.minify('some.html', this.givenHtml, {
|
38 | minify: false
|
39 | }).should.be.exactly(this.givenHtml);
|
40 | });
|
41 |
|
42 | it('should not minify html content when extension is excluded', function () {
|
43 | Stringify.minify('some.html', this.givenHtml, {
|
44 | minify: true,
|
45 | minifyAppliesTo: { includeExtensions: ['.foo'] }
|
46 | }).should.be.exactly(this.givenHtml);
|
47 | });
|
48 |
|
49 | it('should minify custom content when extension is included', function () {
|
50 | Stringify.minify('some.ant', this.givenHtml, {
|
51 | minify: true,
|
52 | minifyAppliesTo: { includeExtensions: ['.ant'] }
|
53 | }).should.be.exactly(this.expectedHtml);
|
54 | });
|
55 |
|
56 | it('should not minify custom content when extension is excluded', function () {
|
57 | Stringify.minify('some.soap', this.givenHtml, {
|
58 | minify: true,
|
59 | minifyAppliesTo: { includeExtensions: ['.xml'] }
|
60 | }).should.be.exactly(this.givenHtml);
|
61 | });
|
62 | });
|