Skip to content

Commit 8f36a28

Browse files
Copiloticlanton
andcommitted
Add tests for ShowExistingFailureLogsPlugin and update snapshots
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
1 parent 1d27c32 commit 8f36a28

3 files changed

Lines changed: 143 additions & 2 deletions

File tree

libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,14 @@ Object {
13181318
"required": false,
13191319
"shortName": undefined,
13201320
},
1321+
Object {
1322+
"description": "Skips execution of operations and instead displays any existing failure logs for the selected projects. This is useful for reviewing failures from a previous run without re-executing the operations. Operations without existing failure logs will be silenced.",
1323+
"environmentVariable": undefined,
1324+
"kind": "Flag",
1325+
"longName": "--show-existing-failure-logs",
1326+
"required": false,
1327+
"shortName": undefined,
1328+
},
13211329
Object {
13221330
"description": "Selects a single instead of the default locale (en-us) for non-ship builds or all locales for ship builds.",
13231331
"environmentVariable": undefined,
@@ -1480,6 +1488,14 @@ Object {
14801488
"required": false,
14811489
"shortName": undefined,
14821490
},
1491+
Object {
1492+
"description": "Skips execution of operations and instead displays any existing failure logs for the selected projects. This is useful for reviewing failures from a previous run without re-executing the operations. Operations without existing failure logs will be silenced.",
1493+
"environmentVariable": undefined,
1494+
"kind": "Flag",
1495+
"longName": "--show-existing-failure-logs",
1496+
"required": false,
1497+
"shortName": undefined,
1498+
},
14831499
Object {
14841500
"description": "Perform a production build, including minification and localization steps",
14851501
"environmentVariable": undefined,
@@ -1629,6 +1645,14 @@ Object {
16291645
"required": false,
16301646
"shortName": undefined,
16311647
},
1648+
Object {
1649+
"description": "Skips execution of operations and instead displays any existing failure logs for the selected projects. This is useful for reviewing failures from a previous run without re-executing the operations. Operations without existing failure logs will be silenced.",
1650+
"environmentVariable": undefined,
1651+
"kind": "Flag",
1652+
"longName": "--show-existing-failure-logs",
1653+
"required": false,
1654+
"shortName": undefined,
1655+
},
16321656
Object {
16331657
"description": "Perform a production build, including minification and localization steps",
16341658
"environmentVariable": undefined,

libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ exports[`CommandLineHelp prints the help for each action: build 1`] = `
192192
[--from-version-policy VERSION_POLICY_NAME] [-v]
193193
[--include-phase-deps] [-c] [--ignore-hooks]
194194
[--node-diagnostic-dir DIRECTORY] [--debug-build-cache-ids]
195-
[-s] [-m]
195+
[--show-existing-failure-logs] [-s] [-m]
196196
197197
198198
This command is similar to \\"rush rebuild\\", except that \\"rush build\\" performs
@@ -334,6 +334,12 @@ Optional arguments:
334334
Logs information about the components of the build
335335
cache ids for individual operations. This is useful
336336
for debugging the incremental build logic.
337+
--show-existing-failure-logs
338+
Skips execution of operations and instead displays
339+
any existing failure logs for the selected projects.
340+
This is useful for reviewing failures from a previous
341+
run without re-executing the operations. Operations
342+
without existing failure logs will be silenced.
337343
-s, --ship Perform a production build, including minification
338344
and localization steps
339345
-m, --minimal Perform a fast build, which disables certain tasks
@@ -488,6 +494,7 @@ exports[`CommandLineHelp prints the help for each action: import-strings 1`] = `
488494
[--include-phase-deps] [--ignore-hooks]
489495
[--node-diagnostic-dir DIRECTORY]
490496
[--debug-build-cache-ids]
497+
[--show-existing-failure-logs]
491498
[--locale {en-us,fr-fr,es-es,zh-cn}]
492499
493500
@@ -612,6 +619,12 @@ Optional arguments:
612619
Logs information about the components of the build
613620
cache ids for individual operations. This is useful
614621
for debugging the incremental build logic.
622+
--show-existing-failure-logs
623+
Skips execution of operations and instead displays
624+
any existing failure logs for the selected projects.
625+
This is useful for reviewing failures from a previous
626+
run without re-executing the operations. Operations
627+
without existing failure logs will be silenced.
615628
--locale {en-us,fr-fr,es-es,zh-cn}
616629
Selects a single instead of the default locale
617630
(en-us) for non-ship builds or all locales for ship
@@ -1129,7 +1142,8 @@ exports[`CommandLineHelp prints the help for each action: rebuild 1`] = `
11291142
[--from-version-policy VERSION_POLICY_NAME] [-v]
11301143
[--include-phase-deps] [--ignore-hooks]
11311144
[--node-diagnostic-dir DIRECTORY]
1132-
[--debug-build-cache-ids] [-s] [-m]
1145+
[--debug-build-cache-ids] [--show-existing-failure-logs]
1146+
[-s] [-m]
11331147
11341148
11351149
This command assumes that the package.json file for each project contains a
@@ -1259,6 +1273,12 @@ Optional arguments:
12591273
Logs information about the components of the build
12601274
cache ids for individual operations. This is useful
12611275
for debugging the incremental build logic.
1276+
--show-existing-failure-logs
1277+
Skips execution of operations and instead displays
1278+
any existing failure logs for the selected projects.
1279+
This is useful for reviewing failures from a previous
1280+
run without re-executing the operations. Operations
1281+
without existing failure logs will be silenced.
12621282
-s, --ship Perform a production build, including minification
12631283
and localization steps
12641284
-m, --minimal Perform a fast build, which disables certain tasks
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
jest.mock('@rushstack/node-core-library');
5+
6+
import { FileSystem } from '@rushstack/node-core-library';
7+
import { StringBufferTerminalProvider, Terminal } from '@rushstack/terminal';
8+
9+
import { ShowExistingFailureLogsPlugin } from '../ShowExistingFailureLogsPlugin';
10+
import { PhasedCommandHooks } from '../../../pluginFramework/PhasedCommandHooks';
11+
import { OperationStatus } from '../OperationStatus';
12+
13+
describe(ShowExistingFailureLogsPlugin.name, () => {
14+
let mockTerminalProvider: StringBufferTerminalProvider;
15+
let mockTerminal: Terminal;
16+
let hooks: PhasedCommandHooks;
17+
let plugin: ShowExistingFailureLogsPlugin;
18+
19+
beforeEach(() => {
20+
mockTerminalProvider = new StringBufferTerminalProvider(false);
21+
mockTerminal = new Terminal(mockTerminalProvider);
22+
hooks = new PhasedCommandHooks();
23+
plugin = new ShowExistingFailureLogsPlugin({ terminal: mockTerminal });
24+
});
25+
26+
afterEach(() => {
27+
jest.restoreAllMocks();
28+
});
29+
30+
it('should apply the plugin to hooks', () => {
31+
plugin.apply(hooks);
32+
expect(hooks.beforeExecuteOperation.isUsed()).toBe(true);
33+
});
34+
35+
it('should handle operations with existing error logs', async () => {
36+
// Mock FileSystem.existsAsync to return true (error log exists)
37+
jest.spyOn(FileSystem, 'existsAsync').mockResolvedValue(true);
38+
39+
// Apply the plugin
40+
plugin.apply(hooks);
41+
42+
// Create a minimal mock context
43+
const mockRunnerContext = {
44+
operation: {
45+
logFilenameIdentifier: 'test-operation',
46+
associatedProject: {
47+
projectFolder: '/test/project',
48+
packageName: 'test-package'
49+
}
50+
},
51+
_operationMetadataManager: {
52+
tryRestoreAsync: jest.fn()
53+
},
54+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55+
runWithTerminalAsync: jest.fn(async (callback: any) => {
56+
await callback(mockTerminal, mockTerminalProvider);
57+
})
58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59+
} as any;
60+
61+
// Trigger the beforeExecuteOperation hook
62+
const result = await hooks.beforeExecuteOperation.promise(mockRunnerContext);
63+
64+
expect(result).toBe(OperationStatus.Failure);
65+
expect(FileSystem.existsAsync).toHaveBeenCalled();
66+
});
67+
68+
it('should handle operations without error logs', async () => {
69+
// Mock FileSystem.existsAsync to return false (no error log)
70+
jest.spyOn(FileSystem, 'existsAsync').mockResolvedValue(false);
71+
72+
// Apply the plugin
73+
plugin.apply(hooks);
74+
75+
// Create a minimal mock context
76+
const mockRunnerContext = {
77+
operation: {
78+
logFilenameIdentifier: 'test-operation',
79+
associatedProject: {
80+
projectFolder: '/test/project'
81+
}
82+
},
83+
_operationMetadataManager: {
84+
tryRestoreAsync: jest.fn()
85+
},
86+
runWithTerminalAsync: jest.fn()
87+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
88+
} as any;
89+
90+
// Trigger the beforeExecuteOperation hook
91+
const result = await hooks.beforeExecuteOperation.promise(mockRunnerContext);
92+
93+
expect(result).toBe(OperationStatus.Skipped);
94+
expect(FileSystem.existsAsync).toHaveBeenCalled();
95+
expect(mockRunnerContext.runWithTerminalAsync).not.toHaveBeenCalled();
96+
});
97+
});

0 commit comments

Comments
 (0)