-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aa33d4
commit 12658b6
Showing
6 changed files
with
196 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
/** @jest-environment node */ | ||
import { exampleHelp, run } from '../src/'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
it('cliHelp test case', async () => { | ||
expect(exampleHelp()).toBeUndefined(); | ||
// process.argv.push('-v'); | ||
// expect(await run()).toBeUndefined(); | ||
process.argv.push('--version'); | ||
expect(await run()).toBeUndefined(); | ||
}); | ||
console.log = jest.fn(); | ||
|
||
const argv = process.argv.slice(0, 2); | ||
|
||
it('version test case', async () => { | ||
expect(exampleHelp()).toBeUndefined(); | ||
process.argv.push('-h'); | ||
expect(await run()).toBeUndefined(); | ||
it('create project. 1', async () => { | ||
process.argv = argv; | ||
process.argv.push('my-app2'); | ||
process.argv.push('-f'); | ||
process.argv.push('--output'); | ||
process.argv.push('test'); | ||
// console.log(process.argv) | ||
await import('../src/cli'); | ||
// console.log(path.resolve(__dirname, 'my-app2')) | ||
expect(await fs.existsSync(path.resolve(__dirname, 'my-app2'))).toBeTruthy(); | ||
await fs.remove('test/my-app2'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** @jest-environment node */ | ||
import fs from 'fs-extra'; | ||
import { create, CreateOptions } from '../src/create'; | ||
import { helpExample } from '../src'; | ||
|
||
console.log = jest.fn(); | ||
|
||
it('create project. 1', async () => { | ||
const opts: CreateOptions = {}; | ||
await create(opts, ''); | ||
// @ts-ignore | ||
expect( | ||
console.log.mock.calls[0][0].indexOf('Please specify the project directory name') > -1, | ||
).toBeTruthy(); | ||
}); | ||
|
||
it('create project. 2', async () => { | ||
const opts: CreateOptions = {}; | ||
await create(opts, helpExample); | ||
// @ts-ignore | ||
expect(console.log.mock.calls[0][0].indexOf('Example:') > -1).toBeTruthy(); | ||
}); | ||
|
||
it('create project. options => appName', async () => { | ||
const opts: CreateOptions = { appName: 'my-app' }; | ||
await create(opts, helpExample); | ||
// @ts-ignore | ||
expect(console.log.mock.calls[0][0].indexOf('my-app') > -1).toBeTruthy(); | ||
}); | ||
|
||
it('create project. options => appName', async () => { | ||
const opts: CreateOptions = { appName: [] as any }; | ||
await create(opts, ''); | ||
// @ts-ignore | ||
expect(console.log.mock.calls[0][0].indexOf('The name directory nam') > -1).toBeTruthy(); | ||
}); | ||
|
||
it('create project. options => path', async () => { | ||
const opts: CreateOptions = { appName: 'my-app', path: [] as any }; | ||
await create(opts, ''); | ||
// @ts-ignore | ||
expect(console.log.mock.calls[0][0].indexOf('Please specify download address') > -1).toBeTruthy(); | ||
}); | ||
|
||
it('create project. options => force/example', async () => { | ||
const mockExit = jest.spyOn(process, 'exit').mockImplementation(); | ||
const opts: CreateOptions = { | ||
force: true, | ||
output: 'test', | ||
appName: 'my-app', | ||
path: 'https://kktjs.github.io/zip/', | ||
}; | ||
await create(opts, ''); | ||
expect(mockExit).toHaveBeenCalledWith(1); | ||
mockExit.mockRestore(); | ||
}); | ||
|
||
it('create project. options => force', async () => { | ||
await fs.ensureDir('test/my-app'); | ||
const mockExit = jest.spyOn(process, 'exit').mockImplementation(); | ||
const opts: CreateOptions = { | ||
output: 'test', | ||
appName: 'my-app', | ||
path: 'https://kktjs.github.io/zip/', | ||
}; | ||
await create(opts, ''); | ||
// @ts-ignore | ||
expect( | ||
console.log.mock.calls[0][0].indexOf("Looks like there's already a directory called") > -1, | ||
).toBeTruthy(); | ||
expect(mockExit).toHaveBeenCalledWith(1); | ||
mockExit.mockRestore(); | ||
}); | ||
|
||
it('create project. options => example', async () => { | ||
const opts: CreateOptions = { | ||
force: true, | ||
output: 'test', | ||
example: 'basic', | ||
appName: 'my-app', | ||
path: 'https://kktjs.github.io/zip/', | ||
}; | ||
await create(opts, ''); | ||
// @ts-ignore | ||
expect(console.log.mock.calls[0][0].indexOf('Success! Created') > -1).toBeTruthy(); | ||
await fs.remove('test/my-app'); | ||
}); |
Oops, something went wrong.