11'use strict' ;
22
3+ var pathFn = require ( 'path' ) ;
34var cheerio = require ( 'cheerio' ) ;
45var should = require ( 'chai' ) . should ( ) ; // eslint-disable-line
56
67describe ( 'img' , function ( ) {
7- var img = require ( '../../../lib/plugins/tag/img' ) ;
8+ var Hexo = require ( '../../../lib/hexo' ) ;
9+ var hexo = new Hexo ( pathFn . join ( __dirname , 'img_test' ) ) ;
10+ var img = require ( '../../../lib/plugins/tag/img' ) ( hexo ) ;
11+
12+ before ( function ( ) {
13+ return hexo . init ( ) ;
14+ } ) ;
815
916 it ( 'src' , function ( ) {
1017 var $ = cheerio . load ( img ( [ 'http://placekitten.com/200/300' ] ) ) ;
@@ -13,9 +20,13 @@ describe('img', function() {
1320 } ) ;
1421
1522 it ( 'internal src' , function ( ) {
23+ hexo . config . root = '/' ;
1624 var $ = cheerio . load ( img ( [ '/images/test.jpg' ] ) ) ;
17-
1825 $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/images/test.jpg' ) ;
26+
27+ hexo . config . root = '/root/' ;
28+ $ = cheerio . load ( img ( [ '/images/test.jpg' ] ) ) ;
29+ $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/root/images/test.jpg' ) ;
1930 } ) ;
2031
2132 it ( 'class + src' , function ( ) {
@@ -26,10 +37,15 @@ describe('img', function() {
2637 } ) ;
2738
2839 it ( 'class + internal src' , function ( ) {
40+ hexo . config . root = '/' ;
2941 var $ = cheerio . load ( img ( 'left /images/test.jpg' . split ( ' ' ) ) ) ;
30-
3142 $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/images/test.jpg' ) ;
3243 $ ( 'img' ) . attr ( 'class' ) . should . eql ( 'left' ) ;
44+
45+ hexo . config . root = '/root/' ;
46+ $ = cheerio . load ( img ( 'left /images/test.jpg' . split ( ' ' ) ) ) ;
47+ $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/root/images/test.jpg' ) ;
48+ $ ( 'img' ) . attr ( 'class' ) . should . eql ( 'left' ) ;
3349 } ) ;
3450
3551 it ( 'multiple classes + src' , function ( ) {
@@ -40,10 +56,15 @@ describe('img', function() {
4056 } ) ;
4157
4258 it ( 'multiple classes + internal src' , function ( ) {
59+ hexo . config . root = '/' ;
4360 var $ = cheerio . load ( img ( 'left top /images/test.jpg' . split ( ' ' ) ) ) ;
44-
4561 $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/images/test.jpg' ) ;
4662 $ ( 'img' ) . attr ( 'class' ) . should . eql ( 'left top' ) ;
63+
64+ hexo . config . root = '/root/' ;
65+ $ = cheerio . load ( img ( 'left top /images/test.jpg' . split ( ' ' ) ) ) ;
66+ $ ( 'img' ) . attr ( 'src' ) . should . eql ( '/root/images/test.jpg' ) ;
67+ $ ( 'img' ) . attr ( 'class' ) . should . eql ( 'left top' ) ;
4768 } ) ;
4869
4970 it ( 'class + src + width' , function ( ) {
0 commit comments