@@ -8,27 +8,27 @@ import byTypeFilenameGenerator from '../../../lib/filename-generator/by-type.js'
88describe ( 'FilenameGenerator: byType' , ( ) => {
99 it ( 'should return resource filename' , ( ) => {
1010 const r = new Resource ( 'http://example.com/a.png' , 'b.png' ) ;
11- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
12- filename . should . equalFileSystemPath ( 'b.png' ) ;
11+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
12+ filepath . should . equalFileSystemPath ( 'b.png' ) ;
1313 } ) ;
1414
1515 it ( 'should return url-based filename if resource has no filename' , ( ) => {
1616 const r = new Resource ( 'http://example.com/a.png' ) ;
17- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
18- filename . should . equalFileSystemPath ( 'a.png' ) ;
17+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
18+ filepath . should . equalFileSystemPath ( 'a.png' ) ;
1919 } ) ;
2020
2121 it ( 'should return url-based filename if resource has empty filename' , ( ) => {
2222 const r = new Resource ( 'http://example.com/a.png' , '' ) ;
23- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
24- filename . should . equalFileSystemPath ( 'a.png' ) ;
23+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
24+ filepath . should . equalFileSystemPath ( 'a.png' ) ;
2525 } ) ;
2626
2727 it ( 'should add missed extensions for html resources' , ( ) => {
2828 const r = new Resource ( 'http://example.com/about' , '' ) ;
2929 r . getType = sinon . stub ( ) . returns ( 'html' ) ;
30- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
31- filename . should . equalFileSystemPath ( 'about.html' ) ;
30+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
31+ filepath . should . equalFileSystemPath ( 'about.html' ) ;
3232 } ) ;
3333
3434 it ( 'should add missed extensions for css resources' , ( ) => {
@@ -41,15 +41,15 @@ describe('FilenameGenerator: byType', () => {
4141 it ( 'should add missed extensions for js resources' , ( ) => {
4242 const r = new Resource ( 'http://example.com/js' , '' ) ;
4343 r . getType = sinon . stub ( ) . returns ( 'js' ) ;
44- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
45- filename . should . equalFileSystemPath ( 'js.js' ) ;
44+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
45+ filepath . should . equalFileSystemPath ( 'js.js' ) ;
4646 } ) ;
4747
4848 it ( 'should not add missed extensions for other resources' , ( ) => {
4949 const r = new Resource ( 'http://1.gravatar.com/avatar/4d63e4a045c7ff22accc33dc08442f86?s=140&d=%2Fwp-content%2Fuploads%2F2015%2F05%2FGood-JOb-150x150.jpg&r=g' , '' ) ;
5050 r . getType = sinon . stub ( ) . returns ( 'home' ) ;
51- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
52- filename . should . equalFileSystemPath ( '4d63e4a045c7ff22accc33dc08442f86' ) ;
51+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
52+ filepath . should . equalFileSystemPath ( '4d63e4a045c7ff22accc33dc08442f86' ) ;
5353 } ) ;
5454
5555 it ( 'should return filename with correct subdirectory' , ( ) => {
@@ -60,8 +60,8 @@ describe('FilenameGenerator: byType', () => {
6060 } ;
6161
6262 const r = new Resource ( 'http://example.com/a.png' ) ;
63- const filename = byTypeFilenameGenerator ( r , options , [ ] ) ;
64- filename . should . equalFileSystemPath ( 'img/a.png' ) ;
63+ const filepath = byTypeFilenameGenerator ( r , options , [ ] ) ;
64+ filepath . should . equalFileSystemPath ( 'img/a.png' ) ;
6565 } ) ;
6666
6767 it ( 'should return filename with correct subdirectory when string cases are different' , ( ) => {
@@ -72,14 +72,14 @@ describe('FilenameGenerator: byType', () => {
7272 } ;
7373
7474 const r = new Resource ( 'http://example.com/a.PNG' ) ;
75- const f = byTypeFilenameGenerator ( r , options , [ ] ) ;
76- f . should . equalFileSystemPath ( 'img/a.PNG' ) ;
75+ const filepath = byTypeFilenameGenerator ( r , options , [ ] ) ;
76+ filepath . should . equalFileSystemPath ( 'img/a.PNG' ) ;
7777 } ) ;
7878
7979 it ( 'should return different filename if desired filename is occupied' , ( ) => {
8080 const r = new Resource ( 'http://second-example.com/a.png' ) ;
81- const filename = byTypeFilenameGenerator ( r , { } , [ 'a.png' ] ) ;
82- filename . should . not . equalFileSystemPath ( 'a.png' ) ;
81+ const filepath = byTypeFilenameGenerator ( r , { } , [ 'a.png' ] ) ;
82+ filepath . should . not . equalFileSystemPath ( 'a.png' ) ;
8383 } ) ;
8484
8585 it ( 'should return different filename if desired filename is occupied N times' , ( ) => {
@@ -89,30 +89,32 @@ describe('FilenameGenerator: byType', () => {
8989 const r3 = new Resource ( 'http://third-example.com/a.png' ) ;
9090 const r4 = new Resource ( 'http://fourth-example.com/a.png' ) ;
9191
92- const f1 = byTypeFilenameGenerator ( r1 , { } , occupiedFilenames ) ;
93- f1 . should . equalFileSystemPath ( 'a.png' ) ;
94- occupiedFilenames . push ( f1 ) ;
92+ const fp1 = byTypeFilenameGenerator ( r1 , { } , occupiedFilenames ) ;
93+ fp1 . should . equalFileSystemPath ( 'a.png' ) ;
94+ occupiedFilenames . push ( fp1 ) ;
9595
96- const f2 = byTypeFilenameGenerator ( r2 , { } , occupiedFilenames ) ;
97- f2 . should . not . equal ( f1 ) ;
98- occupiedFilenames . push ( f2 ) ;
96+ const fp2 = byTypeFilenameGenerator ( r2 , { } , occupiedFilenames ) ;
97+ fp2 . should . not . equal ( fp1 ) ;
98+ occupiedFilenames . push ( fp2 ) ;
9999
100- const f3 = byTypeFilenameGenerator ( r3 , { } , occupiedFilenames ) ;
101- f3 . should . not . equal ( f1 ) ;
102- f3 . should . not . equal ( f2 ) ;
103- occupiedFilenames . push ( f3 ) ;
100+ const fp3 = byTypeFilenameGenerator ( r3 , { } , occupiedFilenames ) ;
101+ fp3 . should . not . equal ( fp1 ) ;
102+ fp3 . should . not . equal ( fp2 ) ;
103+ occupiedFilenames . push ( fp3 ) ;
104104
105- const f4 = byTypeFilenameGenerator ( r4 , { } , occupiedFilenames ) ;
106- f4 . should . not . equal ( f1 ) ;
107- f4 . should . not . equal ( f2 ) ;
108- f4 . should . not . equal ( f3 ) ;
105+ const fp4 = byTypeFilenameGenerator ( r4 , { } , occupiedFilenames ) ;
106+ fp4 . should . not . equal ( fp1 ) ;
107+ fp4 . should . not . equal ( fp2 ) ;
108+ fp4 . should . not . equal ( fp3 ) ;
109109 } ) ;
110110
111111 it ( 'should shorten filename' , ( ) => {
112112 const resourceFilename = new Array ( 1000 ) . fill ( 'a' ) . join ( '' ) + '.png' ;
113113 const r = new Resource ( 'http://example.com/a.png' , resourceFilename ) ;
114- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
115- should ( filename . length ) . be . lessThan ( 255 ) ;
114+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
115+ const filenameParts = filepath . split ( '/' ) ;
116+ const filename = filenameParts [ filenameParts . length - 1 ] ;
117+ should ( filename . length ) . be . lessThanOrEqual ( 255 ) ;
116118 } ) ;
117119
118120 it ( 'should return different short filename if first short filename is occupied' , ( ) => {
@@ -121,28 +123,30 @@ describe('FilenameGenerator: byType', () => {
121123 const r1 = new Resource ( 'http://first-example.com/a.png' , resourceFilename ) ;
122124 const r2 = new Resource ( 'http://second-example.com/a.png' , resourceFilename ) ;
123125
124- const f1 = byTypeFilenameGenerator ( r1 , { } , [ ] ) ;
125- should ( f1 . length ) . be . lessThan ( 255 ) ;
126+ const fp1 = byTypeFilenameGenerator ( r1 , { } , [ ] ) ;
127+ const filenameParts1 = fp1 . split ( '/' ) ;
128+ const filename1 = filenameParts1 [ filenameParts1 . length - 1 ] ;
129+ should ( filename1 . length ) . be . lessThanOrEqual ( 255 ) ;
126130
127- const f2 = byTypeFilenameGenerator ( r2 , { } , [ f1 ] ) ;
128- should ( f2 . length ) . be . lessThan ( 255 ) ;
129- should ( f2 ) . not . be . eql ( f1 ) ;
130-
131- should ( f2 ) . not . be . eql ( f1 ) ;
131+ const fp2 = byTypeFilenameGenerator ( r2 , { } , [ fp1 ] ) ;
132+ const filenameParts2 = fp2 . split ( '/' ) ;
133+ const filename2 = filenameParts2 [ filenameParts2 . length - 1 ] ;
134+ should ( filename2 . length ) . be . lessThanOrEqual ( 255 ) ;
135+ should ( filename2 ) . not . be . eql ( filename1 ) ;
132136 } ) ;
133137
134138 it ( 'should return decoded url-based filename' , ( ) => {
135139 const r = new Resource ( 'https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B' ) ;
136- const filename = byTypeFilenameGenerator ( r , { } , [ ] ) ;
137- filename . should . equalFileSystemPath ( 'JavaScript_шеллы' ) ;
140+ const filepath = byTypeFilenameGenerator ( r , { } , [ ] ) ;
141+ filepath . should . equalFileSystemPath ( 'JavaScript_шеллы' ) ;
138142
139143 const r2 = new Resource ( 'https://developer.mozilla.org/Hello%20G%C3%BCnter.png' ) ;
140- const filename2 = byTypeFilenameGenerator ( r2 , { } , [ ] ) ;
141- filename2 . should . equalFileSystemPath ( 'Hello Günter.png' ) ;
144+ const filepath2 = byTypeFilenameGenerator ( r2 , { } , [ ] ) ;
145+ filepath2 . should . equalFileSystemPath ( 'Hello Günter.png' ) ;
142146 } ) ;
143147
144148 it ( 'should remove not allowed characters from filename' , ( ) => {
145149 const r1 = new Resource ( 'http://example.com/some/path/<*a*>.png' ) ;
146- byTypeFilenameGenerator ( r1 , { } , [ ] ) . should . equalFileSystemPath ( '__a__ .png' ) ;
150+ byTypeFilenameGenerator ( r1 , { } , [ ] ) . should . equalFileSystemPath ( '_a_ .png' ) ;
147151 } ) ;
148152} ) ;
0 commit comments