Skip to content

Commit

Permalink
add test: create --template invalid repository
Browse files Browse the repository at this point in the history
  • Loading branch information
wtto00 committed Oct 27, 2024
1 parent 3670457 commit 0535f23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 12 additions & 5 deletions tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0535f23

Please sign in to comment.