@@ -9,95 +9,139 @@ describe('util', function() {
99
1010 it ( 'text/plain should be categorized as doc' , function ( ) {
1111 var result = util . getContentType ( 'text/plain' ) ;
12- assert . deepEqual ( 'doc' , result ) ;
12+ assert . deepEqual ( result , 'doc' ) ;
1313 } ) ;
1414
1515 it ( 'text/html should be categorized as doc' , function ( ) {
1616 var result = util . getContentType ( 'text/html' ) ;
17- assert . deepEqual ( 'doc' , result ) ;
17+ assert . deepEqual ( result , 'doc' ) ;
1818 } ) ;
1919
2020 it ( 'text/html; charset=utf-8 with charset should be categorized as doc' , function ( ) {
2121 var result = util . getContentType ( 'text/html; charset=utf-8' ) ;
22- assert . deepEqual ( 'doc' , result ) ;
22+ assert . deepEqual ( result , 'doc' ) ;
2323 } ) ;
2424
2525 it ( 'text/javascript should be categorized as js' , function ( ) {
2626 var result = util . getContentType ( 'text/javascript' ) ;
27- assert . deepEqual ( 'js' , result ) ;
27+ assert . deepEqual ( result , 'js' ) ;
2828 } ) ;
2929
3030 it ( 'application/x-javascript; charset=utf-8 should be categorized as js' , function ( ) {
3131 var result = util . getContentType ( 'application/x-javascript; charset=utf-8' ) ;
32- assert . deepEqual ( 'js' , result ) ;
32+ assert . deepEqual ( result , 'js' ) ;
3333 } ) ;
3434
3535 it ( 'text/css should be categorized as css' , function ( ) {
3636 var result = util . getContentType ( 'text/css' ) ;
37- assert . deepEqual ( 'css' , result ) ;
37+ assert . deepEqual ( result , 'css' ) ;
3838 } ) ;
3939
4040 it ( 'image/png should be categorized as image' , function ( ) {
4141 var result = util . getContentType ( 'image/png' ) ;
42- assert . deepEqual ( 'image' , result ) ;
42+ assert . deepEqual ( result , 'image' ) ;
4343 } ) ;
4444
4545 it ( 'image/jpg should be categorized as image' , function ( ) {
4646 var result = util . getContentType ( 'image/jpg' ) ;
47- assert . deepEqual ( 'image' , result ) ;
47+ assert . deepEqual ( result , 'image' ) ;
4848 } ) ;
4949
5050 it ( 'image/gif should be categorized as image' , function ( ) {
5151 var result = util . getContentType ( 'image/gif' ) ;
52- assert . deepEqual ( 'image' , result ) ;
52+ assert . deepEqual ( result , 'image' ) ;
5353 } ) ;
5454
5555 it ( 'image/x-icon should be categorized as image' , function ( ) {
5656 var result = util . getContentType ( 'image/x-icon' ) ;
57- assert . deepEqual ( 'image' , result ) ;
57+ assert . deepEqual ( result , 'image' ) ;
5858 } ) ;
5959
6060 it ( 'image/svg+xml should be categorized as image' , function ( ) {
6161 var result = util . getContentType ( 'image/svg+xml' ) ;
62- assert . deepEqual ( 'image' , result ) ;
62+ assert . deepEqual ( result , 'image' ) ;
6363 } ) ;
6464
6565 it ( 'image/webp should be categorized as image' , function ( ) {
6666 var result = util . getContentType ( 'image/webp' ) ;
67- assert . deepEqual ( 'image' , result ) ;
67+ assert . deepEqual ( result , 'image' ) ;
6868 } ) ;
6969
7070
7171 it ( 'application/font-woff should be categorized as font' , function ( ) {
7272 var result = util . getContentType ( 'application/font-woff' ) ;
73- assert . deepEqual ( 'font' , result ) ;
73+ assert . deepEqual ( result , 'font' ) ;
7474 } ) ;
7575
7676 it ( 'application/font-sfnt should be categorized as font' , function ( ) {
7777 var result = util . getContentType ( 'application/font-sfnt' ) ;
78- assert . deepEqual ( 'font' , result ) ;
78+ assert . deepEqual ( result , 'font' ) ;
7979 } ) ;
8080
8181 it ( 'application/x-font-opentype should be categorized as font' , function ( ) {
8282 var result = util . getContentType ( 'application/x-font-opentype' ) ;
83- assert . deepEqual ( 'font' , result ) ;
83+ assert . deepEqual ( result , 'font' ) ;
8484 } ) ;
8585
8686 it ( 'application/x-font-ttf should be categorized as font' , function ( ) {
8787 var result = util . getContentType ( 'application/x-font-ttf' ) ;
88- assert . deepEqual ( 'font' , result ) ;
88+ assert . deepEqual ( result , 'font' ) ;
8989 } ) ;
9090
9191 it ( 'application/x-shockwave-flash should be categorized as flash' , function ( ) {
9292 var result = util . getContentType ( 'application/x-shockwave-flash' ) ;
93- assert . deepEqual ( 'flash' , result ) ;
93+ assert . deepEqual ( result , 'flash' ) ;
9494 } ) ;
9595
9696 it ( 'application/my-own-type should be categorized as unkown' , function ( ) {
9797 var result = util . getContentType ( 'application/my-own-type' ) ;
98- assert . deepEqual ( 'unknown' , result ) ;
98+ assert . deepEqual ( result , 'unknown' ) ;
9999 } ) ;
100100
101101 } ) ;
102102
103+ describe ( '#getGraphiteURLKey' , function ( ) {
104+
105+ it ( 'A domain without slash should return protocol.www_domain_com ' , function ( ) {
106+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io' ) ;
107+ assert . deepEqual ( result , 'http.www_sitespeed_io.slash' ) ;
108+ } ) ;
109+
110+ it ( 'A https domain should start with https in the keys' , function ( ) {
111+ var result = util . getGraphiteURLKey ( 'https://www.sitespeed.io' ) ;
112+ assert . deepEqual ( result , 'https.www_sitespeed_io.slash' ) ;
113+ } ) ;
114+
115+ it ( 'A domain with a slash should return protocol.www_domain_com' , function ( ) {
116+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io/' ) ;
117+ assert . deepEqual ( result , 'http.www_sitespeed_io.slash' ) ;
118+ } ) ;
119+
120+ it ( 'Many subdomains should keep all domains in the domain part of the key' , function ( ) {
121+ var result = util . getGraphiteURLKey ( 'http://so.many.subdomains.sitespeed.io/hepp' ) ;
122+ assert . deepEqual ( result , 'http.so_many_subdomains_sitespeed_io._hepp' ) ;
123+ } ) ;
124+
125+ it ( 'The path should be separated from the domain (ending without a slash)' , function ( ) {
126+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io/too/deep' ) ;
127+ assert . deepEqual ( result , 'http.www_sitespeed_io._too_deep' ) ;
128+ } ) ;
129+
130+ it ( 'The path should be separated from the domain (ends with a slash)' , function ( ) {
131+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io/too/deep/' ) ;
132+ assert . deepEqual ( result , 'http.www_sitespeed_io._too_deep_' ) ;
133+ } ) ;
134+
135+ it ( 'The path and files should be separated from the domain (when a file is in a folder)' , function ( ) {
136+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io/js/my.js' ) ;
137+ assert . deepEqual ( result , 'http.www_sitespeed_io._js_my_js' ) ;
138+ } ) ;
139+
140+ it ( 'The path and files should be separated from the domain (when the file is in root)' , function ( ) {
141+ var result = util . getGraphiteURLKey ( 'http://www.sitespeed.io/image.gif' ) ;
142+ assert . deepEqual ( result , 'http.www_sitespeed_io._image_gif' ) ;
143+ } ) ;
144+
145+
146+ } ) ;
103147} ) ;
0 commit comments