generated from actions/typescript-action
-
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.
Merge pull request #45 from crs-k/fix-unit-tests
Fix unit tests
- Loading branch information
Showing
21 changed files
with
321 additions
and
374 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist/ | ||
lib/ | ||
node_modules/ | ||
src/functions/__mocks__ | ||
jest.config.js |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const context = { | ||
repo: { | ||
owner: 'owner', | ||
repo: 'repo' | ||
} | ||
} | ||
|
||
const github = { | ||
rest: { | ||
repos: { | ||
get: jest.fn(), | ||
listReleases: jest.fn(), | ||
generateReleaseNotes: jest.fn(), | ||
updateRelease: jest.fn(), | ||
createRelease: jest.fn() | ||
} | ||
} | ||
} | ||
|
||
export const getOctokit = jest.fn().mockImplementation(() => github) |
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,36 @@ | ||
jest.mock('@actions/core') | ||
jest.mock('../../src/functions/get-default-branch') | ||
|
||
const core = require('@actions/core') | ||
import {createDraft} from '../../src/functions/create-draft' | ||
import {github} from '../../src/functions/get-context' | ||
|
||
jest.mock('../../src/functions/get-context') | ||
let targetTag = 'v1.0.0' | ||
let commitish = 'main' | ||
|
||
describe('Create Draft Function', () => { | ||
test('createRelease endpoint is called', async () => { | ||
await createDraft(targetTag) | ||
|
||
expect(github.rest.repos.createRelease).toHaveBeenCalledWith({ | ||
owner: 'owner', | ||
repo: 'repo', | ||
tag_name: targetTag, | ||
name: targetTag, | ||
target_commitish: commitish, | ||
draft: true, | ||
generate_release_notes: true | ||
}) | ||
}) | ||
|
||
test('Infos are set', async () => { | ||
core.info = jest.fn() | ||
await createDraft(targetTag) | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Creating Release Draft...') | ||
expect(core.info).toHaveBeenNthCalledWith(2, `Release ID: '0'`) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `HTML URL: ''`) | ||
expect(core.info).toHaveBeenNthCalledWith(4, `Upload URL: ''`) | ||
}) | ||
}) |
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,30 @@ | ||
jest.mock('@actions/core') | ||
|
||
const core = require('@actions/core') | ||
import {createNextTag} from '../../src/functions/create-next-tag' | ||
|
||
describe('Create Next Tag Function', () => { | ||
test('Infos are set (semver compliant tag)', async () => { | ||
let targetTag = 'v1.2.3' | ||
core.info = jest.fn() | ||
await createNextTag(targetTag) | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Generating Next tag...') | ||
expect(core.info).toHaveBeenNthCalledWith(2, `Bump Type: patch`) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `Next tag: v1.2.4`) | ||
}) | ||
|
||
test('Infos are set (semver noncompliant tag)', async () => { | ||
let targetTag = 'BAD' | ||
core.info = jest.fn() | ||
await createNextTag(targetTag) | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Generating Next tag...') | ||
expect(core.info).toHaveBeenNthCalledWith( | ||
2, | ||
`Next tag failed to generate. Defaulting to v0.1.0` | ||
) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `Bump Type: patch`) | ||
expect(core.info).toHaveBeenNthCalledWith(4, `Next tag: v0.1.0`) | ||
}) | ||
}) |
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,35 @@ | ||
jest.mock('@actions/core') | ||
jest.mock('@actions/github') | ||
jest.mock('assert') | ||
|
||
const core = require('@actions/core') | ||
import {createNotes} from '../../src/functions/create-notes' | ||
import {github} from '../../src/functions/get-context' | ||
|
||
jest.mock('../../src/functions/get-context') | ||
let targetTag = 'v1.0.0' | ||
|
||
describe('Create Notes Function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
test('createNotes endpoint is called', async () => { | ||
await createNotes(targetTag) | ||
|
||
expect(github.rest.repos.generateReleaseNotes).toHaveBeenCalledWith({ | ||
owner: 'owner', | ||
repo: 'repo', | ||
tag_name: targetTag | ||
}) | ||
}) | ||
|
||
test('Infos are set', async () => { | ||
core.info = jest.fn() | ||
await createNotes(targetTag) | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Generating Release Notes...') | ||
expect(core.info).toHaveBeenNthCalledWith(2, `Release Notes failed to generate.`) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `Generated name: 'Unnamed'`) | ||
expect(core.info).toHaveBeenNthCalledWith(4, `Generated body: 'Unnamed'`) | ||
}) | ||
}) |
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,12 @@ | ||
jest.mock('@actions/core') | ||
|
||
const core = require('@actions/core') | ||
import {github, owner, repo} from '../../src/functions/get-context' | ||
|
||
describe('Get Context Function', () => { | ||
test('Mock context check', async () => { | ||
expect(github).toBeTruthy | ||
expect(owner).toBe('owner') | ||
expect(repo).toBe('repo') | ||
}) | ||
}) |
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,32 @@ | ||
jest.mock('@actions/core') | ||
jest.mock('@actions/github') | ||
jest.mock('assert') | ||
|
||
const core = require('@actions/core') | ||
const branch = require('../../src/functions/get-default-branch') | ||
import {getDefaultBranch} from '../../src/functions/get-default-branch' | ||
import {github} from '../../src/functions/get-context' | ||
|
||
jest.mock('../../src/functions/get-context') | ||
|
||
describe('Get Default Branch Function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
test('getDefaultBranch endpoint is called', async () => { | ||
await getDefaultBranch() | ||
|
||
expect(github.rest.repos.get).toHaveBeenCalledWith({ | ||
owner: 'owner', | ||
repo: 'repo' | ||
}) | ||
}) | ||
|
||
test('Infos are set', async () => { | ||
core.info = jest.fn() | ||
await getDefaultBranch() | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Retrieving the default branch name...') | ||
expect(core.info).toHaveBeenNthCalledWith(2, `Default branch: ''`) | ||
}) | ||
}) |
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,39 @@ | ||
jest.mock('@actions/core') | ||
jest.mock('@actions/github') | ||
jest.mock('assert') | ||
|
||
const core = require('@actions/core') | ||
import {getRecentRelease} from '../../src/functions/get-recent-release' | ||
import {github} from '../../src/functions/get-context' | ||
|
||
jest.mock('../../src/functions/get-context') | ||
|
||
describe('Get Recent Release Function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
test('listReleases endpoint is called', async () => { | ||
await getRecentRelease() | ||
|
||
expect(github.rest.repos.listReleases).toHaveBeenCalledWith({ | ||
owner: 'owner', | ||
repo: 'repo', | ||
per_page: 1, | ||
page: 1 | ||
}) | ||
}) | ||
|
||
test('Infos are set', async () => { | ||
core.info = jest.fn() | ||
await getRecentRelease() | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Retrieving the most recent release...') | ||
expect(core.info).toHaveBeenNthCalledWith( | ||
2, | ||
`Previous release cannot be found with reason Cannot read properties of undefined (reading 'data'). Defaulting tag.` | ||
) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `Tag Name: '0.1.0'`) | ||
expect(core.info).toHaveBeenNthCalledWith(4, `Draft: 'false'`) | ||
expect(core.info).toHaveBeenNthCalledWith(5, `Release ID: '0'`) | ||
}) | ||
}) |
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,52 @@ | ||
jest.mock('@actions/core') | ||
jest.mock('@actions/github') | ||
jest.mock('assert') | ||
|
||
const core = require('@actions/core') | ||
import {updateDraft} from '../../src/functions/update-draft' | ||
import {github} from '../../src/functions/get-context' | ||
|
||
jest.mock('../../src/functions/get-context') | ||
let targetTag = 'v1.0.0' | ||
let updateName = 'updateName' | ||
let updateBody = 'updateBody' | ||
let prevReleaseId = 0 | ||
|
||
describe('Update Draft Function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
test('updateDraft endpoint is called', async () => { | ||
await updateDraft(targetTag, updateName, updateBody, prevReleaseId) | ||
|
||
expect(github.rest.repos.updateRelease).toHaveBeenCalledWith({ | ||
owner: 'owner', | ||
repo: 'repo', | ||
release_id: prevReleaseId, | ||
tag_name: targetTag, | ||
name: updateName, | ||
body: updateBody, | ||
draft: true | ||
}) | ||
}) | ||
|
||
test('Infos are set', async () => { | ||
core.info = jest.fn() | ||
await updateDraft(targetTag, updateName, updateBody, prevReleaseId) | ||
|
||
expect(core.info).toHaveBeenNthCalledWith(1, 'Updating Release Draft...') | ||
expect(core.info).toHaveBeenNthCalledWith(2, `Release ID: '0'`) | ||
expect(core.info).toHaveBeenNthCalledWith(3, `HTML URL: ''`) | ||
expect(core.info).toHaveBeenNthCalledWith(4, `Upload URL: ''`) | ||
}) | ||
|
||
/* test('Outputs are set', async () => { | ||
core.output = jest.fn() | ||
await updateDraft(targetTag, updateName, updateBody, prevReleaseId) | ||
expect(core.output).toHaveBeenNthCalledWith(1, 'Updating Release Draft...') | ||
expect(core.output).toHaveBeenNthCalledWith(2, `Release ID: '0'`) | ||
expect(core.output).toHaveBeenNthCalledWith(3, `HTML URL: ''`) | ||
expect(core.output).toHaveBeenNthCalledWith(4, `Upload URL: ''`) | ||
}) */ | ||
}) |
Oops, something went wrong.