Jest
npm install @tracera/jest
Node.js 22.19–26.12 और Jest 30–30.5 पर परीक्षित (देखें ऑटोटेस्ट एडेप्टर)। @tracera/jest npm पर.
jest.config.cjs में (या अपने Jest कॉन्फ़िग में):
module.exports = {
testEnvironment: 'node',
setupFilesAfterEnv: ['@tracera/jest/setup'],
reporters: ['default', '@tracera/jest/reporter'],
};
एनवायरनमेंट, रन मोड और रीट्राई: ऑटोटेस्ट एडेप्टर।
रीट्राई Env कुंजी: JEST_RETRY।
testCaseId और autotestName बाँधना
test, expect और hooks @jest/globals से इम्पोर्ट करें (या Jest-injected globals इस्तेमाल करें), और tracera, annotations और skip @tracera/jest से। @tracera/jest/setup लोड करें ताकि स्टेप्स और बाइंड स्टॉक Jest APIs के साथ काम करें।
घोषणा पर (पसंदीदा — बॉडी जल्दी छोड़ दे तो भी बाइंड चलता है):
import { test, expect } from '@jest/globals';
import { annotations } from '@tracera/jest';
test(
'login',
annotations(42, 'e2e/login', async () => {
expect(true).toBe(true);
}),
);
टेस्ट के अंदर (अगर annotations पहले से केस बाँध चुके हों तो वैकल्पिक):
import { test, expect } from '@jest/globals';
import { tracera } from '@tracera/jest';
test('login', async () => {
tracera.testCase(42, 'e2e/login');
expect(true).toBe(true);
});
छोड़ना
अगर पहले से पता हो कि टेस्ट छोड़ना है — test.skip या describe.skip इस्तेमाल करें। अगर skip शर्त टेस्ट के अंदर गिनी जाती है — इस पैकेज का skip लें: Jest में test.skip(reason) नहीं है।
import { test } from '@jest/globals';
import { annotations, skip } from '@tracera/jest';
test(
'login',
annotations(42, 'e2e/login', () => {
if (!process.env.READY) skip('env not ready');
// …
}),
);
स्टेप्स
tracera.step इस्तेमाल करें: कॉल tracera.step(title, fn), क्लास मेथड पर डेकोरेटर @tracera.step("…"), या tracera.step("…")(fn)। डेकोरेटर शीर्षक में {name} / {0} मेथड आर्गुमेंट से भरते हैं; शीर्षक लौटाने वाला फ़ंक्शन भी दे सकते हैं। कॉल-फ़ॉर्म में {name} / {0} नहीं भरते — तैयार शीर्षक स्ट्रिंग दें (या खुद बनाएँ)। Async मेथड और Promise पूरे होने तक प्रतीक्षा होती है। @jest/globals के मानक beforeEach / afterEach लपेटे गए हैं: उनके अंदर स्टेप्स परिणाम के सेटअप / टीयरडाउन में जाते हैं। सूट-स्तरीय हुक्स (beforeAll / afterAll) रिपोर्ट नहीं होते।
import { test, beforeEach, afterEach } from '@jest/globals';
import { tracera } from '@tracera/jest';
beforeEach(async () => {
await tracera.step('open shop', async () => {
// …
});
});
test('checkout', async () => {
tracera.testCase(10, 'e2e/checkout');
await tracera.step('add to cart', async () => {
// …
});
});
afterEach(async () => {
await tracera.step('cleanup', async () => {
// …
});
});
मेथड पर डेकोरेटर:
import { tracera } from '@tracera/jest';
class Cart {
@tracera.step('add {item}')
async addToCart(item: string) {
// …
}
}
टिप्पणियाँ, त्रुटियाँ और अटैचमेंट
टिप्पणी, त्रुटियाँ और अटैचमेंट: ऑटोटेस्ट एडेप्टर।
import { test } from '@jest/globals';
import { tracera } from '@tracera/jest';
test('login', async () => {
tracera.testCase(42, 'e2e/login');
tracera.comment('result-level note');
tracera.error('result-level error text');
await tracera.step('open login', async () => {
tracera.comment('landed on login');
tracera.attachment({
fileName: 'suite-log.txt',
mimeType: 'text/plain',
data: new TextEncoder().encode('finished login flow'),
});
});
});
पैरामीटराइज़्ड टेस्ट
test.each के साथ कॉलबैक लपेटें: annotations(id, 'login as {login}', fn) — ऑब्जेक्ट पंक्ति के फ़ील्ड {login} जैसे प्लेसहोल्डर भरते हैं।
import { test, expect } from '@jest/globals';
import { annotations } from '@tracera/jest';
test.each([{ login: 'ok' }, { login: 'sso' }])(
'login as $login',
annotations(42, 'login as {login}', async ({ login }) => {
expect(login).toBeTruthy();
}),
);