@@ -87,6 +87,25 @@ describe('new', () => {
87
87
} ) ;
88
88
} ) ;
89
89
90
+ it ( 'slug - s' , ( ) => {
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' ) ;
@@ -107,6 +126,26 @@ describe('new', () => {
107
126
} ) ;
108
127
} ) ;
109
128
129
+ it ( 'path - p' , ( ) => {
130
+ const date = moment ( now ) ;
131
+ const path = pathFn . join ( hexo . source_dir , '_posts' , 'bar.md' ) ;
132
+ const body = [
133
+ 'title: Hello World' ,
134
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
135
+ 'tags:' ,
136
+ '---'
137
+ ] . join ( '\n' ) + '\n' ;
138
+
139
+ return n ( {
140
+ _ : [ 'Hello World' ] ,
141
+ slug : 'foo' ,
142
+ p : 'bar'
143
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
144
+ content . should . eql ( body ) ;
145
+ return fs . unlink ( path ) ;
146
+ } ) ;
147
+ } ) ;
148
+
110
149
it ( 'rename if target existed' , ( ) => {
111
150
const path = pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World-1.md' ) ;
112
151
@@ -125,7 +164,14 @@ describe('new', () => {
125
164
} ) ;
126
165
127
166
it ( 'replace existing files' , ( ) => {
167
+ const date = moment ( now ) ;
128
168
const path = pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World.md' ) ;
169
+ const body = [
170
+ 'title: Hello World' ,
171
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
172
+ 'tags:' ,
173
+ '---'
174
+ ] . join ( '\n' ) + '\n' ;
129
175
130
176
return post . create ( {
131
177
title : 'Hello World'
@@ -134,8 +180,31 @@ describe('new', () => {
134
180
replace : true
135
181
} ) ) . then ( ( ) => fs . exists ( pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World-1.md' ) ) ) . then ( exist => {
136
182
exist . should . be . false ;
137
- return fs . unlink ( path ) ;
138
- } ) ;
183
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
184
+ content . should . eql ( body ) ;
185
+ } ) . finally ( ( ) => fs . unlink ( path ) ) ;
186
+ } ) ;
187
+
188
+ it ( 'replace existing files - r' , ( ) => {
189
+ const date = moment ( now ) ;
190
+ const path = pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World.md' ) ;
191
+ const body = [
192
+ 'title: Hello World' ,
193
+ 'date: ' + date . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
194
+ 'tags:' ,
195
+ '---'
196
+ ] . join ( '\n' ) + '\n' ;
197
+
198
+ return post . create ( {
199
+ title : 'Hello World'
200
+ } ) . then ( ( ) => n ( {
201
+ _ : [ 'Hello World' ] ,
202
+ r : true
203
+ } ) ) . then ( ( ) => fs . exists ( pathFn . join ( hexo . source_dir , '_posts' , 'Hello-World-1.md' ) ) ) . then ( exist => {
204
+ exist . should . be . false ;
205
+ } ) . then ( ( ) => fs . readFile ( path ) ) . then ( content => {
206
+ content . should . eql ( body ) ;
207
+ } ) . finally ( ( ) => fs . unlink ( path ) ) ;
139
208
} ) ;
140
209
141
210
it ( 'extra data' , ( ) => {
0 commit comments