-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tests): add context tests and switch to vitest #102
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,51 @@ | ||
import { merge } from 'ts-deepmerge'; | ||
import { vi } from 'vitest'; | ||
import type { Config } from '../../src/config'; | ||
|
||
type InputMap = { | ||
[key: string]: string; | ||
}; | ||
|
||
const defaultInputs: InputMap = { | ||
'major-keywords': 'BREAKING CHANGE,!', | ||
'minor-keywords': 'feat,feature', | ||
'patch-keywords': 'fix,chore', | ||
'default-first-tag': 'v0.1.0', | ||
'terraform-docs-version': 'v0.16.0', | ||
'delete-legacy-tags': 'false', | ||
'disable-wiki': 'false', | ||
'wiki-sidebar-changelog-max': '10', | ||
'disable-branding': 'false', | ||
'module-change-exclude-patterns': '.gitignore,*.md', | ||
'module-asset-exclude-patterns': 'tests/**,examples/**', | ||
github_token: 'test-token', | ||
}; | ||
|
||
const defaultConfig: Config = { | ||
majorKeywords: ['BREAKING CHANGE', '!'], | ||
minorKeywords: ['feat', 'feature'], | ||
patchKeywords: ['fix', 'chore'], | ||
defaultFirstTag: 'v0.1.0', | ||
terraformDocsVersion: 'v0.19.0', | ||
deleteLegacyTags: false, | ||
disableWiki: false, | ||
wikiSidebarChangelogMax: 10, | ||
disableBranding: false, | ||
moduleChangeExcludePatterns: ['.gitignore', '*.md'], | ||
moduleAssetExcludePatterns: ['tests/**', 'examples/**'], | ||
githubToken: 'ghp_test_token_2c6912E7710c838347Ae178B4', | ||
}; | ||
|
||
// Create a mock factory function | ||
export const createConfigMock = (overrides: Partial<Config> = {}) => ({ | ||
...defaultConfig, | ||
...overrides, | ||
}); | ||
|
||
// Create a mock inputs factory function | ||
export function createInputsMock(inputs: InputMap = {}): InputMap { | ||
return merge(defaultInputs, inputs); | ||
} | ||
|
||
// Create the mock handler | ||
export const configMock = vi.fn(() => defaultConfig); |
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,93 @@ | ||
import { merge } from 'ts-deepmerge'; | ||
import { vi } from 'vitest'; | ||
import type { Context } from '../../src/context'; | ||
|
||
// Only mock the methods we need | ||
const octokitMock = { | ||
rest: { | ||
git: { | ||
deleteRef: vi.fn(), | ||
}, | ||
issues: { | ||
createComment: vi.fn(), | ||
deleteComment: vi.fn(), | ||
listComments: vi.fn(), | ||
listForRepo: vi.fn().mockResolvedValue({ | ||
data: [ | ||
{ | ||
number: 1, | ||
title: 'issue 1', | ||
body: 'issue 1 body', | ||
}, | ||
{ | ||
number: 2, | ||
title: 'issue 2', | ||
body: 'issue 2 body', | ||
}, | ||
], | ||
}), | ||
}, | ||
pulls: { | ||
listCommits: vi.fn().mockResolvedValue({ | ||
data: [ | ||
{ sha: 'sha1', committer: { name: '<NAME>' } }, | ||
{ sha: 'sha2', committer: { name: '<NAME>' } }, | ||
], | ||
}), | ||
listFiles: vi.fn().mockResolvedValue({ | ||
data: [{ filename: 'file1.txt' }, { filename: 'file2.txt' }], | ||
}), | ||
}, | ||
repos: { | ||
getCommit: vi.fn().mockResolvedValue({ | ||
data: { | ||
sha: '1234567890', | ||
}, | ||
}), | ||
listTags: vi.fn(), | ||
listReleases: vi.fn(), | ||
}, | ||
}, | ||
paginate: vi.fn(), | ||
}; | ||
|
||
const defaultContext: Context = { | ||
repo: { | ||
owner: 'techpivot', | ||
repo: 'terraform-module-releaser', | ||
}, | ||
repoUrl: 'https://github.com/techpivot/terraform-module-releaser', | ||
octokit: octokitMock as unknown as Context['octokit'], | ||
prNumber: 1, | ||
prTitle: 'Test Pull Request', | ||
prBody: 'This is a test pull request body.', | ||
issueNumber: 1, | ||
workspaceDir: '/path/to/workspace', | ||
isPrMergeEvent: false, | ||
}; | ||
|
||
const defaultPullRequestPayload = { | ||
action: 'opened', | ||
pull_request: { | ||
number: 123, | ||
title: 'Test PR', | ||
body: 'Test PR body', | ||
merged: false, | ||
}, | ||
repository: { | ||
full_name: 'techpivot/terraform-module-releaser', | ||
}, | ||
}; | ||
|
||
// Create a mock context factory function | ||
//export function createContextMock(overrides: Partial<Context> = {}): Context { | ||
// return merge(defaultContext, overrides); | ||
//} | ||
|
||
// Create a mock pull request factory function | ||
export function createPullRequestMock(overrides = {}) { | ||
return merge(defaultPullRequestPayload, overrides); | ||
} | ||
|
||
// Create the mock handler | ||
export const contextMock = vi.fn(() => defaultContext); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / SonarCloud
GitHub tokens should not be disclosed