Testing Git URL Transformation Utilities in Insomnia
This test suite validates the addDotGit utility function in the Insomnia repository, ensuring proper handling of Git repository URLs across different protocols. The tests verify URL transformation behavior for both bare links and those already containing .git extensions.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
kong/insomnia
packages/insomnia/src/sync/git/__tests__/utils.test.ts
import { describe, expect, it } from 'vitest';
import { addDotGit } from '../utils';
const links = {
scp: {
bare: '[email protected]:a/b',
dotGit: '[email protected]:a/b.git',
},
ssh: {
bare: 'ssh://[email protected]/b',
dotGit: 'ssh://[email protected]/b.git',
},
http: {
bare: 'http://github.com/a/b',
dotGit: 'http://github.com/a/b.git',
},
https: {
bare: 'https://github.com/a/b',
dotGit: 'https://github.com/a/b.git',
},
};
describe('addDotGit', () => {
it('adds the .git to bare links', () => {
expect(addDotGit(links.scp.bare)).toEqual(links.scp.dotGit);
expect(addDotGit(links.ssh.bare)).toEqual(links.ssh.dotGit);
expect(addDotGit(links.http.bare)).toEqual(links.http.dotGit);
expect(addDotGit(links.https.bare)).toEqual(links.https.dotGit);
});
it('leaves links that already have .git alone', () => {
expect(addDotGit(links.scp.dotGit)).toEqual(links.scp.dotGit);
expect(addDotGit(links.ssh.dotGit)).toEqual(links.ssh.dotGit);
expect(addDotGit(links.http.dotGit)).toEqual(links.http.dotGit);
expect(addDotGit(links.https.dotGit)).toEqual(links.https.dotGit);
});
});