@@ -87,6 +87,25 @@ describe('new', () => {
87
87
} ) ;
88
88
} ) ;
89
89
90
+ it ( 'slug(2)' , ( ) => {
91
+ const date = moment ( now ) ;
92
+ const path = pathFn . join ( hexo . source_dir , '_posts' , 'foo.md' ) ;
93
+ const body = [
94
+ 'title: Hello World' ,
95
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
96
+ 'tags:' ,
97
+ '---'
98
+ ] . join ( '\n' ) + '\n' ;
99
+
100
+ return n ( {
101
+ _ : [ 'Hello World' ] ,
102
+ s : 'foo'
103
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
104
+ content . should . eql ( body ) ;
105
+ return fs . unlink ( path ) ;
106
+ } ) ;
107
+ } ) ;
108
+
90
109
it ( 'path' , ( ) => {
91
110
const date = moment ( now ) ;
92
111
const path = pathFn . join ( hexo . source_dir , '_posts' , 'bar.md' ) ;
@@ -125,7 +144,14 @@ describe('new', () => {
125
144
} ) ;
126
145
127
146
it ( 'replace existing files' , ( ) => {
147
+ const date = moment ( now ) ;
128
148
const path = pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World.md' ) ;
149
+ const body = [
150
+ 'title: Hello World' ,
151
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
152
+ 'tags:' ,
153
+ '---'
154
+ ] . join ( '\n' ) + '\n' ;
129
155
130
156
return post . create ( {
131
157
title : 'Hello World'
@@ -134,8 +160,31 @@ describe('new', () => {
134
160
replace : true
135
161
} ) ) . then ( ( ) => fs . exists ( pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World-1.md' ) ) ) . then ( exist => {
136
162
exist . should . be . false ;
137
- return fs . unlink ( path ) ;
138
- } ) ;
163
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
164
+ content . should . eql ( body ) ;
165
+ } ) . finally ( ( ) => fs . unlink ( path ) ) ;
166
+ } ) ;
167
+
168
+ it ( 'replace existing files (2)' , ( ) => {
169
+ const date = moment ( now ) ;
170
+ const path = pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World.md' ) ;
171
+ const body = [
172
+ 'title: Hello World' ,
173
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
174
+ 'tags:' ,
175
+ '---'
176
+ ] . join ( '\n' ) + '\n' ;
177
+
178
+ return post . create ( {
179
+ title : 'Hello World'
180
+ } ) . then ( ( ) => n ( {
181
+ _ : [ 'Hello World' ] ,
182
+ r : true
183
+ } ) ) . then ( ( ) => fs . exists ( pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World-1.md' ) ) ) . then ( exist => {
184
+ exist . should . be . false ;
185
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
186
+ content . should . eql ( body ) ;
187
+ } ) . finally ( ( ) => fs . unlink ( path ) ) ;
139
188
} ) ;
140
189
141
190
it ( 'extra data' , ( ) => {
0 commit comments