Files
renovate/lib/modules/datasource/node-version/schema.spec.ts
Sebastian Poxhofer c908d078ef fix(datasource): replace getJsonUnchecked in npm/Node/PyPI/Go (#43699)
* fix(datasource): replace getJsonUnchecked with validated getJson in npm/Node/PyPI/Go

Replace all getJsonUnchecked calls in npm, Node.js, PyPI, and Go datasources
with Zod-validated getJson calls:

- datasource/npm: add NpmResponseSchema to schema.ts (shared with presets)
- config/presets/npm: migrate to NpmResponseSchema with passthrough version fields
- datasource/node-version: add NodeReleasesSchema using LooseArray
- datasource/pypi: add PypiJSONSchema (nullable+catch for lenient empty-body handling)
- datasource/go: add VersionInfoSchema for both versionInfo and getLatestVersion calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* some manual cleaning up

* removing schema level catch

* removing some more types

* refactor: rename schema

* fix linter errors

* remove schema suffix which hasn't been catched by linter

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 19:14:50 +00:00

41 lines
1.3 KiB
TypeScript

import { NodeRelease, NodeReleases } from './schema.ts';
describe('modules/datasource/node-version/schema', () => {
describe('NodeRelease', () => {
it('parses a stable LTS release', () => {
const result = NodeRelease.parse({
version: 'v20.0.0',
date: '2023-04-18',
lts: 'Iron',
});
expect(result.version).toBe('v20.0.0');
expect(result.lts).toBe('Iron');
});
it('parses a non-LTS release', () => {
const result = NodeRelease.parse({
version: 'v21.0.0',
date: '2023-10-17',
lts: false,
});
expect(result.version).toBe('v21.0.0');
expect(result.lts).toBe(false);
});
});
describe('NodeReleasesSchema', () => {
it('parses an array of releases, skipping invalid elements', () => {
const input = [
{ version: 'v20.0.0', date: '2023-04-18', lts: 'Iron' },
{ notARelease: true }, // invalid — missing required fields
{ version: 'v18.0.0', date: '2022-04-19', lts: 'Hydrogen' },
];
const result = NodeReleases.parse(input);
// invalid element is skipped (LooseArray behavior)
expect(result).toHaveLength(2);
expect(result[0].version).toBe('v20.0.0');
expect(result[1].version).toBe('v18.0.0');
});
});
});