mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-09-27 15:34:30 +00:00
## Summary
Update all direct npm dependencies and devDependencies to the current
npm latest versions and pin them exactly instead of using caret or tilde
ranges.
## Changes
- Pin all direct runtime and development package versions in
`package.json` and refresh `package-lock.json`.
- Migrate ESLint from `.eslintrc.json` to flat config for ESLint 10.
- Update Jest and TypeScript configuration and test mocks to support the
latest ESM-only packages.
- Add response status handling and typed JSON access for the latest
`node-fetch` types.
## Checklist
- [x] I have read the latest README and followed the instructions.
- [x] I have added or updated tests for behavior changes.
- [x] I have updated README.md and action.yml when inputs or runtime
behavior changed.
- [x] I have run the relevant verification commands.
## Verification
- [x] `npm --userconfig=/private/tmp/empty-npmrc outdated --json
--include=dev` returned `{}`
- [x] `npm run all`
- [x] `npm run build`
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Tests**
* Added comprehensive test mocks for Actions APIs and fetch, improved
integration tests, and updated assertions for more precise error
validation.
* Configured Jest to map external modules to local test mocks.
* **Chores**
* Migrated ESLint to the flat config format and replaced prior ESLint
config.
* Updated project dependencies and modernized TypeScript compiler
settings.
* **Refactor**
* Adjusted exported tool constants and made error handling more explicit
in version-fetching logic.
[](https://app.coderabbit.ai/change-stack/peaceiris/actions-hugo/pull/689)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Codex <noreply@openai.com>
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import * as main from '../src/main';
|
|
import * as io from '@actions/io';
|
|
import path from 'path';
|
|
import nock from 'nock';
|
|
import {Tool, Action} from '../src/constants';
|
|
import {FetchError} from 'node-fetch';
|
|
import jsonTestBrew from './data/brew.json';
|
|
// import jsonTestGithub from './data/github.json';
|
|
|
|
jest.setTimeout(30000);
|
|
|
|
describe('Integration testing run()', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName);
|
|
await io.rmRF(workDir);
|
|
|
|
delete process.env['INPUT_HUGO-VERSION'];
|
|
delete process.env['INPUT_EXTENDED'];
|
|
nock.cleanAll();
|
|
});
|
|
|
|
test('succeed in installing a custom version', async () => {
|
|
const testVersion = Tool.TestVersionSpec;
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${testVersion}`);
|
|
});
|
|
|
|
test('succeed in installing a custom extended version', async () => {
|
|
const testVersion = Tool.TestVersionSpec;
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${testVersion}`);
|
|
expect(result.output).toMatch(`extended`);
|
|
});
|
|
|
|
test('succeed in installing the latest version', async () => {
|
|
const testVersion = 'latest';
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
|
});
|
|
|
|
test('succeed in installing the latest extended version', async () => {
|
|
const testVersion = 'latest';
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
|
expect(result.output).toMatch(`extended`);
|
|
});
|
|
|
|
test('fail to install the latest version due to 404 of brew', async () => {
|
|
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
|
|
|
await expect(main.run()).rejects.toThrow(FetchError);
|
|
});
|
|
});
|
|
|
|
describe('showVersion()', () => {
|
|
let result: main.ActionResult = {
|
|
exitcode: 0,
|
|
output: ''
|
|
};
|
|
|
|
test('return version', async () => {
|
|
result = await main.showVersion('git', ['--version']);
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(/git version/);
|
|
});
|
|
|
|
test('return not found', async () => {
|
|
await expect(main.showVersion('gitgit', ['--version'])).rejects.toThrow('spawn gitgit ENOENT');
|
|
});
|
|
});
|