@@ -49,76 +49,24 @@ it('add a new rule for a prop that exists', async () => {
49
49
<meta charset="UTF-8">
50
50
<meta name="viewport" content="width=device-width, initial-scale=1.0">
51
51
<meta http-equiv="X-UA-Compatible" content="ie=edge">
52
+ <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
52
53
<title>Document</title>
53
54
</head>
54
55
<body>
55
- <div class="logos">
56
- <img class="logo" href="https://microlink.io/logo.png">
57
- <img class="logo" href="https://microlink.io/logo.png">
58
- <img class="logo" href="https://microlink.io/logo.png">
59
- <img class="logo" href="https://microlink.io/logo.png">
60
- </div>
61
-
62
- <img class="main-logo" href="https://microlink.io/logo.png">
56
+ <img id="logo" src="https://microlink.io/logo.png">
63
57
<p>Hello World </p>
64
58
</body>
65
59
</html>
66
60
`
67
61
68
62
const rules = [
69
63
{
70
- foo : [ ( ) => 'bar' ]
64
+ image : [ ( { htmlDom : $ } ) => $ ( '#logo' ) . attr ( 'src' ) ]
71
65
}
72
66
]
73
67
74
- const metascraper = require ( '../..' ) ( [
75
- {
76
- foo : [ ( ) => false , ( ) => false , ( ) => false ]
77
- }
78
- ] )
79
-
80
- const meta = await metascraper ( { url, html, rules } )
81
- should ( meta . foo ) . be . equal ( 'bar' )
82
- } )
83
-
84
- it ( 'rules are added from the end' , async ( ) => {
85
- const url = 'https://microlink.io'
86
-
87
- const html = `
88
- <!DOCTYPE html>
89
- <html lang="en">
90
- <head>
91
- <meta charset="UTF-8">
92
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
93
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
94
- <title>Document</title>
95
- </head>
96
- <body>
97
- <div class="logos">
98
- <img class="logo" href="https://microlink.io/logo.png">
99
- <img class="logo" href="https://microlink.io/logo.png">
100
- <img class="logo" href="https://microlink.io/logo.png">
101
- <img class="logo" href="https://microlink.io/logo.png">
102
- </div>
103
-
104
- <img class="main-logo" href="https://microlink.io/logo.png">
105
- <p>Hello World </p>
106
- </body>
107
- </html>
108
- `
109
-
110
- const rules = [
111
- {
112
- foo : [ ( ) => 'bar' ]
113
- }
114
- ]
115
-
116
- const metascraper = require ( '../..' ) ( [
117
- {
118
- foo : [ ( ) => false , ( ) => false , ( ) => 'baz' ]
119
- }
120
- ] )
68
+ const metascraper = require ( '../..' ) ( [ require ( 'metascraper-image' ) ( ) ] )
121
69
122
70
const meta = await metascraper ( { url, html, rules } )
123
- should ( meta . foo ) . be . equal ( 'baz ' )
71
+ should ( meta . image ) . be . equal ( 'https://microlink.io/logo.png ' )
124
72
} )
0 commit comments