UNPKG

4.55 kBJavaScriptView Raw
1/* jshint expr: true */
2/* global describe: false, it: false, before: false */
3'use strict';
4require('should');
5var Stringify = require('../index');
6
7describe('the "getMinifyOptions" function', function () {
8
9 function assertObjectInReturnedOptions () {
10 it('should have returned an object', function () {
11 this.returned_options.should.be.an.Object;
12 });
13 }
14
15 function assertCorrectOptionsReturned () {
16 it('should have returned the correct extensions', function () {
17 this.returned_options.should.eql(this.correct_test_options);
18 });
19 }
20
21 describe('when passed no options argument', function () {
22 before(function () {
23 this.correct_test_options = { requested: false };
24 this.returned_options = Stringify.getMinifyOptions();
25 });
26
27 assertObjectInReturnedOptions();
28 assertCorrectOptionsReturned();
29 });
30
31 describe('when passed empty options argument', function () {
32 before(function () {
33 this.correct_test_options = { requested: false };
34 this.returned_options = Stringify.getMinifyOptions({});
35 });
36
37 assertObjectInReturnedOptions();
38 assertCorrectOptionsReturned();
39 });
40
41 describe('when passed options argument with minify set to false', function () {
42 before(function () {
43 this.correct_test_options = { requested: false };
44 this.returned_options = Stringify.getMinifyOptions({ minify: false });
45 });
46
47 assertObjectInReturnedOptions();
48 assertCorrectOptionsReturned();
49 });
50
51 describe('when passed options argument with minify set to true', function () {
52 before(function () {
53 this.correct_test_options = {
54 requested: true,
55 options: Stringify.DEFAULT_MINIFY_OPTIONS
56 };
57
58 this.returned_options = Stringify.getMinifyOptions({ minify: true });
59 });
60
61 assertObjectInReturnedOptions();
62 assertCorrectOptionsReturned();
63 });
64
65 describe('when passed options argument with minifyOptions set', function () {
66 before(function () {
67 var minifyOptions = { grape: 'fruit' };
68
69 this.correct_test_options = {
70 requested: true,
71 options: minifyOptions
72 };
73
74 this.returned_options = Stringify.getMinifyOptions({
75 minify: true,
76 minifyOptions: minifyOptions
77 });
78 });
79
80 assertObjectInReturnedOptions();
81 assertCorrectOptionsReturned();
82 });
83
84 describe('when passed options argument with minifier.options set', function () {
85 before(function () {
86 var minifierOptions = { sweet: 'tooth' };
87
88 this.correct_test_options = {
89 requested: true,
90 options: minifierOptions
91 };
92
93 this.returned_options = Stringify.getMinifyOptions({
94 minify: true,
95 minifier: { options: minifierOptions }
96 });
97 });
98
99 assertObjectInReturnedOptions();
100 assertCorrectOptionsReturned();
101 });
102
103 describe('when passed options argument with minifyAppliesTo set', function () {
104 before(function () {
105 var minifyAppliesTo = { includeExtensions: ['.car', '.vs', '.train'] };
106
107 this.correct_test_options = {
108 requested: true,
109 config: { appliesTo: minifyAppliesTo },
110 options: Stringify.DEFAULT_MINIFY_OPTIONS
111 };
112
113 this.returned_options = Stringify.getMinifyOptions({
114 minify: true,
115 minifyAppliesTo: minifyAppliesTo
116 });
117 });
118
119 assertObjectInReturnedOptions();
120 assertCorrectOptionsReturned();
121 });
122
123 describe('when passed options argument with minifier.extensions set', function () {
124 before(function () {
125 var extensions = ['.top', '.hat'];
126
127 this.correct_test_options = {
128 requested: true,
129 config: { appliesTo: { includeExtensions: extensions } },
130 options: Stringify.DEFAULT_MINIFY_OPTIONS
131 };
132
133 this.returned_options = Stringify.getMinifyOptions({
134 minify: true,
135 minifier: { extensions : extensions }
136 });
137 });
138
139 assertObjectInReturnedOptions();
140 assertCorrectOptionsReturned();
141 });
142
143 describe('when passed options argument with minifier.extensions._ set', function () {
144 before(function () {
145 var extensions = ['.box', '.glove'];
146
147 this.correct_test_options = {
148 requested: true,
149 config: { appliesTo: { includeExtensions: extensions } },
150 options: Stringify.DEFAULT_MINIFY_OPTIONS
151 };
152
153 this.returned_options = Stringify.getMinifyOptions({
154 minify: true,
155 minifier: { extensions : { _: extensions } }
156 });
157 });
158
159 assertObjectInReturnedOptions();
160 assertCorrectOptionsReturned();
161 });
162});