Skip to content

Commit 3574a3a

Browse files
committed
tests
1 parent 8bc3fab commit 3574a3a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

packages/inquirerer/__tests__/defaultFrom.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ describe('Inquirerer - defaultFrom feature', () => {
311311
it('should use custom async resolver', async () => {
312312
const customRegistry = new DefaultResolverRegistry();
313313
customRegistry.register('custom.async', async () => {
314-
return new Promise(resolve => setTimeout(() => resolve('async-result'), 10));
314+
// Return a promise without setTimeout to avoid issues with fake timers
315+
return Promise.resolve('async-result');
315316
});
316317

317318
const prompter = new Inquirerer({
@@ -422,7 +423,9 @@ describe('Inquirerer - defaultFrom feature', () => {
422423

423424
describe('interactive mode with defaultFrom', () => {
424425
it('should show resolved default in prompt and allow override', async () => {
425-
mockedExecSync.mockReturnValue(Buffer.from('John Doe\n'));
426+
jest.useRealTimers(); // Use real timers for interactive tests
427+
428+
mockedExecSync.mockReturnValue('John Doe\n' as any);
426429

427430
enqueueInputResponse({ type: 'read', value: 'Custom Name' });
428431

@@ -444,10 +447,15 @@ describe('Inquirerer - defaultFrom feature', () => {
444447
const result = await prompter.prompt({}, questions);
445448

446449
expect(result).toEqual({ authorName: 'Custom Name' });
450+
451+
jest.useFakeTimers(); // Restore fake timers
452+
jest.setSystemTime(new Date('2025-11-23T15:30:45.123Z'));
447453
});
448454

449455
it('should use resolved default when user presses enter', async () => {
450-
mockedExecSync.mockReturnValue(Buffer.from('John Doe\n'));
456+
jest.useRealTimers(); // Use real timers for interactive tests
457+
458+
mockedExecSync.mockReturnValue('John Doe\n' as any);
451459

452460
enqueueInputResponse({ type: 'read', value: '' }); // Empty input = use default
453461

@@ -469,11 +477,16 @@ describe('Inquirerer - defaultFrom feature', () => {
469477
const result = await prompter.prompt({}, questions);
470478

471479
expect(result).toEqual({ authorName: 'John Doe' });
480+
481+
jest.useFakeTimers(); // Restore fake timers
482+
jest.setSystemTime(new Date('2025-11-23T15:30:45.123Z'));
472483
});
473484
});
474485

475486
describe('question types with defaultFrom', () => {
476487
it('should work with confirm type', async () => {
488+
jest.useRealTimers(); // Use real timers for interactive tests
489+
477490
const customRegistry = new DefaultResolverRegistry();
478491
customRegistry.register('custom.bool', () => true);
479492

@@ -498,6 +511,9 @@ describe('Inquirerer - defaultFrom feature', () => {
498511
const result = await prompter.prompt({}, questions);
499512

500513
expect(result).toEqual({ confirmed: true });
514+
515+
jest.useFakeTimers(); // Restore fake timers
516+
jest.setSystemTime(new Date('2025-11-23T15:30:45.123Z'));
501517
});
502518

503519
it('should work with number type', async () => {

packages/inquirerer/__tests__/resolvers.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ describe('Date Resolvers', () => {
316316
it('should resolve current timestamp in milliseconds', async () => {
317317
const result = await globalResolverRegistry.resolve('date.timestamp');
318318

319-
expect(result).toBe('1732375845123');
319+
// 2025-11-23T15:30:45.123Z corresponds to this timestamp
320+
expect(result).toBe(String(new Date('2025-11-23T15:30:45.123Z').getTime()));
320321
});
321322
});
322323
});

0 commit comments

Comments
 (0)