mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-09-21 16:27:45 +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>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import {getURL, getLatestVersion} from '../src/get-latest-version';
|
|
import nock from 'nock';
|
|
import {FetchError} from 'node-fetch';
|
|
import {Tool} from '../src/constants';
|
|
import jsonTestBrew from './data/brew.json';
|
|
import jsonTestGithub from './data/github.json';
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
afterEach(() => {
|
|
nock.cleanAll();
|
|
});
|
|
|
|
describe('getURL()', () => {
|
|
test('return expected URL', () => {
|
|
const urlBrewExpected = `https://formulae.brew.sh/api/formula/${Tool.Repo}.json`;
|
|
const urlBrew: string = getURL(Tool.Org, Tool.Repo, 'brew');
|
|
expect(urlBrew).toMatch(urlBrewExpected);
|
|
|
|
const urlGithubExpected = `https://api.github.com/repos/${Tool.Org}/${Tool.Repo}/releases/latest`;
|
|
const urlGithub: string = getURL(Tool.Org, Tool.Repo, 'github');
|
|
expect(urlGithub).toMatch(urlGithubExpected);
|
|
});
|
|
});
|
|
|
|
describe('getLatestVersion()', () => {
|
|
test('return latest version via brew', async () => {
|
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
|
|
|
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'brew');
|
|
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
|
});
|
|
|
|
test('return latest version via GitHub', async () => {
|
|
nock('https://api.github.com')
|
|
.get(`/repos/${Tool.Org}/${Tool.Repo}/releases/latest`)
|
|
.reply(200, jsonTestGithub);
|
|
|
|
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'github');
|
|
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
|
});
|
|
|
|
test('return exception 404', async () => {
|
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
|
|
|
await expect(getLatestVersion(Tool.Org, Tool.Repo, 'brew')).rejects.toThrow(FetchError);
|
|
});
|
|
});
|