|
| 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 | +import * as path from 'node:path'; |
| 5 | + |
| 6 | +import { FileSystem, JsonFile } from '@rushstack/node-core-library'; |
| 7 | + |
| 8 | +import { Rush } from '../Rush'; |
| 9 | +import { RushConfiguration } from '../RushConfiguration'; |
| 10 | + |
| 11 | +const TEMP_FOLDER: string = path.join(__dirname, 'temp', 'RushConfigurationReporting'); |
| 12 | +const RUSH_JSON_PATH: string = path.join(TEMP_FOLDER, 'rush.json'); |
| 13 | + |
| 14 | +function writeRushJson(reporting?: unknown): void { |
| 15 | + JsonFile.save( |
| 16 | + { |
| 17 | + rushVersion: Rush.version, |
| 18 | + pnpmVersion: '10.0.0', |
| 19 | + projects: [], |
| 20 | + ...(reporting === undefined ? {} : { reporting }) |
| 21 | + }, |
| 22 | + RUSH_JSON_PATH |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +describe('RushConfiguration reporting configuration', () => { |
| 27 | + beforeEach(() => { |
| 28 | + FileSystem.ensureEmptyFolder(TEMP_FOLDER); |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(() => { |
| 32 | + FileSystem.ensureEmptyFolder(TEMP_FOLDER); |
| 33 | + }); |
| 34 | + |
| 35 | + it('defaults agent environment variables to an empty array', () => { |
| 36 | + writeRushJson(); |
| 37 | + |
| 38 | + const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(RUSH_JSON_PATH); |
| 39 | + |
| 40 | + expect(rushConfiguration.reportingConfiguration.agentEnvironmentVariables).toEqual([]); |
| 41 | + }); |
| 42 | + |
| 43 | + it('loads configured agent environment variables', () => { |
| 44 | + writeRushJson({ |
| 45 | + agentEnvironmentVariables: ['MY_AGENT_CLI', 'ANOTHER_AGENT'] |
| 46 | + }); |
| 47 | + |
| 48 | + const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(RUSH_JSON_PATH); |
| 49 | + |
| 50 | + expect(rushConfiguration.reportingConfiguration.agentEnvironmentVariables).toEqual([ |
| 51 | + 'MY_AGENT_CLI', |
| 52 | + 'ANOTHER_AGENT' |
| 53 | + ]); |
| 54 | + }); |
| 55 | + |
| 56 | + it('rejects invalid agent environment variables', () => { |
| 57 | + writeRushJson({ |
| 58 | + agentEnvironmentVariables: ['MY_AGENT_CLI', 123] |
| 59 | + }); |
| 60 | + |
| 61 | + expect(() => RushConfiguration.loadFromConfigurationFile(RUSH_JSON_PATH)).toThrow( |
| 62 | + /agentEnvironmentVariables/ |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + it('rejects unsupported reporting settings', () => { |
| 67 | + writeRushJson({ |
| 68 | + agentEnvironmentVariables: [], |
| 69 | + defaultReporter: 'ai' |
| 70 | + }); |
| 71 | + |
| 72 | + expect(() => RushConfiguration.loadFromConfigurationFile(RUSH_JSON_PATH)).toThrow(/defaultReporter/); |
| 73 | + }); |
| 74 | +}); |
0 commit comments