From 4fec0e0991c95fa6eceb953401291d36e77cb3ec Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Wed, 17 Apr 2024 00:05:45 +0800 Subject: [PATCH] test: add test case for issue #4334 (#5465) --- package.json | 4 +- test/scripts/console/new.ts | 77 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b489563829..b136c849ed 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "abbrev": "^2.0.0", "archy": "^1.0.0", "bluebird": "^3.7.2", - "hexo-cli": "^4.3.0", + "hexo-cli": "^4.3.2", "hexo-front-matter": "^4.2.1", "hexo-fs": "^4.1.3", "hexo-i18n": "^2.0.0", @@ -74,6 +74,7 @@ "@types/mocha": "^10.0.6", "@types/node": "^18.11.8 <18.19.9", "@types/nunjucks": "^3.2.2", + "@types/rewire": "^2.5.30", "@types/sinon": "^17.0.3", "@types/text-table": "^0.2.4", "c8": "^9.0.0", @@ -86,6 +87,7 @@ "husky": "^8.0.1", "lint-staged": "^15.2.0", "mocha": "^10.0.0", + "rewire": "^7.0.0", "sinon": "^17.0.1", "ts-node": "^10.9.1", "typescript": "^5.3.2" diff --git a/test/scripts/console/new.ts b/test/scripts/console/new.ts index 9ff8fb4bb4..29448ea909 100644 --- a/test/scripts/console/new.ts +++ b/test/scripts/console/new.ts @@ -6,6 +6,7 @@ import Promise from 'bluebird'; import { useFakeTimers, spy, SinonSpy } from 'sinon'; import Hexo from '../../../lib/hexo'; import newConsole from '../../../lib/plugins/console/new'; +import rewire from 'rewire'; type OriginalParams = Parameters; type OriginalReturn = ReturnType; @@ -363,4 +364,80 @@ describe('new', () => { await unlink(path); }); + + it('path - number (issue #4334)', async () => { + let args; + const cli = rewire('hexo-cli'); + return cli.__with__({ + find_pkg_1: { + default: (_cwd, _args) => { + args = _args; + return Promise.resolve(); + } + } + })(async () => { + process.argv = ['hexo', 'new', '--path', '123', 'test']; + // @ts-ignore + cli(null, null); + args.path.should.eql('123'); + process.argv = []; + }); + }); + + it('p - number (issue #4334)', async () => { + let args; + const cli = rewire('hexo-cli'); + return cli.__with__({ + find_pkg_1: { + default: (_cwd, _args) => { + args = _args; + return Promise.resolve(); + } + } + })(async () => { + process.argv = ['hexo', 'new', '-p', '123', 'test']; + // @ts-ignore + cli(null, null); + args.p.should.eql('123'); + process.argv = []; + }); + }); + + it('slug - number (issue #4334)', async () => { + let args; + const cli = rewire('hexo-cli'); + return cli.__with__({ + find_pkg_1: { + default: (_cwd, _args) => { + args = _args; + return Promise.resolve(); + } + } + })(async () => { + process.argv = ['hexo', 'new', '--slug', '123', 'test']; + // @ts-ignore + cli(null, null); + args.slug.should.eql('123'); + process.argv = []; + }); + }); + + it('s - number (issue #4334)', async () => { + let args; + const cli = rewire('hexo-cli'); + return cli.__with__({ + find_pkg_1: { + default: (_cwd, _args) => { + args = _args; + return Promise.resolve(); + } + } + })(async () => { + process.argv = ['hexo', 'new', '-s', '123', 'test']; + // @ts-ignore + cli(null, null); + args.s.should.eql('123'); + process.argv = []; + }); + }); });