@@ -27,65 +27,87 @@ describe( 'scraping', function () {
2727 }
2828
2929 describe ( 'parseAll function' , ( ) => {
30- it ( 'should resolve promise from woorank with headers' , ( ) => {
31- const url = 'https://www.woorank.com/en/blog/dublin-core-metadata-for-seo-and-usability' ;
32- return meta ( { uri : url , headers : { 'User-Agent' : userAgent , Accept : acceptHeader } } )
33- . then ( ( result ) => {
34- assert . ok ( result , 'Expected result to be truthy' ) ;
35- } )
36- . catch ( ( e ) => {
37- console . error ( 'Error in woorank test:' , e ) ;
38- throw e ;
39- } ) ;
40- } ) ;
4130
42- it ( 'should resolve promise from blog.schema.org without headers' , ( ) => {
43- const url = 'http://blog.schema.org' ;
44- return meta ( url )
45- . then ( ( result ) => {
46- assert . ok ( result , 'Expected result to be truthy' ) ;
31+ describe ( 'Promise style' , ( ) => {
32+ it ( 'should resolve promise from woorank with headers' , ( ) => {
33+ const url = 'https://www.woorank.com/en/blog/dublin-core-metadata-for-seo-and-usability' ;
34+ return meta ( { uri : url , headers : { 'User-Agent' : userAgent , Accept : acceptHeader } } )
35+ . then ( ( result ) => {
36+ assert . ok ( result , 'Expected result to be truthy' ) ;
37+ } )
38+ . catch ( ( e ) => {
39+ console . error ( 'Error in woorank test:' , e ) ;
40+ throw e ;
41+ } ) ;
42+ } ) ;
43+
44+ it ( 'should resolve promise from blog.schema.org without headers' , ( ) => {
45+ const url = 'http://blog.schema.org' ;
46+ return meta ( url )
47+ . then ( ( result ) => {
48+ assert . ok ( result , 'Expected result to be truthy' ) ;
49+ } )
50+ . catch ( ( e ) => {
51+ console . error ( 'Error in blog.schema.org test:' , e ) ;
52+ throw e ;
53+ } ) ;
54+ } ) ;
55+
56+ it ( 'should throw error if no uri supplied' , ( ) => meta ( )
57+ . then ( ( ) => {
58+ assert . fail ( 'Should have rejected the promise' ) ;
4759 } )
4860 . catch ( ( e ) => {
49- console . error ( 'Error in blog.schema.org test:' , e ) ;
50- throw e ;
61+ assert . ok ( e instanceof Error , 'Error should be an Error object' ) ;
62+ assert . strictEqual ( e . message , 'No uri supplied in argument' , 'Error message should match expected message' ) ;
63+ } )
64+ ) ;
65+
66+ it ( 'should not have any undefined values' , ( ) => {
67+ const url = 'http://web.archive.org/web/20220127144804/https://www.cnet.com/special-reports/vr101/' ;
68+ return getWithHeaders ( url ) . then ( ( body ) => {
69+ const chtml = cheerio . load ( body ) ;
70+ return meta . parseAll ( chtml )
71+ . then ( ( results ) => {
72+ Object . keys ( results ) . forEach ( ( metadataType ) => {
73+ Object . keys ( results [ metadataType ] ) . forEach ( ( key ) => {
74+ assert . notStrictEqual ( results [ metadataType ] [ key ] , undefined , `${ metadataType } .${ key } should not be undefined` ) ;
75+ } ) ;
76+ } ) ;
77+ } ) ;
5178 } ) ;
52- } ) ;
79+ } ) ;
5380
54- it ( 'should throw error if no uri supplied' , ( ) => meta ( )
55- . then ( ( ) => {
56- assert . fail ( 'Should have rejected the promise' ) ;
57- } )
58- . catch ( ( e ) => {
59- assert . ok ( e instanceof Error , 'Error should be an Error object' ) ;
60- assert . strictEqual ( e . message , 'No uri supplied in argument' , 'Error message should match expected message' ) ;
61- } )
62- ) ;
63-
64- it ( 'should support await implementation with headers' , async ( ) => {
65- const url = 'http://blog.schema.org' ;
66- const result = await meta ( { uri : url , headers : { 'User-Agent' : userAgent , Accept : acceptHeader } } ) ;
67- assert . ok ( result , 'Expected result to be truthy' ) ;
6881 } ) ;
6982
70- it ( 'should support await implementation without headers' , async ( ) => {
71- const url = 'http://blog.schema.org' ;
72- const result = await meta ( url ) ;
73- assert . ok ( result , 'Expected result to be truthy' ) ;
74- } ) ;
83+ describe ( 'Await style' , ( ) => {
7584
76- it ( 'should throw error if no uri is supplied with async/await' , async ( ) => {
77- try {
78- await meta ( ) ;
79- assert . fail ( 'Should have thrown an error' ) ;
80- } catch ( e ) {
81- assert . ok ( e instanceof Error , 'Error should be an Error object' ) ;
82- assert . strictEqual ( e . message , 'No uri supplied in argument' , 'Error message should match expected message' ) ;
83- }
85+ it ( 'should support await implementation with headers' , async ( ) => {
86+ const url = 'http://blog.schema.org' ;
87+ const result = await meta ( { uri : url , headers : { 'User-Agent' : userAgent , Accept : acceptHeader } } ) ;
88+ assert . ok ( result , 'Expected result to be truthy' ) ;
89+ } ) ;
90+
91+ it ( 'should support await implementation without headers' , async ( ) => {
92+ const url = 'http://blog.schema.org' ;
93+ const result = await meta ( url ) ;
94+ assert . ok ( result , 'Expected result to be truthy' ) ;
95+ } ) ;
96+
97+ it ( 'should throw error if no uri is supplied with async/await' , async ( ) => {
98+ try {
99+ await meta ( ) ;
100+ assert . fail ( 'Should have thrown an error' ) ;
101+ } catch ( e ) {
102+ assert . ok ( e instanceof Error , 'Error should be an Error object' ) ;
103+ assert . strictEqual ( e . message , 'No uri supplied in argument' , 'Error message should match expected message' ) ;
104+ }
105+ } ) ;
84106 } ) ;
85107
86108 } ) ;
87109
88- describe ( 'parseBEPress function ' , ( ) => {
110+ describe ( 'Individual metadata functions ' , ( ) => {
89111 it ( 'should get BE Press metadata tags' , ( ) => {
90112 const url = 'http://biostats.bepress.com/harvardbiostat/paper154/' ;
91113 return getWithHeaders ( url ) . then ( ( body ) => {
@@ -106,9 +128,7 @@ describe( 'scraping', function () {
106128 } ) ;
107129 } ) ;
108130 } ) ;
109- } ) ;
110131
111- describe ( 'parseCOinS function' , ( ) => {
112132 it ( 'should get COinS metadata' , ( ) => {
113133 const url = 'https://en.wikipedia.org/wiki/Viral_phylodynamics' ;
114134 return getWithHeaders ( url ) . then ( ( body ) => {
@@ -121,9 +141,7 @@ describe( 'scraping', function () {
121141 } ) ;
122142 } ) ;
123143 } ) ;
124- } ) ;
125144
126- describe ( 'parseEPrints function' , ( ) => {
127145 it ( 'should get EPrints metadata' , ( ) => {
128146 const url = 'http://eprints.gla.ac.uk/113711/' ;
129147 return getWithHeaders ( url ) . then ( ( body ) => {
@@ -139,45 +157,17 @@ describe( 'scraping', function () {
139157 } ) ;
140158 } ) ;
141159 } ) ;
142- } ) ;
143-
144- describe ( 'parseGeneral function' , ( ) => {
145- it ( 'should get html lang parameter' , ( ) => {
146- const expected = 'fr' ;
147- const url = 'http://www.lemonde.fr' ;
148- return getWithHeaders ( url ) . then ( ( body ) => {
149- const chtml = cheerio . load ( body ) ;
150- return meta . parseGeneral ( chtml ) . then ( ( results ) => {
151- assert . strictEqual ( results . lang , expected ) ;
152- } ) ;
153- } ) ;
154- } ) ;
155160
156- it ( 'should get html dir parameter ' , ( ) => {
157- const expected = 'rtl ' ;
158- const url = 'https ://www.iranrights.org/fa/ ' ;
161+ it ( 'should get general metadata ' , ( ) => {
162+ const expected = 'Example Domain ' ;
163+ const url = 'http ://example.com ' ;
159164 return getWithHeaders ( url ) . then ( ( body ) => {
160165 const chtml = cheerio . load ( body ) ;
161166 return meta . parseGeneral ( chtml ) . then ( ( results ) => {
162- assert . strictEqual ( results . dir , expected ) ;
167+ assert . strictEqual ( results . title , expected ) ;
163168 } ) ;
164169 } ) ;
165170 } ) ;
166171 } ) ;
167172
168- it ( 'should not have any undefined values' , ( ) => {
169- const url = 'http://web.archive.org/web/20220127144804/https://www.cnet.com/special-reports/vr101/' ;
170- return getWithHeaders ( url ) . then ( ( body ) => {
171- const chtml = cheerio . load ( body ) ;
172- return meta . parseAll ( chtml )
173- . then ( ( results ) => {
174- Object . keys ( results ) . forEach ( ( metadataType ) => {
175- Object . keys ( results [ metadataType ] ) . forEach ( ( key ) => {
176- assert . notStrictEqual ( results [ metadataType ] [ key ] , undefined , `${ metadataType } .${ key } should not be undefined` ) ;
177- } ) ;
178- } ) ;
179- } ) ;
180- } ) ;
181- } ) ;
182-
183173} ) ;
0 commit comments