Agent skill
add-test
Generate unit or E2E test files for existing code
Install this agent skill to your Project
npx add-skill https://github.com/gitkraken/vscode-gitlens/tree/main/.claude/skills/add-test
SKILL.md
/add-test - Generate Tests
Usage
/add-test [type] [target]
type—unit(default) ore2etarget— File path or feature name to test
Unit Test Template
Creates src/path/__tests__/file.test.ts:
import * as assert from 'assert';
import { functionToTest } from '../file.js';
suite('FeatureName Test Suite', () => {
suite('functionName', () => {
test('should handle normal input', () => {
const result = functionToTest('input');
assert.strictEqual(result, 'expected');
});
test('should handle edge case', () => {
const result = functionToTest('');
assert.strictEqual(result, undefined);
});
test('should throw on invalid input', () => {
assert.throws(() => functionToTest(null), /error message/);
});
});
suite('async function', () => {
test('should resolve with data', async () => {
const result = await asyncFunction();
assert.deepStrictEqual(result, { key: 'value' });
});
});
});
When mocking is needed, use sinon:
import * as sinon from 'sinon';
let sandbox: sinon.SinonSandbox;
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => {
sandbox.restore();
});
E2E Test Template
Creates tests/e2e/specs/feature.test.ts:
import { test as base, expect, GitFixture, MaxTimeout } from '../baseTest.js';
import { createTmpDir } from '../fixtures/tmpDir.js';
const test = base.extend({
vscodeOptions: [
{
vscodeVersion: process.env.VSCODE_VERSION ?? 'stable',
setup: async () => {
const repoDir = await createTmpDir();
const git = new GitFixture(repoDir);
await git.init();
await git.commit('Initial commit', 'README.md', '# Test');
return repoDir;
},
},
{ scope: 'worker' },
],
});
test.describe('Feature Name', () => {
test.describe.configure({ mode: 'serial' });
test('should display feature correctly', async ({ vscode, page, expect }) => {
await vscode.gitlens.openGitLensSidebar();
await expect(page.getByRole('heading')).toContainText('Expected');
});
});
Instructions
Unit Tests
- Read target file to understand exports
- Create
__tests__/directory if needed - Cover: normal paths, edge cases (empty/null/undefined), error conditions, async operations
- Assertions:
assert.strictEqual(),assert.deepStrictEqual(),assert.ok(),assert.throws()
E2E Tests
- Determine Git state needed (commits, branches, tags)
- Create GitFixture setup
- Cover: UI presence, user interactions, navigation, error states
- Assertions:
expect(locator).toBeVisible(),.toContainText(),.toHaveCount()
GitFixture Methods
await git.init()
await git.commit(message, fileName, content)
await git.branch(name)
await git.checkout(name, create?)
await git.tag(name, { message?, ref? })
await git.stash(message?)
await git.worktree(path, branch)
await git.addRemote(name, url)
await git.merge(branch, message?)
Running Tests
pnpm run test -- --grep "FeatureName" # Unit
pnpm run test:e2e -- tests/e2e/specs/file.test.ts # E2E
For detailed test running patterns, output interpretation, and debugging: see docs/testing.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
investigate
Structured investigation of a bug or unexpected behavior before implementing a fix
commit
Create well-formatted git commits following GitLens conventions
analyze
Deep design and implementation analysis with devil's advocate evaluation
add-command
Create new VS Code commands with all required boilerplate
add-icon
Add new icons to the GitLens GL Icons font
deep-planning
Use when formulating the best technical approach for a task — before writing implementation plans or code. Triggers on architecture decisions, complex features, refactors, or when the user asks how to approach something. Investigates current codebase, questions existing patterns, researches alternatives, and presents approaches with trade-offs.
Didn't find tool you were looking for?