upgrade module to esm and update dependencies (#2463)

* upgrade module to esm so I can update dependencies

* fix ci failures
This commit is contained in:
Aiqiao Yan
2026-06-16 17:10:58 -04:00
committed by GitHub
parent 537c7ef99c
commit d914b262ff
57 changed files with 29272 additions and 24100 deletions

View File

@@ -1,10 +1,12 @@
import * as github from '@actions/github'
import {assertSafePrCheckout} from '../lib/unsafe-pr-checkout-helper'
// Shallow clone original @actions/github context
const originalContext = {...github.context}
const originalEventName = github.context.eventName
const originalPayload = github.context.payload
import {
jest,
describe,
it,
expect,
beforeAll,
afterEach,
afterAll
} from '@jest/globals'
const BASE_REPO_ID = 100
const FORK_REPO_ID = 200
@@ -15,9 +17,30 @@ const WORKFLOW_RUN_HEAD_COMMIT_SHA = '4444444444444444444444444444444444444444'
const BASE_QUALIFIED_REPO = 'some-owner/some-repo'
const FORK_QUALIFIED_REPO = 'another-repo/fork'
// Mutable mock context
const mockContext: any = {
eventName: '',
payload: {},
repo: {owner: 'some-owner', repo: 'some-repo'},
ref: '',
sha: ''
}
jest.unstable_mockModule('@actions/github', () => ({
context: mockContext
}))
// Dynamic imports after mocking
const {assertSafePrCheckout} = await import(
'../src/unsafe-pr-checkout-helper.js'
)
const originalEventName = mockContext.eventName
const originalPayload = mockContext.payload
function setContext(eventName: string, payload: object): void {
;(github.context as {eventName: string}).eventName = eventName
;(github.context as {payload: object}).payload = payload
mockContext.eventName = eventName
mockContext.payload = payload
}
function forkPullRequestTargetPayload(): object {
@@ -59,22 +82,17 @@ function forkWorkflowRunPayload(): object {
describe('unsafe-pr-checkout-helper', () => {
beforeAll(() => {
jest.spyOn(github.context, 'repo', 'get').mockReturnValue({
owner: 'some-owner',
repo: 'some-repo'
})
mockContext.repo = {owner: 'some-owner', repo: 'some-repo'}
})
afterEach(() => {
;(github.context as {eventName: string}).eventName = originalEventName
;(github.context as {payload: object}).payload = originalPayload
mockContext.eventName = originalEventName
mockContext.payload = originalPayload
})
afterAll(() => {
;(github.context as {eventName: string}).eventName =
originalContext.eventName
;(github.context as {payload: object}).payload = originalContext.payload
jest.restoreAllMocks()
mockContext.eventName = originalEventName
mockContext.payload = originalPayload
})
it('allows pull_request events untouched', () => {