feat(core): Implement Protocol V2 with enhanced settings and lifecycle hooks

This commit is contained in:
2025-05-26 04:02:32 +00:00
parent 91880f8d42
commit 33d2ff1d4f
24 changed files with 2356 additions and 441 deletions

View File

@ -0,0 +1,41 @@
import { tap } from '../../ts_tapbundle/index.js';
// TAP-compliant comment output
console.log('# 🚀 00init.ts: LOADED AND EXECUTING');
console.log('# 🚀 00init.ts: Setting up global test configuration');
// Add a global variable to verify 00init.ts was loaded
(global as any).__00INIT_LOADED = true;
// Configure global test settings
tap.settings({
// Set a default timeout of 5 seconds for all tests
timeout: 5000,
// Enable retries for flaky tests
retries: 2,
retryDelay: 1000,
// Show test duration
showTestDuration: true,
// Global lifecycle hooks
beforeAll: async () => {
console.log('Global beforeAll: Initializing test environment');
},
afterAll: async () => {
console.log('Global afterAll: Cleaning up test environment');
},
beforeEach: async (testName: string) => {
console.log(`Global beforeEach: Starting test "${testName}"`);
},
afterEach: async (testName: string, passed: boolean) => {
console.log(`Global afterEach: Test "${testName}" ${passed ? 'passed' : 'failed'}`);
}
});
console.log('# 🚀 00init.ts: Configuration COMPLETE');
console.log('# 🚀 00init.ts: tap.settings() called successfully');

View File

@ -0,0 +1,44 @@
import { tap, expect } from '../../ts_tapbundle/index.js';
// TAP-compliant comment output
console.log('# 🔍 TEST FILE LOADED - test.config.ts');
// Check if 00init.ts was loaded
const initLoaded = (global as any).__00INIT_LOADED;
console.log(`# 🔍 00init.ts loaded: ${initLoaded === true}`);
// Test that uses the global timeout setting
tap.test('Test with global timeout', async (toolsArg) => {
// This test should complete within the 5 second timeout set in 00init.ts
await toolsArg.delayFor(2000); // 2 seconds
expect(true).toBeTrue();
});
// Test that demonstrates retries
tap.test('Test with retries', async () => {
// This test will use the global retry setting (2 retries)
console.log('Running test that might be flaky');
// Simulate a flaky test that passes on second try
const randomValue = Math.random();
console.log(`Random value: ${randomValue}`);
// Always pass for demonstration
expect(true).toBeTrue();
});
// Test with custom timeout that overrides global
tap.timeout(1000).test('Test with custom timeout', async (toolsArg) => {
// This test has a 1 second timeout, overriding the global 5 seconds
await toolsArg.delayFor(500); // 500ms - should pass
expect(true).toBeTrue();
});
// Test to verify lifecycle hooks are working
tap.test('Test lifecycle hooks', async () => {
console.log('Inside test: lifecycle hooks should have run');
expect(true).toBeTrue();
});
// Start the test suite
tap.start();

View File

@ -0,0 +1,22 @@
import { tap, expect } from '../../ts_tapbundle/index.js';
// Override global settings for this file
tap.settings({
timeout: 2000, // Override global timeout to 2 seconds
retries: 0, // Disable retries for this file
});
tap.test('Test with file-level timeout', async (toolsArg) => {
// This should use the file-level timeout of 2 seconds
console.log('Running with file-level timeout of 2 seconds');
await toolsArg.delayFor(1000); // 1 second - should pass
expect(true).toBeTrue();
});
tap.test('Test without retries', async () => {
// This test should not retry even if it fails
console.log('This test has no retries (file-level setting)');
expect(true).toBeTrue();
});
tap.start();