1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var errors_1 = require("./errors");
|
4 | var helpers = require("./helpers");
|
5 | var originalEnv = null;
|
6 | describe('helpers', function () {
|
7 | beforeEach(function () {
|
8 | originalEnv = process.env;
|
9 | process.env = {};
|
10 | });
|
11 | afterEach(function () {
|
12 | process.env = originalEnv;
|
13 | });
|
14 | describe('getIntPropertyValue', function () {
|
15 | it('should return an int', function () {
|
16 |
|
17 | var propertyName = 'test';
|
18 | var propertyValue = '3000';
|
19 | process.env[propertyName] = propertyValue;
|
20 |
|
21 | var result = helpers.getIntPropertyValue(propertyName);
|
22 |
|
23 | expect(result).toEqual(3000);
|
24 | });
|
25 | it('should round to an int', function () {
|
26 |
|
27 | var propertyName = 'test';
|
28 | var propertyValue = '3000.03';
|
29 | process.env[propertyName] = propertyValue;
|
30 |
|
31 | var result = helpers.getIntPropertyValue(propertyName);
|
32 |
|
33 | expect(result).toEqual(3000);
|
34 | });
|
35 | it('should round to a NaN', function () {
|
36 |
|
37 | var propertyName = 'test';
|
38 | var propertyValue = 'tacos';
|
39 | process.env[propertyName] = propertyValue;
|
40 |
|
41 | var result = helpers.getIntPropertyValue(propertyName);
|
42 |
|
43 | expect(result).toEqual(NaN);
|
44 | });
|
45 | });
|
46 | describe('getBooleanPropertyValue', function () {
|
47 | beforeEach(function () {
|
48 | originalEnv = process.env;
|
49 | process.env = {};
|
50 | });
|
51 | afterEach(function () {
|
52 | process.env = originalEnv;
|
53 | });
|
54 | it('should return true when value is "true"', function () {
|
55 |
|
56 | var propertyName = 'test';
|
57 | var propertyValue = 'true';
|
58 | process.env[propertyName] = propertyValue;
|
59 |
|
60 | var result = helpers.getBooleanPropertyValue(propertyName);
|
61 |
|
62 | expect(result).toEqual(true);
|
63 | });
|
64 | it('should return false when value is undefined/null', function () {
|
65 |
|
66 | var propertyName = 'test';
|
67 |
|
68 | var result = helpers.getBooleanPropertyValue(propertyName);
|
69 |
|
70 | expect(result).toEqual(false);
|
71 | });
|
72 | it('should return false when value is not "true"', function () {
|
73 |
|
74 | var propertyName = 'test';
|
75 | var propertyValue = 'taco';
|
76 | process.env[propertyName] = propertyValue;
|
77 |
|
78 | var result = helpers.getBooleanPropertyValue(propertyName);
|
79 |
|
80 | expect(result).toEqual(false);
|
81 | });
|
82 | });
|
83 | describe('processStatsImpl', function () {
|
84 | it('should convert object graph to known module map', function () {
|
85 |
|
86 | var moduleOne = '/Users/noone/myModuleOne.js';
|
87 | var moduleTwo = '/Users/noone/myModuleTwo.js';
|
88 | var moduleThree = '/Users/noone/myModuleThree.js';
|
89 | var moduleFour = '/Users/noone/myModuleFour.js';
|
90 | var objectGraph = {
|
91 | modules: [
|
92 | {
|
93 | identifier: moduleOne,
|
94 | reasons: [
|
95 | {
|
96 | moduleIdentifier: moduleTwo
|
97 | },
|
98 | {
|
99 | moduleIdentifier: moduleThree
|
100 | }
|
101 | ]
|
102 | },
|
103 | {
|
104 | identifier: moduleTwo,
|
105 | reasons: [
|
106 | {
|
107 | moduleIdentifier: moduleThree
|
108 | }
|
109 | ]
|
110 | },
|
111 | {
|
112 | identifier: moduleThree,
|
113 | reasons: [
|
114 | {
|
115 | moduleIdentifier: moduleOne
|
116 | }
|
117 | ]
|
118 | },
|
119 | {
|
120 | identifier: moduleFour,
|
121 | reasons: []
|
122 | }
|
123 | ]
|
124 | };
|
125 |
|
126 | var result = helpers.processStatsImpl(objectGraph);
|
127 |
|
128 | var setOne = result.get(moduleOne);
|
129 | expect(setOne.has(moduleTwo)).toBeTruthy();
|
130 | expect(setOne.has(moduleThree)).toBeTruthy();
|
131 | var setTwo = result.get(moduleTwo);
|
132 | expect(setTwo.has(moduleThree)).toBeTruthy();
|
133 | var setThree = result.get(moduleThree);
|
134 | expect(setThree.has(moduleOne)).toBeTruthy();
|
135 | var setFour = result.get(moduleFour);
|
136 | expect(setFour.size).toEqual(0);
|
137 | });
|
138 | });
|
139 | describe('ensureSuffix', function () {
|
140 | it('should not include the suffix of a string that already has the suffix', function () {
|
141 | expect(helpers.ensureSuffix('dan dan the sunshine man', ' man')).toEqual('dan dan the sunshine man');
|
142 | });
|
143 | it('should ensure the suffix of a string without the suffix', function () {
|
144 | expect(helpers.ensureSuffix('dan dan the sunshine', ' man')).toEqual('dan dan the sunshine man');
|
145 | });
|
146 | });
|
147 | describe('removeSuffix', function () {
|
148 | it('should remove the suffix of a string that has the suffix', function () {
|
149 | expect(helpers.removeSuffix('dan dan the sunshine man', ' man')).toEqual('dan dan the sunshine');
|
150 | });
|
151 | it('should do nothing if the string does not have the suffix', function () {
|
152 | expect(helpers.removeSuffix('dan dan the sunshine man', ' woman')).toEqual('dan dan the sunshine man');
|
153 | });
|
154 | });
|
155 | describe('replaceAll', function () {
|
156 | it('should replace a variable', function () {
|
157 | expect(helpers.replaceAll('hello $VAR world', '$VAR', 'my')).toEqual('hello my world');
|
158 | });
|
159 | it('should replace a variable with newlines', function () {
|
160 | expect(helpers.replaceAll('hello\n $VARMORETEXT\n world', '$VAR', 'NO')).toEqual('hello\n NOMORETEXT\n world');
|
161 | });
|
162 | it('should replace a variable and handle undefined', function () {
|
163 | expect(helpers.replaceAll('hello $VAR world', '$VAR', undefined)).toEqual('hello world');
|
164 | });
|
165 | });
|
166 | describe('buildErrorToJson', function () {
|
167 | it('should return a pojo', function () {
|
168 | var buildError = new errors_1.BuildError('message1');
|
169 | buildError.name = 'name1';
|
170 | buildError.stack = 'stack1';
|
171 | buildError.isFatal = true;
|
172 | buildError.hasBeenLogged = false;
|
173 | var object = helpers.buildErrorToJson(buildError);
|
174 | expect(object.message).toEqual('message1');
|
175 | expect(object.name).toEqual(buildError.name);
|
176 | expect(object.stack).toEqual(buildError.stack);
|
177 | expect(object.isFatal).toEqual(buildError.isFatal);
|
178 | expect(object.hasBeenLogged).toEqual(buildError.hasBeenLogged);
|
179 | });
|
180 | });
|
181 | describe('upperCaseFirst', function () {
|
182 | it('should capitalize a one character string', function () {
|
183 | var result = helpers.upperCaseFirst('t');
|
184 | expect(result).toEqual('T');
|
185 | });
|
186 | it('should capitalize the first character of string', function () {
|
187 | var result = helpers.upperCaseFirst('taco');
|
188 | expect(result).toEqual('Taco');
|
189 | });
|
190 | });
|
191 | describe('removeCaseFromString', function () {
|
192 | var map = new Map();
|
193 | map.set('test', 'test');
|
194 | map.set('TEST', 'test');
|
195 | map.set('testString', 'test string');
|
196 | map.set('testString123', 'test string123');
|
197 | map.set('testString_1_2_3', 'test string 1 2 3');
|
198 | map.set('x_256', 'x 256');
|
199 | map.set('anHTMLTag', 'an html tag');
|
200 | map.set('ID123String', 'id123 string');
|
201 | map.set('Id123String', 'id123 string');
|
202 | map.set('foo bar123', 'foo bar123');
|
203 | map.set('a1bStar', 'a1b star');
|
204 | map.set('CONSTANT_CASE', 'constant case');
|
205 | map.set('CONST123_FOO', 'const123 foo');
|
206 | map.set('FOO_bar', 'foo bar');
|
207 | map.set('dot.case', 'dot case');
|
208 | map.set('path/case', 'path case');
|
209 | map.set('snake_case', 'snake case');
|
210 | map.set('snake_case123', 'snake case123');
|
211 | map.set('snake_case_123', 'snake case 123');
|
212 | map.set('"quotes"', 'quotes');
|
213 | map.set('version 0.45.0', 'version 0 45 0');
|
214 | map.set('version 0..78..9', 'version 0 78 9');
|
215 | map.set('version 4_99/4', 'version 4 99 4');
|
216 | map.set('amazon s3 data', 'amazon s3 data');
|
217 | map.set('foo_13_bar', 'foo 13 bar');
|
218 | map.forEach(function (value, key) {
|
219 | var result = helpers.removeCaseFromString(key);
|
220 | expect(result).toEqual(value);
|
221 | });
|
222 | });
|
223 | describe('sentenceCase', function () {
|
224 | it('should lower case a single word', function () {
|
225 | var resultOne = helpers.sentenceCase('test');
|
226 | var resultTwo = helpers.sentenceCase('TEST');
|
227 | expect(resultOne).toEqual('Test');
|
228 | expect(resultTwo).toEqual('Test');
|
229 | });
|
230 | it('should sentence case regular sentence cased strings', function () {
|
231 | var resultOne = helpers.sentenceCase('test string');
|
232 | var resultTwo = helpers.sentenceCase('Test String');
|
233 | expect(resultOne).toEqual('Test string');
|
234 | expect(resultTwo).toEqual('Test string');
|
235 | });
|
236 | it('should sentence case non-alphanumeric separators', function () {
|
237 | var resultOne = helpers.sentenceCase('dot.case');
|
238 | var resultTwo = helpers.sentenceCase('path/case');
|
239 | expect(resultOne).toEqual('Dot case');
|
240 | expect(resultTwo).toEqual('Path case');
|
241 | });
|
242 | });
|
243 | describe('camelCase', function () {
|
244 | it('should lower case a single word', function () {
|
245 | var resultOne = helpers.camelCase('test');
|
246 | var resultTwo = helpers.camelCase('TEST');
|
247 | expect(resultOne).toEqual('test');
|
248 | expect(resultTwo).toEqual('test');
|
249 | });
|
250 | it('should camel case regular sentence cased strings', function () {
|
251 | expect(helpers.camelCase('test string')).toEqual('testString');
|
252 | expect(helpers.camelCase('Test String')).toEqual('testString');
|
253 | });
|
254 | it('should camel case non-alphanumeric separators', function () {
|
255 | expect(helpers.camelCase('dot.case')).toEqual('dotCase');
|
256 | expect(helpers.camelCase('path/case')).toEqual('pathCase');
|
257 | });
|
258 | it('should underscore periods inside numbers', function () {
|
259 | expect(helpers.camelCase('version 1.2.10')).toEqual('version_1_2_10');
|
260 | expect(helpers.camelCase('version 1.21.0')).toEqual('version_1_21_0');
|
261 | });
|
262 | it('should camel case pascal cased strings', function () {
|
263 | expect(helpers.camelCase('TestString')).toEqual('testString');
|
264 | });
|
265 | it('should camel case non-latin strings', function () {
|
266 | expect(helpers.camelCase('simple éxample')).toEqual('simpleÉxample');
|
267 | });
|
268 | });
|
269 | describe('paramCase', function () {
|
270 | it('should param case a single word', function () {
|
271 | expect(helpers.paramCase('test')).toEqual('test');
|
272 | expect(helpers.paramCase('TEST')).toEqual('test');
|
273 | });
|
274 | it('should param case regular sentence cased strings', function () {
|
275 | expect(helpers.paramCase('test string')).toEqual('test-string');
|
276 | expect(helpers.paramCase('Test String')).toEqual('test-string');
|
277 | });
|
278 | it('should param case non-alphanumeric separators', function () {
|
279 | expect(helpers.paramCase('dot.case')).toEqual('dot-case');
|
280 | expect(helpers.paramCase('path/case')).toEqual('path-case');
|
281 | });
|
282 | it('should param case param cased strings', function () {
|
283 | expect(helpers.paramCase('TestString')).toEqual('test-string');
|
284 | expect(helpers.paramCase('testString1_2_3')).toEqual('test-string1-2-3');
|
285 | expect(helpers.paramCase('testString_1_2_3')).toEqual('test-string-1-2-3');
|
286 | });
|
287 | it('should param case non-latin strings', function () {
|
288 | expect(helpers.paramCase('My Entrée')).toEqual('my-entrée');
|
289 | });
|
290 | });
|
291 | describe('pascalCase', function () {
|
292 | it('should pascal case a single word', function () {
|
293 | expect(helpers.pascalCase('test')).toEqual('Test');
|
294 | expect(helpers.pascalCase('TEST')).toEqual('Test');
|
295 | });
|
296 | it('should pascal case regular sentence cased strings', function () {
|
297 | expect(helpers.pascalCase('test string')).toEqual('TestString');
|
298 | expect(helpers.pascalCase('Test String')).toEqual('TestString');
|
299 | });
|
300 | it('should pascal case non-alphanumeric separators', function () {
|
301 | expect(helpers.pascalCase('dot.case')).toEqual('DotCase');
|
302 | expect(helpers.pascalCase('path/case')).toEqual('PathCase');
|
303 | });
|
304 | it('should pascal case pascal cased strings', function () {
|
305 | expect(helpers.pascalCase('TestString')).toEqual('TestString');
|
306 | });
|
307 | });
|
308 | describe('snakeCase', function () {
|
309 | it('should convert the phrase to use underscores', function () {
|
310 | expect(helpers.snakeCase('taco bell')).toEqual('taco_bell');
|
311 | });
|
312 | });
|
313 | describe('constantCase', function () {
|
314 | it('should capitalize and separate words by underscore', function () {
|
315 | expect(helpers.constantCase('taco bell')).toEqual('TACO_BELL');
|
316 | });
|
317 | it('should convert camel case to correct case', function () {
|
318 | expect(helpers.constantCase('TacoBell')).toEqual('TACO_BELL');
|
319 | });
|
320 | });
|
321 | });
|