feat(core): Implement Protocol V2 with enhanced settings and lifecycle hooks
This commit is contained in:
41
test/config-test/00init.ts
Normal file
41
test/config-test/00init.ts
Normal 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');
|
44
test/config-test/test.config.ts
Normal file
44
test/config-test/test.config.ts
Normal 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();
|
22
test/config-test/test.file-settings.ts
Normal file
22
test/config-test/test.file-settings.ts
Normal 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();
|
56
test/tapbundle/test.diff-demo.ts
Normal file
56
test/tapbundle/test.diff-demo.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { tap, expect } from '../../ts_tapbundle/index.js';
|
||||
|
||||
tap.test('should show string diff', async () => {
|
||||
const expected = `Hello World
|
||||
This is a test
|
||||
of multiline strings`;
|
||||
|
||||
const actual = `Hello World
|
||||
This is a demo
|
||||
of multiline strings`;
|
||||
|
||||
// This will fail and show a diff
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
tap.test('should show object diff', async () => {
|
||||
const expected = {
|
||||
name: 'John',
|
||||
age: 30,
|
||||
city: 'New York',
|
||||
hobbies: ['reading', 'coding']
|
||||
};
|
||||
|
||||
const actual = {
|
||||
name: 'John',
|
||||
age: 31,
|
||||
city: 'Boston',
|
||||
hobbies: ['reading', 'gaming']
|
||||
};
|
||||
|
||||
// This will fail and show a diff
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
tap.test('should show array diff', async () => {
|
||||
const expected = [1, 2, 3, 4, 5];
|
||||
const actual = [1, 2, 3, 5, 6];
|
||||
|
||||
// This will fail and show a diff
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
tap.test('should show primitive diff', async () => {
|
||||
const expected = 42;
|
||||
const actual = 43;
|
||||
|
||||
// This will fail and show a diff
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
|
||||
tap.test('should pass without diff', async () => {
|
||||
expect(true).toBe(true);
|
||||
expect('hello').toEqual('hello');
|
||||
});
|
||||
|
||||
tap.start({ throwOnError: false });
|
23
test/tapbundle/test.simple-diff.ts
Normal file
23
test/tapbundle/test.simple-diff.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { tap, expect } from '../../ts_tapbundle/index.js';
|
||||
|
||||
tap.test('should show string diff', async () => {
|
||||
const expected = `line 1
|
||||
line 2
|
||||
line 3`;
|
||||
|
||||
const actual = `line 1
|
||||
line changed
|
||||
line 3`;
|
||||
|
||||
try {
|
||||
expect(actual).toEqual(expected);
|
||||
} catch (e) {
|
||||
// Expected to fail
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should pass', async () => {
|
||||
expect('hello').toEqual('hello');
|
||||
});
|
||||
|
||||
tap.start({ throwOnError: false });
|
Reference in New Issue
Block a user