-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[TS migration] Migrate awaitStagingDeploysTest to Typescript #37084
Merged
marcaaron
merged 7 commits into
Expensify:main
from
ruben-rebelo:ts-migration/unit-awaitStagingDeploysTest
Mar 30, 2024
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffbe73a
[TS migration] Migrate awaitStagingDeploysTest to Typescript
ruben-rebelo 760b75e
Merge branch 'main' into ts-migration/unit-awaitStagingDeploysTest
ruben-rebelo 0bb481d
[TS migration][awaitStagingDeploysTest] Removed expect error from oct…
ruben-rebelo 2835706
Merge branch 'main' into ts-migration/unit-awaitStagingDeploysTest
ruben-rebelo 887bfcd
[TS migration][awaitStagingDeploysTest] Generated github utils
ruben-rebelo b0ab451
Merge branch 'main' into ts-migration/unit-awaitStagingDeploysTest
ruben-rebelo 5e8d0ee
[TS migration] Removed AsMutable old file
ruben-rebelo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type {Writable} from 'type-fest'; | ||
|
||
const asMutable = <T>(value: T): Writable<T> => value as Writable<T>; | ||
|
||
export default asMutable; |
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,29 +1,46 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
/** | ||
* @jest-environment node | ||
*/ | ||
import * as core from '@actions/core'; | ||
import _ from 'underscore'; | ||
import asMutable from '@src/types/utils/AsMutable'; | ||
import run from '../../.github/actions/javascript/awaitStagingDeploys/awaitStagingDeploys'; | ||
import GithubUtils from '../../.github/libs/GithubUtils'; | ||
|
||
type Workflow = { | ||
workflow_id: string; | ||
branch: string; | ||
}; | ||
|
||
type WorkflowStatus = {status: string}; | ||
|
||
// Lower poll rate to speed up tests | ||
const TEST_POLL_RATE = 1; | ||
const COMPLETED_WORKFLOW = {status: 'completed'}; | ||
const INCOMPLETE_WORKFLOW = {status: 'in_progress'}; | ||
const COMPLETED_WORKFLOW: WorkflowStatus = {status: 'completed'}; | ||
const INCOMPLETE_WORKFLOW: WorkflowStatus = {status: 'in_progress'}; | ||
|
||
type MockListResponse = { | ||
data: { | ||
workflow_runs: WorkflowStatus[]; | ||
}; | ||
}; | ||
|
||
type MockedFunctionListResponse = jest.MockedFunction<() => Promise<MockListResponse>>; | ||
|
||
const consoleSpy = jest.spyOn(console, 'log'); | ||
const mockGetInput = jest.fn(); | ||
const mockListPlatformDeploysForTag = jest.fn(); | ||
const mockListPlatformDeploys = jest.fn(); | ||
const mockListPreDeploys = jest.fn(); | ||
const mockListWorkflowRuns = jest.fn().mockImplementation((args) => { | ||
const mockListPlatformDeploysForTag: MockedFunctionListResponse = jest.fn(); | ||
const mockListPlatformDeploys: MockedFunctionListResponse = jest.fn(); | ||
const mockListPreDeploys: MockedFunctionListResponse = jest.fn(); | ||
const mockListWorkflowRuns = jest.fn().mockImplementation((args: Workflow) => { | ||
const defaultReturn = Promise.resolve({data: {workflow_runs: []}}); | ||
|
||
if (!_.has(args, 'workflow_id')) { | ||
if (!args.workflow_id) { | ||
return defaultReturn; | ||
} | ||
|
||
if (!_.isUndefined(args.branch)) { | ||
if (args.branch !== undefined) { | ||
return mockListPlatformDeploysForTag(); | ||
} | ||
|
||
|
@@ -40,7 +57,7 @@ | |
|
||
beforeAll(() => { | ||
// Mock core module | ||
core.getInput = mockGetInput; | ||
asMutable(core).getInput = mockGetInput; | ||
|
||
// Mock octokit module | ||
const moctokit = { | ||
|
@@ -50,8 +67,10 @@ | |
}, | ||
}, | ||
}; | ||
|
||
// @ts-expect-error TODO: Remove this once GithubUtils (https://github.com/Expensify/App/issues/25382) is migrated to TypeScript. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's hold this PR for now |
||
GithubUtils.internalOctokit = moctokit; | ||
GithubUtils.POLL_RATE = TEST_POLL_RATE; | ||
}); | ||
|
||
beforeEach(() => { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is a bit different, this is more accurate:
But the suggested change should work, right?