一键导入
testing
Mocha/Chai/Sinon testing and TDD for @contentstack/cli-cm-export-query. Use when writing or debugging tests in test/unit/ or adjusting coverage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Mocha/Chai/Sinon testing and TDD for @contentstack/cli-cm-export-query. Use when writing or debugging tests in test/unit/ or adjusting coverage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | testing |
| description | Mocha/Chai/Sinon testing and TDD for @contentstack/cli-cm-export-query. Use when writing or debugging tests in test/unit/ or adjusting coverage. |
Testing best practices and TDD workflow for @contentstack/cli-cm-export-query.
RED → GREEN → REFACTOR for behavior changes; pure refactors / docs-only may skip new tests when behavior is unchanged.
describe('[ComponentName]', () => {
beforeEach(() => {
// Setup mocks and test data
sinon.stub(ExternalService.prototype, 'method').resolves(mockData);
});
afterEach(() => {
sinon.restore();
});
it('should [expected behavior] when [condition]', () => {
// Arrange
const input = { /* test data */ };
// Act
const result = component.method(input);
// Assert
expect(result).to.equal(expectedOutput);
});
});
describe('ExportQueryCommand', () => {
beforeEach(() => {
sinon.stub(ContentstackClient.prototype, 'stack').returns(mockStack);
});
it('should run export when query and auth are valid', async () => {
// Stub parse, setupQueryExportConfig, QueryExporter.prototype.execute, etc.
});
});
fsUtil), not irrelevant internalsafterEach() to prevent test pollutiondescribe blocks// Mock Contentstack API
sinon.stub(ContentstackClient.prototype, 'fetch').resolves(mockData);
// Mock with specific responses
sinon.stub(client, 'getEntry')
.withArgs('entry1').resolves(mockEntry1)
.withArgs('entry2').resolves(mockEntry2);
// Mock rate limiter
sinon.stub(RateLimiter.prototype, 'wait').resolves();
// Mock file operations
sinon.stub(fsUtil, 'writeFile').returns(true);
sinon.stub(fsUtil, 'readFile').resolves(JSON.stringify(mockData));
// Mock API errors
const apiError = new Error('API Error');
apiError.status = 500;
sinon.stub(client, 'fetch').rejects(apiError);
// Mock rate limiting
const rateLimitError = new Error('Rate limited');
rateLimitError.status = 429;
sinon.stub(client, 'fetch').rejects(rateLimitError);
it('should handle rate limit errors', () => {
const error = new Error('Rate limited');
error.status = 429;
sinon.stub(client, 'fetch').rejects(error);
expect(service.performOperation()).to.eventually.be.fulfilled;
});
it('should throw validation error for invalid input', () => {
const invalidInput = { /* invalid data */ };
expect(() => service.validate(invalidInput))
.to.throw('Validation failed');
});
it('should handle async operation failures', async () => {
sinon.stub(service, 'performAsync').rejects(new Error('Operation failed'));
try {
await service.execute();
expect.fail('Should have thrown error');
} catch (error) {
expect(error.message).to.include('Operation failed');
}
});
test/unit/: e.g. test/unit/query-executor.test.ts, test/unit/query-parser-simple.test.ts[module-name].test.tstest/integration/test/fixtures/mock-factory.ts// .mocharc.json
{
"require": ["ts-node/register"],
"extensions": ["ts"],
"spec": "test/**/*.test.ts",
"timeout": 5000,
"forbid-only": true
}
// package.json nyc configuration
"nyc": {
"check-coverage": true,
"lines": 80,
"functions": 80,
"branches": 80,
"statements": 80
}
For new behavior or bug fixes, prefer:
Exceptions: pure refactors, documentation-only edits, and trivial non-behavior changes may skip new tests.
anysrc/commands/cm/stacks/src/core/ (QueryExporter, ModuleExporter, …)src/utils/test/unit/ — *.test.ts per module (e.g. query-executor.test.ts)kebab-case.ts / kebab-case.test.tsPascalCasecamelCaseSCREAMING_SNAKE_CASEany type usagefsUtil, etc.)describe('[ComponentName]', () => {
beforeEach(() => {
sinon.stub(ExternalService.prototype, 'method').resolves(mockData);
});
afterEach(() => {
sinon.restore();
});
it('should [expected behavior] when [condition]', () => {
const input = { /* test data */ };
const result = component.method(input);
expect(result).to.equal(expectedOutput);
});
});
fsUtil, etc.), not irrelevant internalsfeat(scope): descriptionconsole.log, debugger) left innpm run lint, npm run test, npm run test:report if you need LCOVPR and release checklist for cli-cm-regex-validate (security, packaging, CI, messages)
Contentstack CLI plugin patterns for cm:stacks:validate-regex (SDK, schema, safe-regex, output)
Local and CI workflow for cli-cm-regex-validate — commands, layout, naming, hooks, and merge expectations
Jest testing patterns for cli-cm-regex-validate (mocks, fixtures, no live API calls)
Reviews pull requests and risky changes for the contentstack-cli-content-type plugin. Use when reviewing diffs, security-sensitive edits, dependency upgrades, or changes to compare/diagram/temp-file behavior, ESLint, and tests.
Develops and maintains the contentstack-cli-content-type csdx plugin (content-type list, details, audit, compare, compare-remote, diagram). Use when editing this repository, ContentTypeCommand setup and flags, CMA/Management SDK usage, axios audit/references calls, diff/compare HTML output, Graphviz diagrams, or oclif readme/manifest workflows.