mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2026-05-31 00:12:03 +08:00
* chore: merge all Dependabot dependency updates with fixes - Update @actions/core/exec/github/io to v3/v9 (ESM-only) - Update @eslint/js to v10, @typescript-eslint/* to 8.58, eslint-plugin-jest/prettier - Update jest 29→30, typescript 5.8→6.0, @types/jest/node, prettier, rimraf, ts-jest - Update lodash 4.17→4.18 (yarn.lock only) - Add CJS test stubs for ESM-only @actions/* packages - Update tsconfig.json: target es2022, add types for node+jest - Update jest.config.js: moduleNameMapper for stubs, remove jest-circus runner - Fix new lint rules: preserve-caught-error and no-useless-assignment Agent-Logs-Url: https://github.com/JamesIves/github-pages-deploy-action/sessions/2a6d68c0-eab5-4c98-a927-2525b124ca87 Co-authored-by: JamesIves <10888441+JamesIves@users.noreply.github.com> * refactor: convert project to proper ESM - package.json: add "type": "module" for ESM runtime + nodenext compilation - tsconfig.json: module/moduleResolution → nodenext (ESM output with .js extensions) - src/*.ts: add .js extensions to all relative imports - __tests__/*.test.ts: add .js to relative imports, remove jest.mock() factories for @actions/* - jest.config.js → jest.config.cjs: CJS jest config, moduleNameMapper strips .js for ts-jest - __mocks__/@actions/*.js + package.json: proper Jest manual mocks (CJS, with functional implementations for integration tests) replacing __tests__/stubs/ workaround - eslint.config.mjs: ignore __mocks__/** instead of __tests__/stubs/** Agent-Logs-Url: https://github.com/JamesIves/github-pages-deploy-action/sessions/c73b8f61-87f7-4eab-8e99-d363a69f6e66 Co-authored-by: JamesIves <10888441+JamesIves@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JamesIves <10888441+JamesIves@users.noreply.github.com>
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
// Initial env variable setup for tests.
|
|
process.env['INPUT_FOLDER'] = 'build'
|
|
process.env['GITHUB_SHA'] = '123'
|
|
process.env['INPUT_DEBUG'] = 'debug'
|
|
process.env['GITHUB_REF_NAME'] = 'test'
|
|
process.env['RUNNER_OS'] = 'Linux'
|
|
process.env['CI'] = 'true'
|
|
|
|
import '../src/main.js'
|
|
import {action, TestFlag} from '../src/constants.js'
|
|
import run from '../src/lib.js'
|
|
import {execute} from '../src/execute.js'
|
|
import {rmRF} from '@actions/io'
|
|
import {setFailed, exportVariable} from '@actions/core'
|
|
|
|
const originalAction = JSON.stringify(action)
|
|
|
|
jest.mock('../src/execute', () => ({
|
|
execute: jest.fn(() => ({stdout: '', stderr: ''}))
|
|
}))
|
|
|
|
jest.mock('@actions/io')
|
|
|
|
jest.mock('@actions/core')
|
|
|
|
describe('main', () => {
|
|
afterEach(() => {
|
|
Object.assign(action, JSON.parse(originalAction))
|
|
})
|
|
|
|
it('should run through the commands', async () => {
|
|
Object.assign(action, {
|
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
|
folder: '.github/docs',
|
|
branch: 'branch',
|
|
token: '123',
|
|
hostname: 'github.com',
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
},
|
|
isTest: TestFlag.NONE,
|
|
debug: true
|
|
})
|
|
await run(action)
|
|
expect(execute).toHaveBeenCalledTimes(19)
|
|
expect(rmRF).toHaveBeenCalledTimes(1)
|
|
expect(exportVariable).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should run through the commands and succeed', async () => {
|
|
Object.assign(action, {
|
|
hostname: 'github.com',
|
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
|
folder: '.github/docs',
|
|
branch: 'branch',
|
|
token: '123',
|
|
sshKey: true,
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
},
|
|
isTest: TestFlag.HAS_CHANGED_FILES
|
|
})
|
|
await run(action)
|
|
expect(execute).toHaveBeenCalledTimes(22)
|
|
expect(rmRF).toHaveBeenCalledTimes(1)
|
|
expect(exportVariable).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should throw if an error is encountered', async () => {
|
|
Object.assign(action, {
|
|
hostname: 'github.com',
|
|
folder: '.github/docs',
|
|
branch: 'branch',
|
|
token: null,
|
|
sshKey: null,
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
},
|
|
isTest: TestFlag.HAS_CHANGED_FILES
|
|
})
|
|
await run(action)
|
|
expect(execute).toHaveBeenCalledTimes(0)
|
|
expect(setFailed).toHaveBeenCalledTimes(1)
|
|
expect(exportVariable).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|