AGENT SKILL

add-test

Generate unit or E2E test files for existing code

License 许可
MIT
最近更新
2026-11-12
Stars
★ 0
Forks
0

01 前言 Front Matter

name
add-test
description
Generate unit or E2E test files for existing code

03 SKILL.md 正文

/add-test - Generate Tests

Usage

/add-test [type] [target]
  • type — unit (default) or e2e
  • target — 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

  1. Read target file to understand exports
  2. Create __tests__/ directory if needed
  3. Cover: normal paths, edge cases (empty/null/undefined), error conditions, async operations
  4. Assertions: assert.strictEqual(), assert.deepStrictEqual(), assert.ok(), assert.throws()

E2E Tests

  1. Determine Git state needed (commits, branches, tags)
  2. Create GitFixture setup
  3. Cover: UI presence, user interactions, navigation, error states
  4. 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

04 同仓库更多 Skills

realsudarshan
realsudarshan/SD-skill

winui-app

Bootstrap, develop, and design modern WinUI 3 desktop applications with C# and the Windows App SDK using official Microsoft guidance, WinUI Gallery patterns, Windows App SDK samples, and CommunityToolkit components. Use when creating a brand new app, preparing a machine for WinUI, reviewing, refactoring, planning, troubleshooting, environment-checking, or setting up WinUI 3 XAML, controls, navigation, windowing, theming, accessibility, responsiveness, performance, deployment, or related Windows app design and development work.

★ 0
realsudarshan
realsudarshan/SD-skill

vercel-deploy

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

★ 0
realsudarshan
realsudarshan/SD-skill

security-best-practices

Perform language and framework specific security best-practice reviews and suggest improvements. Trigger only when the user explicitly requests security best practices guidance, a security review/report, or secure-by-default coding help. Trigger only for supported languages (python, javascript/typescript, go). Do not trigger for general code review, debugging, or non-security tasks.

★ 0
realsudarshan
realsudarshan/SD-skill

playwright

Use when the task requires automating a real browser from the terminal (navigation, form filling, snapshots, screenshots, data extraction, UI-flow debugging) via `playwright-cli` or the bundled wrapper script.

★ 0
realsudarshan
realsudarshan/SD-skill

openai-docs

Use when the user asks how to build with OpenAI products or APIs and needs up-to-date official documentation with citations, help choosing the latest model for a use case, or model upgrade and prompt-upgrade guidance; prioritize OpenAI docs MCP tools, use bundled references only as helper context, and restrict any fallback browsing to official OpenAI domains.

★ 0
realsudarshan
realsudarshan/SD-skill

netlify-deploy

Deploy web projects to Netlify using the Netlify CLI (`npx netlify`). Use when the user asks to deploy, host, publish, or link a site/repo on Netlify, including preview and production deploys.

★ 0