Skip to content

Commit 3ee4fe4

Browse files
committed
Fix rush-lib test that was failing intermittently
1 parent ad8185e commit 3ee4fe4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

apps/rush-lib/src/logic/taskRunner/test/TaskRunner.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { ITaskWriter } from '@microsoft/stream-collator';
44
import { TaskStatus } from '../TaskStatus';
55
import { ITaskDefinition, ITask } from '../ITask';
66
import { StringBufferTerminalProvider, Terminal } from '@microsoft/node-core-library';
7+
import { Utilities } from '../../../utilities/Utilities';
8+
9+
// The TaskRunner prints "x.xx seconds" in TestRunner.test.ts.snap; ensure that the Stopwatch timing is deterministic
10+
jest.mock('../../../utilities/Utilities');
11+
const mockGetTimeInMs: jest.Mock<unknown> = jest.fn();
12+
Utilities.getTimeInMs = mockGetTimeInMs;
13+
14+
let mockTimeInMs: number = 0;
15+
mockGetTimeInMs.mockImplementation(() => {
16+
console.log('CALLED mockGetTimeInMs');
17+
mockTimeInMs += 100;
18+
return mockTimeInMs;
19+
});
720

821
function createTaskRunner(taskRunnerOptions: ITaskRunnerOptions, taskDefinition: ITaskDefinition): TaskRunner {
922
const task: ITask = taskDefinition as ITask;

apps/rush-lib/src/logic/taskRunner/test/__snapshots__/TaskRunner.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`TaskRunner Constructor throwsErrorOnInvalidParallelism 1`] = `"Invalid
44

55
exports[`TaskRunner Error logging preservedLeadingBlanksButTrimmedTrailingBlanks 1`] = `"Project(s) failed to build"`;
66

7-
exports[`TaskRunner Error logging preservedLeadingBlanksButTrimmedTrailingBlanks 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[large stderr with leading and trailing blanks] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mlarge stderr with leading and trailing blanks (0.00 seconds)[x][39m[n]List of errors:[-n-] - error #1;[-n-] - error #2;[-n-] - error #3;[-n-] - error #4;[-n-] - error #5;[-n-] - error #6;[-n-] - error #7;[-n-] - error #8;[-n-] - error #9;[-n-][...21 lines omitted...][-n-] - error #31;[-n-] - error #32;[-n-] - error #33;[-n-] - error #34;[-n-] - error #35;[-n-] - error #36;[-n-] - error #37;[-n-] - error #38;[-n-] - error #39;[-n-] - error #40;[-n-] - error #41;[-n-] - error #42;[-n-] - error #43;[-n-] - error #44;[-n-] - error #45;[-n-] - error #46;[-n-] - error #47;[-n-] - error #48;[-n-] - error #49;[-n-] - error #50;[n][x][31m================================[-n-][x][39m[n][n]"`;
7+
exports[`TaskRunner Error logging preservedLeadingBlanksButTrimmedTrailingBlanks 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[large stderr with leading and trailing blanks] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mlarge stderr with leading and trailing blanks (0.10 seconds)[x][39m[n]List of errors:[-n-] - error #1;[-n-] - error #2;[-n-] - error #3;[-n-] - error #4;[-n-] - error #5;[-n-] - error #6;[-n-] - error #7;[-n-] - error #8;[-n-] - error #9;[-n-][...21 lines omitted...][-n-] - error #31;[-n-] - error #32;[-n-] - error #33;[-n-] - error #34;[-n-] - error #35;[-n-] - error #36;[-n-] - error #37;[-n-] - error #38;[-n-] - error #39;[-n-] - error #40;[-n-] - error #41;[-n-] - error #42;[-n-] - error #43;[-n-] - error #44;[-n-] - error #45;[-n-] - error #46;[-n-] - error #47;[-n-] - error #48;[-n-] - error #49;[-n-] - error #50;[n][x][31m================================[-n-][x][39m[n][n]"`;
88

99
exports[`TaskRunner Error logging preservedLeadingBlanksButTrimmedTrailingBlanks 3`] = `""`;
1010

@@ -14,7 +14,7 @@ exports[`TaskRunner Error logging preservedLeadingBlanksButTrimmedTrailingBlanks
1414

1515
exports[`TaskRunner Error logging printedAbridgedStdoutAfterErrorWithEmptyStderr 1`] = `"Project(s) failed to build"`;
1616

17-
exports[`TaskRunner Error logging printedAbridgedStdoutAfterErrorWithEmptyStderr 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[large stdout only] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mlarge stdout only (0.00 seconds)[x][39m[n]Building units...[-n-] - unit #1;[-n-] - unit #2;[-n-] - unit #3;[-n-] - unit #4;[-n-] - unit #5;[-n-] - unit #6;[-n-] - unit #7;[-n-] - unit #8;[-n-] - unit #9;[-n-][...21 lines omitted...][-n-] - unit #31;[-n-] - unit #32;[-n-] - unit #33;[-n-] - unit #34;[-n-] - unit #35;[-n-] - unit #36;[-n-] - unit #37;[-n-] - unit #38;[-n-] - unit #39;[-n-] - unit #40;[-n-] - unit #41;[-n-] - unit #42;[-n-] - unit #43;[-n-] - unit #44;[-n-] - unit #45;[-n-] - unit #46;[-n-] - unit #47;[-n-] - unit #48;[-n-] - unit #49;[-n-] - unit #50;[n][x][31m================================[-n-][x][39m[n][n]"`;
17+
exports[`TaskRunner Error logging printedAbridgedStdoutAfterErrorWithEmptyStderr 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[large stdout only] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mlarge stdout only (0.10 seconds)[x][39m[n]Building units...[-n-] - unit #1;[-n-] - unit #2;[-n-] - unit #3;[-n-] - unit #4;[-n-] - unit #5;[-n-] - unit #6;[-n-] - unit #7;[-n-] - unit #8;[-n-] - unit #9;[-n-][...21 lines omitted...][-n-] - unit #31;[-n-] - unit #32;[-n-] - unit #33;[-n-] - unit #34;[-n-] - unit #35;[-n-] - unit #36;[-n-] - unit #37;[-n-] - unit #38;[-n-] - unit #39;[-n-] - unit #40;[-n-] - unit #41;[-n-] - unit #42;[-n-] - unit #43;[-n-] - unit #44;[-n-] - unit #45;[-n-] - unit #46;[-n-] - unit #47;[-n-] - unit #48;[-n-] - unit #49;[-n-] - unit #50;[n][x][31m================================[-n-][x][39m[n][n]"`;
1818

1919
exports[`TaskRunner Error logging printedAbridgedStdoutAfterErrorWithEmptyStderr 3`] = `""`;
2020

@@ -24,7 +24,7 @@ exports[`TaskRunner Error logging printedAbridgedStdoutAfterErrorWithEmptyStderr
2424

2525
exports[`TaskRunner Error logging printedStderrAfterError 1`] = `"Project(s) failed to build"`;
2626

27-
exports[`TaskRunner Error logging printedStderrAfterError 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[stdout+stderr] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mstdout+stderr (0.00 seconds)[x][39m[n]Error: step 1 failed[n][x][31m================================[-n-][x][39m[n][n]"`;
27+
exports[`TaskRunner Error logging printedStderrAfterError 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[stdout+stderr] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mstdout+stderr (0.10 seconds)[x][39m[n]Error: step 1 failed[n][x][31m================================[-n-][x][39m[n][n]"`;
2828

2929
exports[`TaskRunner Error logging printedStderrAfterError 3`] = `""`;
3030

@@ -34,7 +34,7 @@ exports[`TaskRunner Error logging printedStderrAfterError 5`] = `"[x][31m[-n-]1
3434

3535
exports[`TaskRunner Error logging printedStdoutAfterErrorWithEmptyStderr 1`] = `"Project(s) failed to build"`;
3636

37-
exports[`TaskRunner Error logging printedStdoutAfterErrorWithEmptyStderr 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[stdout only] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mstdout only (0.00 seconds)[x][39m[n]Build step 1[-n-]Error: step 1 failed[n][x][31m================================[-n-][x][39m[n][n]"`;
37+
exports[`TaskRunner Error logging printedStdoutAfterErrorWithEmptyStderr 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[stdout only] started[x][39m[n][n][x][31mFAILURE (1)[x][39m[n][x][31m================================[x][39m[n][x][31mstdout only (0.10 seconds)[x][39m[n]Build step 1[-n-]Error: step 1 failed[n][x][31m================================[-n-][x][39m[n][n]"`;
3838

3939
exports[`TaskRunner Error logging printedStdoutAfterErrorWithEmptyStderr 3`] = `""`;
4040

@@ -44,18 +44,18 @@ exports[`TaskRunner Error logging printedStdoutAfterErrorWithEmptyStderr 5`] = `
4444

4545
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 1`] = `"An error occurred."`;
4646

47-
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[success with warnings (failure)] started[x][39m[n][n][x][33m[x][4mSUCCESS WITH WARNINGS (1)[x][24m[x][39m[n][x][33m================================[x][39m[n][x][33m[x][4msuccess with warnings (failure) (0.00 seconds)[x][24m[x][39m[n]Build step 1[-n-]Warning: step 1 succeeded with warnings[n][x][33m================================[-n-][x][39m[n][n]"`;
47+
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 2`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[success with warnings (failure)] started[x][39m[n][n][x][33m[x][4mSUCCESS WITH WARNINGS (1)[x][24m[x][39m[n][x][33m================================[x][39m[n][x][33m[x][4msuccess with warnings (failure) (0.10 seconds)[x][24m[x][39m[n]Build step 1[-n-]Warning: step 1 succeeded with warnings[n][x][33m================================[-n-][x][39m[n][n]"`;
4848

4949
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 3`] = `""`;
5050

51-
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 4`] = `"[x][33m1 of 1: [success with warnings (failure)] completed with warnings in 0.00 seconds[x][39m[n][x][33mProject(s) succeeded with warnings[x][39m[n]"`;
51+
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 4`] = `"[x][33m1 of 1: [success with warnings (failure)] completed with warnings in 0.10 seconds[x][39m[n][x][33mProject(s) succeeded with warnings[x][39m[n]"`;
5252

5353
exports[`TaskRunner Warning logging Fail on warning Logs warnings correctly 5`] = `""`;
5454

55-
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 1`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[success with warnings (success)] started[x][39m[n][n][x][33m[x][4mSUCCESS WITH WARNINGS (1)[x][24m[x][39m[n][x][33m================================[x][39m[n][x][33m[x][4msuccess with warnings (success) (0.00 seconds)[x][24m[x][39m[n]Build step 1[-n-]Warning: step 1 succeeded with warnings[n][x][33m================================[-n-][x][39m[n][n]"`;
55+
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 1`] = `"Executing a maximum of 1 simultaneous processes...[-n-][n][x][37m[success with warnings (success)] started[x][39m[n][n][x][33m[x][4mSUCCESS WITH WARNINGS (1)[x][24m[x][39m[n][x][33m================================[x][39m[n][x][33m[x][4msuccess with warnings (success) (0.10 seconds)[x][24m[x][39m[n]Build step 1[-n-]Warning: step 1 succeeded with warnings[n][x][33m================================[-n-][x][39m[n][n]"`;
5656

5757
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 2`] = `""`;
5858

59-
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 3`] = `"[x][33m1 of 1: [success with warnings (success)] completed with warnings in 0.00 seconds[x][39m[n]"`;
59+
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 3`] = `"[x][33m1 of 1: [success with warnings (success)] completed with warnings in 0.10 seconds[x][39m[n]"`;
6060

6161
exports[`TaskRunner Warning logging Success on warning Logs warnings correctly 4`] = `""`;

0 commit comments

Comments
 (0)