Skip to content

Commit 4fec0e0

Browse files
authored
test: add test case for issue #4334 (#5465)
1 parent 43fcce3 commit 4fec0e0

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"abbrev": "^2.0.0",
4444
"archy": "^1.0.0",
4545
"bluebird": "^3.7.2",
46-
"hexo-cli": "^4.3.0",
46+
"hexo-cli": "^4.3.2",
4747
"hexo-front-matter": "^4.2.1",
4848
"hexo-fs": "^4.1.3",
4949
"hexo-i18n": "^2.0.0",
@@ -74,6 +74,7 @@
7474
"@types/mocha": "^10.0.6",
7575
"@types/node": "^18.11.8 <18.19.9",
7676
"@types/nunjucks": "^3.2.2",
77+
"@types/rewire": "^2.5.30",
7778
"@types/sinon": "^17.0.3",
7879
"@types/text-table": "^0.2.4",
7980
"c8": "^9.0.0",
@@ -86,6 +87,7 @@
8687
"husky": "^8.0.1",
8788
"lint-staged": "^15.2.0",
8889
"mocha": "^10.0.0",
90+
"rewire": "^7.0.0",
8991
"sinon": "^17.0.1",
9092
"ts-node": "^10.9.1",
9193
"typescript": "^5.3.2"

test/scripts/console/new.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Promise from 'bluebird';
66
import { useFakeTimers, spy, SinonSpy } from 'sinon';
77
import Hexo from '../../../lib/hexo';
88
import newConsole from '../../../lib/plugins/console/new';
9+
import rewire from 'rewire';
910
type OriginalParams = Parameters<typeof newConsole>;
1011
type OriginalReturn = ReturnType<typeof newConsole>;
1112

@@ -363,4 +364,80 @@ describe('new', () => {
363364

364365
await unlink(path);
365366
});
367+
368+
it('path - number (issue #4334)', async () => {
369+
let args;
370+
const cli = rewire('hexo-cli');
371+
return cli.__with__({
372+
find_pkg_1: {
373+
default: (_cwd, _args) => {
374+
args = _args;
375+
return Promise.resolve();
376+
}
377+
}
378+
})(async () => {
379+
process.argv = ['hexo', 'new', '--path', '123', 'test'];
380+
// @ts-ignore
381+
cli(null, null);
382+
args.path.should.eql('123');
383+
process.argv = [];
384+
});
385+
});
386+
387+
it('p - number (issue #4334)', async () => {
388+
let args;
389+
const cli = rewire('hexo-cli');
390+
return cli.__with__({
391+
find_pkg_1: {
392+
default: (_cwd, _args) => {
393+
args = _args;
394+
return Promise.resolve();
395+
}
396+
}
397+
})(async () => {
398+
process.argv = ['hexo', 'new', '-p', '123', 'test'];
399+
// @ts-ignore
400+
cli(null, null);
401+
args.p.should.eql('123');
402+
process.argv = [];
403+
});
404+
});
405+
406+
it('slug - number (issue #4334)', async () => {
407+
let args;
408+
const cli = rewire('hexo-cli');
409+
return cli.__with__({
410+
find_pkg_1: {
411+
default: (_cwd, _args) => {
412+
args = _args;
413+
return Promise.resolve();
414+
}
415+
}
416+
})(async () => {
417+
process.argv = ['hexo', 'new', '--slug', '123', 'test'];
418+
// @ts-ignore
419+
cli(null, null);
420+
args.slug.should.eql('123');
421+
process.argv = [];
422+
});
423+
});
424+
425+
it('s - number (issue #4334)', async () => {
426+
let args;
427+
const cli = rewire('hexo-cli');
428+
return cli.__with__({
429+
find_pkg_1: {
430+
default: (_cwd, _args) => {
431+
args = _args;
432+
return Promise.resolve();
433+
}
434+
}
435+
})(async () => {
436+
process.argv = ['hexo', 'new', '-s', '123', 'test'];
437+
// @ts-ignore
438+
cli(null, null);
439+
args.s.should.eql('123');
440+
process.argv = [];
441+
});
442+
});
366443
});

0 commit comments

Comments
 (0)