diff --git a/src/utils/git.ts b/src/utils/git.ts index ead5a94..19102ce 100644 --- a/src/utils/git.ts +++ b/src/utils/git.ts @@ -18,8 +18,8 @@ export function gitIgnorePath(ignorePath: string) { * - user/repo */ export function getRepoPath(repo: string) { - if (/^[0-9a-zA-Z](-[0-9a-zA-Z]+|[0-9a-zA-Z]*)[\/\\][0-9a-zA-Z\.\-_]+$/.test(repo)) { - return `https://github.com/${repo.replace(/\\/g, '/')}` + if (/^[0-9a-zA-Z](-[0-9a-zA-Z]+|[0-9a-zA-Z]*)\/[0-9a-zA-Z\.\-_]+$/.test(repo)) { + return `https://github.com/${repo}` } - return repo.replace(/\\/g, '/') + return repo } diff --git a/tests/create.test.ts b/tests/create.test.ts index ed47d91..9ac862d 100644 --- a/tests/create.test.ts +++ b/tests/create.test.ts @@ -33,21 +33,21 @@ describe('create', () => { } }) - it('help', { timeout: 10000 }, async () => { + it('help create', { timeout: 10000 }, async () => { const { stdout } = await execaUniapp('help create') assert.equal(stdout, HELP_TEXT) }) - it('--help', { timeout: 10000 }, async () => { + it('create --help', { timeout: 10000 }, async () => { const { stdout } = await execaUniapp('create --help') assert.equal(stdout, HELP_TEXT) }) - it('None arguments', { timeout: 10000 }, () => { + it('create none arguments', { timeout: 10000 }, () => { assert.rejects(() => execaUniapp('create'), `error: missing required argument 'project-name'\n\n${HELP_TEXT}`) }) - it('Invalid project name', { timeout: 10000 }, () => { + it('create invalid project name', { timeout: 10000 }, () => { assert.rejects( () => execaUniapp('create 你好'), (err: SyncResult) => { @@ -61,7 +61,7 @@ describe('create', () => { ) }) - it('create', { timeout: 10000 }, () => { + it('create no template', { timeout: 10000 }, () => { assert.throws( () => execaUniappSync('create test-project'), `\x1B[34m?\x1B[39m \x1B[1m请选择新建项目的模板\x1B[22m \x1B[2m(Use arrow keys)\x1B[22m\n\x1B[36m❯ vitesse\x1B[39m @@ -73,6 +73,13 @@ describe('create', () => { ) }) + it('--template invalid repository', { timeout: 10000 }, () => { + assert.rejects( + () => execaUniapp('create test-project-invlide-repository --template xxxx'), + "fatal: repository 'xxxx' does not exist", + ) + }) + it('--template branch', { timeout: 30000 }, async () => { const { stdout } = await execaUniapp('create test-project-branch --template dcloudio/uni-preset-vue#vite-ts') assert.equal( diff --git a/tests/version.test.ts b/tests/version.test.ts index 2411010..baf4729 100644 --- a/tests/version.test.ts +++ b/tests/version.test.ts @@ -3,7 +3,7 @@ import assert from 'node:assert' import { execaUniapp } from './helper.js' import { type PackageJson, readPackageJSON } from 'pkg-types' -describe('help', async () => { +describe('version', async () => { let packages = {} as PackageJson before(async () => {