1- /* eslint-disable */
2- const should = require ( 'should' ) ;
3- const url = require ( 'url' ) ;
1+ 'use strict' ;
2+
3+ /* eslint-env mocha */
4+
5+ require ( 'should' ) ;
6+ const { URL } = require ( 'url' ) ;
7+ const gravatar = require ( '..' ) ;
48const nixt = require ( 'nixt' ) ;
5- const gravatar = require ( '../lib/gravatar' ) ;
9+ const normalizeUrl = require ( 'normalize-url' ) ;
10+
11+ const parseUrl = url => new URL ( normalizeUrl ( url ) ) ;
612
713describe ( 'gravatar' , function ( ) {
8- const baseNoProtocolURL = '//www. gravatar.com/avatar/' ;
9- const baseUnsecureURL = 'http://www. gravatar.com/avatar/' ;
10- const baseSecureURL = 'https://s. gravatar.com/avatar/' ;
11- const profileURL = 'http://www. gravatar.com/' ;
12- const profileSecureURL = 'https://secure. gravatar.com/' ;
14+ const baseNoProtocolURL = '//gravatar.com/avatar/' ;
15+ const baseUnsecureURL = 'http://gravatar.com/avatar/' ;
16+ const baseSecureURL = 'https://gravatar.com/avatar/' ;
17+ const profileURL = 'http://gravatar.com/' ;
18+ const profileSecureURL = 'https://gravatar.com/' ;
1319 const unspecifiedHash = 'd415f0e30c471dfdd9bc4f827329ef48' ;
1420
1521 it ( 'should gererate correct uri given an email' , function ( ) {
@@ -30,11 +36,11 @@ describe('gravatar', function () {
3036
3137 it ( 'should generate uri with user passed parameters' , function ( ) {
3238 const gravatarURL = gravatar . url ( 'emerleite@gmail.com' , { s : '200' , f : 'y' , r : 'g' , d : '404' } ) ;
33- const queryString = url . parse ( gravatarURL , true ) . query ;
34- queryString . s . should . equal ( '200' ) ;
35- queryString . f . should . equal ( 'y' ) ;
36- queryString . r . should . equal ( 'g' ) ;
37- queryString . d . should . equal ( '404' ) ;
39+ const { searchParams } = parseUrl ( gravatarURL ) ;
40+ searchParams . get ( 's' ) . should . equal ( '200' ) ;
41+ searchParams . get ( 'f' ) . should . equal ( 'y' ) ;
42+ searchParams . get ( 'r' ) . should . equal ( 'g' ) ;
43+ searchParams . get ( 'd' ) . should . equal ( '404' ) ;
3844 } ) ;
3945
4046 it ( 'should force http protocol on gravatar uri generation' , function ( ) {
@@ -48,9 +54,11 @@ describe('gravatar', function () {
4854 } ) ;
4955
5056 it ( 'should handle falsey values for the email property' , function ( ) {
57+ /* eslint-disable no-unused-expressions */
5158 gravatar . url ( null ) . should . be . ok ;
5259 gravatar . url ( undefined ) . should . be . ok ;
5360 gravatar . url ( '' ) . should . be . ok ;
61+ /* eslint-enable */
5462 } ) ;
5563
5664 it ( 'should handle non string values for the email property' , function ( ) {
@@ -82,11 +90,11 @@ describe('gravatar', function () {
8290
8391 it ( 'should generate uri with user passed parameters and protocol in options' , function ( ) {
8492 const gravatarURL = gravatar . url ( 'emerleite@gmail.com' , { protocol : 'https' , s : '200' , f : 'y' , r : 'g' , d : '404' } ) ;
85- const queryString = url . parse ( gravatarURL , true ) . query ;
86- queryString . s . should . equal ( '200' ) ;
87- queryString . f . should . equal ( 'y' ) ;
88- queryString . r . should . equal ( 'g' ) ;
89- queryString . d . should . equal ( '404' ) ;
93+ const { searchParams } = parseUrl ( gravatarURL ) ;
94+ searchParams . get ( 's' ) . should . equal ( '200' ) ;
95+ searchParams . get ( 'f' ) . should . equal ( 'y' ) ;
96+ searchParams . get ( 'r' ) . should . equal ( 'g' ) ;
97+ searchParams . get ( 'd' ) . should . equal ( '404' ) ;
9098 } ) ;
9199
92100 it ( 'should generate profile url with protocol in options' , function ( ) {
@@ -112,7 +120,7 @@ describe('CLI', function () {
112120 it ( 'accepts an email argument with options and writes gravatar URL to STDOUT' , function ( done ) {
113121 nixt ( )
114122 . run ( './cli.js zeke@sikelianos.com -p https -s 500 -d retro' )
115- . stdout ( 'Gravatar (avatar):\nhttps://s. gravatar.com/avatar/8f344b1c4bdcfc28bd848e97e94c3523?default=retro&size=500' )
123+ . stdout ( 'Gravatar (avatar):\nhttps://gravatar.com/avatar/8f344b1c4bdcfc28bd848e97e94c3523?default=retro&size=500' )
116124 . end ( done ) ;
117125 } ) ;
118126 it ( 'outputs usage if -h arg is present' , function ( done ) {
@@ -127,7 +135,7 @@ describe('CLI', function () {
127135 it ( 'accepts an email argument with options and writes gravatar URL to STDOUT' , function ( done ) {
128136 nixt ( )
129137 . run ( './cli.js avatar zeke@sikelianos.com -p https -s 500 -d retro' )
130- . stdout ( 'Gravatar (avatar):\nhttps://s. gravatar.com/avatar/8f344b1c4bdcfc28bd848e97e94c3523?default=retro&size=500' )
138+ . stdout ( 'Gravatar (avatar):\nhttps://gravatar.com/avatar/8f344b1c4bdcfc28bd848e97e94c3523?default=retro&size=500' )
131139 . end ( done ) ;
132140 } ) ;
133141 } ) ;
@@ -136,7 +144,7 @@ describe('CLI', function () {
136144 it ( 'accepts an email argument with options and writes gravatar profile URL to STDOUT' , function ( done ) {
137145 nixt ( )
138146 . run ( './cli.js profile zeke@sikelianos.com -p https -c doSomething' )
139- . stdout ( 'Gravatar (profile):\nhttps://secure. gravatar.com/8f344b1c4bdcfc28bd848e97e94c3523.json?callback=doSomething' )
147+ . stdout ( 'Gravatar (profile):\nhttps://gravatar.com/8f344b1c4bdcfc28bd848e97e94c3523.json?callback=doSomething' )
140148 . end ( done ) ;
141149 } ) ;
142150 } ) ;
0 commit comments