Skip to content

Commit ca21506

Browse files
Add test cases
1 parent 9930523 commit ca21506

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

test/scripts/console/new.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ describe('new', () => {
8787
});
8888
});
8989

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+
90109
it('path', () => {
91110
const date = moment(now);
92111
const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md');
@@ -125,7 +144,14 @@ describe('new', () => {
125144
});
126145

127146
it('replace existing files', () => {
147+
const date = moment(now);
128148
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';
129155

130156
return post.create({
131157
title: 'Hello World'
@@ -134,8 +160,31 @@ describe('new', () => {
134160
replace: true
135161
})).then(() => fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'))).then(exist => {
136162
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));
139188
});
140189

141190
it('extra data', () => {

0 commit comments

Comments
 (0)