-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from deinsoftware/dev
fix: 🐛 fix open repo with ssh
- Loading branch information
Showing
5 changed files
with
164 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "swpm", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
|
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,135 @@ | ||
import { afterEach, it, describe, expect, vi } from 'vitest' | ||
import { pathExists } from 'find-up' | ||
import { getCommandResult } from './cmds.js' | ||
import { getReposStatus, hasRepository } from './repos.js' | ||
|
||
describe('getReposStatus()', () => { | ||
vi.mock('./cmds.ts', async () => { | ||
const mod = await vi.importActual<typeof import('./cmds.ts')>('./cmds.ts') | ||
return { | ||
...mod, | ||
getCommandResult: vi.fn() | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('should return ssh repository object', async () => { | ||
// Mock the dependencies | ||
vi.mocked(getCommandResult) | ||
.mockReturnValueOnce('[email protected]:username/repo.git') | ||
.mockReturnValueOnce('main') | ||
|
||
// Call the function | ||
const result = await getReposStatus() | ||
|
||
// Assertions | ||
expect(getCommandResult).toHaveBeenCalledTimes(2) | ||
expect(result).toEqual({ | ||
url: 'https://github.com/username/repo', | ||
provider: 'github', | ||
current: 'main' | ||
}) | ||
|
||
vi.mocked(getCommandResult).mockRestore() | ||
}) | ||
|
||
it('should return ssh repository object without .git extension', async () => { | ||
// Mock the dependencies | ||
vi.mocked(getCommandResult) | ||
.mockReturnValueOnce('[email protected]:username/repo') | ||
.mockReturnValueOnce('main') | ||
|
||
// Call the function | ||
const result = await getReposStatus() | ||
|
||
// Assertions | ||
expect(getCommandResult).toHaveBeenCalledTimes(2) | ||
expect(result).toEqual({ | ||
url: 'https://github.com/username/repo', | ||
provider: 'github', | ||
current: 'main' | ||
}) | ||
|
||
vi.mocked(getCommandResult).mockRestore() | ||
}) | ||
|
||
it('should return http repository object', async () => { | ||
// Mock the dependencies | ||
vi.mocked(getCommandResult) | ||
.mockReturnValueOnce('https://github.com/username/repo.git') | ||
.mockReturnValueOnce('main') | ||
|
||
// Call the function | ||
const result = await getReposStatus() | ||
|
||
// Assertions | ||
expect(getCommandResult).toHaveBeenCalledTimes(2) | ||
expect(result).toEqual({ | ||
url: 'https://github.com/username/repo', | ||
provider: 'github', | ||
current: 'main' | ||
}) | ||
|
||
vi.mocked(getCommandResult).mockRestore() | ||
}) | ||
|
||
it('should return http repository object without .git extension', async () => { | ||
// Mock the dependencies | ||
vi.mocked(getCommandResult) | ||
.mockReturnValueOnce('https://github.com/username/repo') | ||
.mockReturnValueOnce('main') | ||
|
||
// Call the function | ||
const result = await getReposStatus() | ||
|
||
// Assertions | ||
expect(getCommandResult).toHaveBeenCalledTimes(2) | ||
expect(result).toEqual({ | ||
url: 'https://github.com/username/repo', | ||
provider: 'github', | ||
current: 'main' | ||
}) | ||
|
||
vi.mocked(getCommandResult).mockRestore() | ||
}) | ||
}) | ||
|
||
describe('hasRepository()', () => { | ||
vi.mock('find-up', async () => { | ||
const mod = await vi.importActual<typeof import('find-up')>('find-up') | ||
|
||
return { | ||
...mod, | ||
pathExists: await vi.fn() | ||
} | ||
}) | ||
|
||
const pathMock = vi.mocked(pathExists) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('should found a repository in current path', async () => { | ||
vi.mocked(pathExists).mockResolvedValue(true) | ||
const result = await hasRepository() | ||
expect(pathMock).toHaveBeenCalledTimes(1) | ||
expect(result).toBeTruthy() | ||
|
||
vi.mocked(pathExists).mockRestore() | ||
}) | ||
|
||
it('should found not found a repository in current path', async () => { | ||
vi.mocked(pathExists).mockResolvedValue(false) | ||
const result = await hasRepository() | ||
expect(pathMock).toHaveBeenCalledTimes(1) | ||
expect(result).toBeFalsy() | ||
|
||
vi.mocked(pathExists).mockRestore() | ||
}) | ||
}) |
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