-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add context tests and switch to vitest
- Switched from Jest to Vitest for faster test execution. - Improved config and context providers for consistent behavior. - Enhanced testing with a generic test setup and utilities. - Added numerous tests to cover context functionality.
- Loading branch information
Showing
15 changed files
with
2,330 additions
and
1,966 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 |
---|---|---|
@@ -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', | ||
Check failure Code scanning / SonarCloud GitHub tokens should not be disclosed High test
Make sure this Github token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
}; | ||
|
||
// 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.