Skip to content

Commit ddc3cca

Browse files
Copilotdmichon-msft
andcommitted
Address feedback: export env var constant and simplify test mocks
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent 490659b commit ddc3cca

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

libraries/rush-lib/src/logic/operations/IgnoredParametersPlugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import type { IOperationExecutionResult } from './IOperationExecutionResult';
77

88
const PLUGIN_NAME: string = 'IgnoredParametersPlugin';
99

10+
/**
11+
* Environment variable name for forwarding ignored parameters to child processes
12+
* @public
13+
*/
14+
export const RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR: string =
15+
'RUSHSTACK_OPERATION_IGNORED_PARAMETERS';
16+
1017
/**
1118
* Phased command plugin that forwards the value of the `parameterNamesToIgnore` operation setting
1219
* to child processes as the RUSHSTACK_OPERATION_IGNORED_PARAMETERS environment variable.
@@ -20,7 +27,7 @@ export class IgnoredParametersPlugin implements IPhasedCommandPlugin {
2027

2128
// If there are parameter names to ignore, set the environment variable
2229
if (settings?.parameterNamesToIgnore && settings.parameterNamesToIgnore.length > 0) {
23-
env.RUSHSTACK_OPERATION_IGNORED_PARAMETERS = settings.parameterNamesToIgnore.join(' ');
30+
env[RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR] = settings.parameterNamesToIgnore.join(' ');
2431
}
2532

2633
return env;

libraries/rush-lib/src/logic/operations/test/IgnoredParametersPlugin.test.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,27 @@ import type { Operation } from '../Operation';
1111
import type { ICommandLineJson } from '../../../api/CommandLineJson';
1212
import { PhasedOperationPlugin } from '../PhasedOperationPlugin';
1313
import { ShellOperationRunnerPlugin } from '../ShellOperationRunnerPlugin';
14-
import { IgnoredParametersPlugin } from '../IgnoredParametersPlugin';
14+
import {
15+
IgnoredParametersPlugin,
16+
RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR
17+
} from '../IgnoredParametersPlugin';
1518
import {
1619
type ICreateOperationsContext,
1720
PhasedCommandHooks
1821
} from '../../../pluginFramework/PhasedCommandHooks';
1922
import { RushProjectConfiguration } from '../../../api/RushProjectConfiguration';
2023
import type { IEnvironment } from '../../../utilities/Utilities';
24+
import type { IOperationRunnerContext } from '../IOperationRunner';
25+
import type { IOperationExecutionResult } from '../IOperationExecutionResult';
2126

2227
/**
2328
* Helper function to create a minimal mock record for testing the createEnvironmentForOperation hook
2429
*/
25-
function createMockRecord(operation: Operation): any {
30+
function createMockRecord(operation: Operation): IOperationRunnerContext & IOperationExecutionResult {
2631
return {
2732
operation,
28-
collatedWriter: {} as any,
29-
debugMode: false,
30-
quietMode: true,
31-
_operationMetadataManager: {} as any,
32-
stopwatch: {} as any,
33-
status: {} as any,
34-
environment: undefined,
35-
error: undefined,
36-
silent: false,
37-
stdioSummarizer: {} as any,
38-
problemCollector: {} as any,
39-
nonCachedDurationMs: undefined,
40-
metadataFolderPath: undefined,
41-
logFilePaths: undefined,
42-
getStateHash: () => '',
43-
getStateHashComponents: () => [],
44-
runWithTerminalAsync: async () => {}
45-
};
33+
environment: undefined
34+
} as IOperationRunnerContext & IOperationExecutionResult;
4635
}
4736

4837
describe(IgnoredParametersPlugin.name, () => {
@@ -110,7 +99,7 @@ describe(IgnoredParametersPlugin.name, () => {
11099
const envA: IEnvironment = hooks.createEnvironmentForOperation.call({ ...process.env }, mockRecordA);
111100

112101
// Verify the environment variable is set correctly for project 'a'
113-
expect(envA.RUSHSTACK_OPERATION_IGNORED_PARAMETERS).toBe('--production');
102+
expect(envA[RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR]).toBe('--production');
114103

115104
// Test project 'b' which has parameterNamesToIgnore: ["--verbose", "--config", "--mode", "--tags"]
116105
const operationB = Array.from(operations).find((op) => op.name === 'b');
@@ -121,7 +110,7 @@ describe(IgnoredParametersPlugin.name, () => {
121110
const envB: IEnvironment = hooks.createEnvironmentForOperation.call({ ...process.env }, mockRecordB);
122111

123112
// Verify the environment variable is set correctly for project 'b'
124-
expect(envB.RUSHSTACK_OPERATION_IGNORED_PARAMETERS).toBe('--verbose --config --mode --tags');
113+
expect(envB[RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR]).toBe('--verbose --config --mode --tags');
125114
});
126115

127116
it('should not set environment variable when parameterNamesToIgnore is not specified', async () => {
@@ -177,6 +166,6 @@ describe(IgnoredParametersPlugin.name, () => {
177166
const env: IEnvironment = hooks.createEnvironmentForOperation.call({ ...process.env }, mockRecord);
178167

179168
// Verify the environment variable is not set
180-
expect(env.RUSHSTACK_OPERATION_IGNORED_PARAMETERS).toBeUndefined();
169+
expect(env[RUSHSTACK_OPERATION_IGNORED_PARAMETERS_ENV_VAR]).toBeUndefined();
181170
});
182171
});

0 commit comments

Comments
 (0)