-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'serverless-flare' into nicholas.hulston/serverless-flar…
…e/autodiscover-infrastructure-files
- Loading branch information
Showing
46 changed files
with
972 additions
and
611 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 @@ | ||
import * as simpleGit from 'simple-git' | ||
|
||
import {getCommitInfo, gitRemote, newSimpleGit, stripCredentials} from '../git' | ||
import {getCommitInfo, newSimpleGit, stripCredentials} from '../git' | ||
|
||
interface MockConfig { | ||
hash?: string | ||
|
@@ -9,6 +9,8 @@ interface MockConfig { | |
} | ||
|
||
const createMockSimpleGit = (conf: MockConfig) => ({ | ||
// eslint-disable-next-line no-null/no-null | ||
getConfig: (_: string) => ({value: null}), | ||
getRemotes: async (_: boolean) => { | ||
if (conf.remotes === undefined) { | ||
throw Error('Unexpected call to getRemotes') | ||
|
@@ -32,31 +34,6 @@ const createMockSimpleGit = (conf: MockConfig) => ({ | |
}) | ||
|
||
describe('git', () => { | ||
describe('gitRemote', () => { | ||
test('should choose the remote named origin', async () => { | ||
const mock = createMockSimpleGit({ | ||
remotes: [ | ||
{name: 'first', refs: {push: 'remote1'}}, | ||
{name: 'origin', refs: {push: 'remote2'}}, | ||
], | ||
}) as any | ||
const remote = await gitRemote(mock) | ||
|
||
expect(remote).toBe('remote2') | ||
}) | ||
test('should choose the first remote', async () => { | ||
const mock = createMockSimpleGit({ | ||
remotes: [ | ||
{name: 'first', refs: {push: 'remote1'}}, | ||
{name: 'second', refs: {push: 'remote2'}}, | ||
], | ||
}) as any | ||
const remote = await gitRemote(mock) | ||
|
||
expect(remote).toBe('remote1') | ||
}) | ||
}) | ||
|
||
describe('stripCredentials: git protocol', () => { | ||
test('should return the same value', () => { | ||
const input = '[email protected]:user/project.git' | ||
|
@@ -115,15 +92,15 @@ describe('git', () => { | |
|
||
describe('newSimpleGit', () => { | ||
test('should throw an error if git is not installed', async () => { | ||
jest.spyOn(simpleGit, 'gitP').mockImplementation(() => { | ||
jest.spyOn(simpleGit, 'simpleGit').mockImplementation(() => { | ||
throw Error('gitp error') | ||
}) | ||
await expect(newSimpleGit()).rejects.toThrow('gitp error') | ||
}) | ||
|
||
test('should throw an error if revparse throws an error', async () => { | ||
const mock = createMockSimpleGit({}) as any | ||
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock) | ||
jest.spyOn(simpleGit, 'simpleGit').mockReturnValue(mock) | ||
jest.spyOn(mock, 'revparse').mockImplementation(async () => { | ||
throw Error('revparse error') | ||
}) | ||
|
@@ -133,7 +110,7 @@ describe('git', () => { | |
|
||
test('should not throw any errors', async () => { | ||
const mock = createMockSimpleGit({}) as any | ||
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock) | ||
jest.spyOn(simpleGit, 'simpleGit').mockReturnValue(mock) | ||
jest.spyOn(mock, 'revparse').mockResolvedValue('1234') | ||
|
||
await expect(newSimpleGit()).resolves.not.toThrow() | ||
|
Oops, something went wrong.