Skip to content

Commit d80acbd

Browse files
committed
chore: experiment with sleeping on the bin tests to allow asynchronous logging to finish
1 parent d0d66ed commit d80acbd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/bin/typescript-demo-lib.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from 'os';
33
import path from 'path';
44
import { mockProcessStdout } from 'jest-mock-process';
55
import main from '@/bin/typescript-demo-lib';
6+
import { sleep } from '@/utils';
67

78
const uuidRegex = new RegExp(
89
'[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}',
@@ -25,6 +26,7 @@ describe('main', () => {
2526
const mockLog = mockProcessStdout();
2627
expect(await main(['', '', '1', '2', dataDir])).toEqual(0);
2728
mockLog.mockRestore();
29+
await sleep(2000);
2830
});
2931
test('no input', async () => {
3032
const mockLog = mockProcessStdout();
@@ -45,6 +47,7 @@ describe('main', () => {
4547
expect(tmpMockLog).toMatch(uuidRegex);
4648
expect(tmpMockLog).toContain('0 + 0 = 0\n');
4749
mockLog.mockRestore();
50+
await sleep(2000);
4851
});
4952
test('adds 0 + 1', async () => {
5053
const mockLog = mockProcessStdout();
@@ -55,6 +58,7 @@ describe('main', () => {
5558
expect(tmpMockLog).toMatch(uuidRegex);
5659
expect(tmpMockLog).toContain('0 + 1 = 1\n');
5760
mockLog.mockRestore();
61+
await sleep(2000);
5862
});
5963
test('adds 1 + 0', async () => {
6064
const mockLog = mockProcessStdout();
@@ -65,6 +69,7 @@ describe('main', () => {
6569
expect(tmpMockLog).toMatch(uuidRegex);
6670
expect(tmpMockLog).toContain('1 + 0 = 1\n');
6771
mockLog.mockRestore();
72+
await sleep(2000);
6873
});
6974
test('adds 7657 + 238947', async () => {
7075
const mockLog = mockProcessStdout();
@@ -75,5 +80,6 @@ describe('main', () => {
7580
expect(tmpMockLog).toMatch(uuidRegex);
7681
expect(tmpMockLog).toContain('7657 + 238947 = 246604\n');
7782
mockLog.mockRestore();
83+
await sleep(2000);
7884
});
7985
});

0 commit comments

Comments
 (0)