Files
renovate/lib/modules/manager/batect-wrapper/artifacts.spec.ts
Jamie Tanna 2d1e57532f refactor(types): rename lockFile to fileName in ArtifactError (#41631)
As `fileName` makes more sense (as it's not always a lock file we're
updating).

Also, if you set `fileName`, it would never actually output the
filename.

This renames the usages of `lockFile` to `fileName`.

Co-authored-by: Claude Sonnet 4.5 <jamie.tanna+github-copilot@mend.io>
2026-03-10 09:57:31 +00:00

121 lines
3.4 KiB
TypeScript

import * as httpMock from '~test/http-mock.ts';
import type { UpdateArtifact } from '../types.ts';
import { updateArtifacts } from './index.ts';
const defaultTo = '1.2.3';
const newUnixWrapperContent = `Unix wrapper script for ${defaultTo}`;
const newWindowsWrapperContent = `Windows wrapper script for ${defaultTo}`;
function artifactForPath(
path: string,
newVersion: string = defaultTo,
): UpdateArtifact {
return {
packageFileName: path,
updatedDeps: [
{
depName: 'batect/batect',
},
],
newPackageFileContent: 'not used',
config: {
newVersion,
},
};
}
describe('modules/manager/batect-wrapper/artifacts', () => {
beforeEach(() => {
httpMock
.scope('https://github.com')
.get('/batect/batect/releases/download/1.2.3/batect')
.reply(200, newUnixWrapperContent);
httpMock
.scope('https://github.com')
.get('/batect/batect/releases/download/1.2.3/batect.cmd')
.reply(200, newWindowsWrapperContent);
httpMock
.scope('https://github.com')
.get('/batect/batect/releases/download/3.4.5/batect')
.reply(404);
httpMock
.scope('https://github.com')
.get('/batect/batect/releases/download/3.4.5/batect.cmd')
.reply(418);
});
// TODO: fix mocks
afterEach(() => httpMock.clear(false));
describe('updateArtifacts', () => {
it('returns updated files if the wrapper script is in the root directory', async () => {
const artifact = artifactForPath('batect');
const result = await updateArtifacts(artifact);
expect(result).toEqual([
{
file: {
type: 'addition',
path: 'batect',
contents: newUnixWrapperContent,
},
},
{
file: {
type: 'addition',
path: 'batect.cmd',
contents: newWindowsWrapperContent,
},
},
]);
});
it('returns updated files if the wrapper script is in a subdirectory', async () => {
const artifact = artifactForPath('some/sub/dir/batect');
const result = await updateArtifacts(artifact);
expect(result).toEqual([
{
file: {
type: 'addition',
path: 'some/sub/dir/batect',
contents: newUnixWrapperContent,
},
},
{
file: {
type: 'addition',
path: 'some/sub/dir/batect.cmd',
contents: newWindowsWrapperContent,
},
},
]);
});
it('returns an error if the updated wrapper script cannot be downloaded', async () => {
const artifact = artifactForPath('batect', '3.4.5');
const result = await updateArtifacts(artifact);
expect(result).toEqual([
{
artifactError: {
fileName: 'batect',
stderr:
'HTTP GET https://github.com/batect/batect/releases/download/3.4.5/batect failed: HTTPError: Request failed with status code 404 (Not Found): GET https://github.com/batect/batect/releases/download/3.4.5/batect',
},
},
{
artifactError: {
fileName: 'batect.cmd',
stderr:
"HTTP GET https://github.com/batect/batect/releases/download/3.4.5/batect.cmd failed: HTTPError: Request failed with status code 418 (I'm a Teapot): GET https://github.com/batect/batect/releases/download/3.4.5/batect.cmd",
},
},
]);
});
});
});