From cc93ae3a332c858120575e6272be431ff9fc13f2 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 3 Oct 2021 16:48:59 +0800 Subject: [PATCH] test: Add test case. --- package.json | 2 +- test/cli.test.ts | 16 ++++++++++++++++ test/index.test.ts | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/cli.test.ts diff --git a/package.json b/package.json index 239069f..060bf0c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "create-kkt", "version": "2.3.0", "description": "Creates a KKT application using the command line.", - "homepage": "https://github.com/kktjs/create-kkt", + "homepage": "https://kktjs.github.io/create-kkt", "author": "Kenny Wong (https://github.com/jaywcjlove)", "main": "lib/index.js", "license": "MIT", diff --git a/test/cli.test.ts b/test/cli.test.ts new file mode 100644 index 0000000..1be25b6 --- /dev/null +++ b/test/cli.test.ts @@ -0,0 +1,16 @@ +/** @jest-environment node */ +import { exampleHelp, run } from '../src/'; + +it('cliHelp test case', async () => { + expect(exampleHelp()).toBeUndefined(); + // process.argv.push('-v'); + // expect(await run()).toBeUndefined(); + process.argv.push('--version'); + expect(await run()).toBeUndefined(); +}); + +it('version test case', async () => { + expect(exampleHelp()).toBeUndefined(); + process.argv.push('-h'); + expect(await run()).toBeUndefined(); +}); diff --git a/test/index.test.ts b/test/index.test.ts index 7e5f906..afae16f 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -26,3 +26,24 @@ it('create project.', async () => { expect(pkg.version).toEqual('1.0.0'); expect(Object.keys(pkg)).toEqual(expect.arrayContaining(['name', 'version'])); }); + +it('create project Option appName=undefined.', async () => { + jest.spyOn(process, 'exit').mockImplementation(); + const opts: CreateOptions = { + _: [], + f: true, + force: true, + }; + await create(opts, () => {}); +}); + +it('create project Option path=undefined.', async () => { + jest.spyOn(process, 'exit').mockImplementation(); + const opts: CreateOptions = { + _: ['my-app'], + f: true, + force: true, + appName: 'my-app', + }; + await create(opts, () => {}); +});