Files
Sebastian Poxhofer f4fa861457 test(npm): replace file snapshots with explicit assertions (#45658)
* test(npm): replace file snapshots with explicit assertions

* test(npm): replace inline snapshots with explicit assertions
2026-09-04 06:36:41 +00:00

81 lines
2.1 KiB
TypeScript

import * as npmUpdater from '../../index.ts';
describe('modules/manager/npm/update/package-version/index', () => {
describe('.bumpPackageVersion()', () => {
const content = JSON.stringify({
name: 'some-package',
version: '0.0.2',
dependencies: { chalk: '2.4.2' },
});
it('mirrors', () => {
const { bumpedContent } = npmUpdater.bumpPackageVersion(
content,
'0.0.2',
'mirror:chalk',
);
expect(bumpedContent).toBe(
'{"name":"some-package","version":"2.4.2","dependencies":{"chalk":"2.4.2"}}',
);
expect(bumpedContent).not.toEqual(content);
});
it('aborts mirror', () => {
const { bumpedContent } = npmUpdater.bumpPackageVersion(
content,
'0.0.2',
'mirror:a',
);
expect(bumpedContent).toEqual(content);
});
it('increments', () => {
const { bumpedContent } = npmUpdater.bumpPackageVersion(
content,
'0.0.2',
'patch',
);
expect(bumpedContent).toBe(
'{"name":"some-package","version":"0.0.3","dependencies":{"chalk":"2.4.2"}}',
);
expect(bumpedContent).not.toEqual(content);
});
it('no ops', () => {
const { bumpedContent } = npmUpdater.bumpPackageVersion(
content,
'0.0.1',
'patch',
);
expect(bumpedContent).toEqual(content);
});
it('updates', () => {
const { bumpedContent } = npmUpdater.bumpPackageVersion(
content,
'0.0.1',
'minor',
);
expect(bumpedContent).toBe(
'{"name":"some-package","version":"0.1.0","dependencies":{"chalk":"2.4.2"}}',
);
expect(bumpedContent).not.toEqual(content);
});
it('returns content if bumping errors', async () => {
vi.doMock('semver', () => ({
inc: () => {
throw new Error('semver inc');
},
}));
const npmUpdater1 = await import('./index.ts');
const { bumpedContent } = npmUpdater1.bumpPackageVersion(
content,
'0.0.2',
true as any,
);
expect(bumpedContent).toEqual(content);
});
});
});