Repository navigation
Expand file tree
/
Copy pathoutputSelection.test.ts
More file actions
99 lines (90 loc) · 4.96 KB
/
Copy pathoutputSelection.test.ts
File metadata and controls
99 lines (90 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import {
findRushJsonPath,
getAgentCommandName,
readUseRushReporter,
selectClientOutputMode
} from '../outputSelection';
describe(selectClientOutputMode.name, () => {
it.each([
{ argv: ['build'], environment: {}, mode: 'legacy' },
{ argv: ['build'], environment: { RUSHD_OUTPUT: 'agent' }, mode: 'agent' },
{ argv: ['build'], environment: { RUSHD_OUTPUT: ' AGENT ' }, mode: 'agent' },
{ argv: ['build'], environment: { COPILOT_CLI: '1' }, mode: 'agent' },
{ argv: ['build'], environment: { COPILOT_CLI: 'false' }, mode: 'legacy' },
{ argv: ['build'], environment: { COPILOT_CLI: '1', RUSHD_OUTPUT: 'legacy' }, mode: 'legacy' },
{ argv: ['build'], environment: { CLAUDECODE: '1' }, mode: 'legacy' },
{ argv: ['build'], environment: { COPILOT_CLI: '1', RUSH_REPORTER: 'legacy' }, mode: 'agent' },
{ argv: ['build'], environment: { COPILOT_CLI: '1', RUSH_REPORTER: ' LEGACY ' }, mode: 'agent' },
// Explicit reporter controls always keep the native reporter path, and nothing is written ahead of it.
{ argv: ['build', '--reporter=ai'], environment: { RUSHD_OUTPUT: 'agent' }, mode: 'legacy' },
{ argv: ['build', '--reporter', 'ai'], environment: { COPILOT_CLI: '1' }, mode: 'legacy' },
{ argv: ['build', '--reporter=ai', '--no-daemon'], environment: { COPILOT_CLI: '1' }, mode: 'legacy' },
{ argv: ['build', '--no-daemon'], environment: { RUSHD_OUTPUT: 'agent' }, mode: 'legacy' },
{ argv: ['build', '--output', 'x.log'], environment: { RUSHD_OUTPUT: 'agent' }, mode: 'legacy' },
{ argv: ['build'], environment: { RUSHD_OUTPUT: 'agent', RUSH_REPORTER: 'ai' }, mode: 'legacy' },
{ argv: ['build'], environment: { RUSHD_OUTPUT: 'agent', RUSH_LOG_LEVEL: 'debug' }, mode: 'legacy' },
{ argv: ['build', '--', '--reporter=ai'], environment: { RUSHD_OUTPUT: 'agent' }, mode: 'agent' }
])('selects $mode for $argv with $environment', ({ argv, environment, mode }) => {
expect(selectClientOutputMode({ argv, environment })).toBe(mode);
});
it('keeps useRushReporter repositories on the native reporter output', () => {
expect(
selectClientOutputMode({ argv: ['build'], environment: { COPILOT_CLI: '1' }, useRushReporter: true })
).toBe('legacy');
});
});
describe(getAgentCommandName.name, () => {
it.each([
{ argv: ['build'], commandName: 'build' },
{ argv: ['--wait-timeout', '1.25', 'build'], commandName: 'build' },
{ argv: ['--wait-timeout=2', 'build', '-t', 'a'], commandName: 'build' },
{ argv: ['--no-wait', 'rebuild'], commandName: 'rebuild' },
{ argv: ['--', 'build'], commandName: undefined },
{ argv: ['-q', 'build'], commandName: 'build' },
{ argv: ['--quiet', '--no-wait', '-q', 'build'], commandName: 'build' },
{ argv: ['-q'], commandName: undefined },
{ argv: ['-q', '--debug', 'build'], commandName: undefined },
{ argv: ['-d', 'build'], commandName: undefined },
{ argv: ['daemon', 'status'], commandName: undefined },
{ argv: ['-q', 'daemon', 'status'], commandName: undefined },
{ argv: ['check'], commandName: undefined },
{ argv: ['update-autoinstaller', '--name', 'x'], commandName: undefined },
{ argv: ['build', '--help'], commandName: undefined },
{ argv: ['build', '-h'], commandName: undefined },
{ argv: ['build', '--', '--help'], commandName: 'build' },
{ argv: [], commandName: undefined }
])('returns $commandName for $argv', ({ argv, commandName }) => {
expect(getAgentCommandName(argv)).toBe(commandName);
});
});
describe(readUseRushReporter.name, () => {
let folder: string;
beforeEach(() => {
folder = fs.mkdtempSync(path.join(os.tmpdir(), 'rush-output-selection-'));
fs.writeFileSync(path.join(folder, 'rush.json'), '{}');
fs.mkdirSync(path.join(folder, 'common', 'config', 'rush'), { recursive: true });
});
afterEach(() => fs.rmSync(folder, { recursive: true, force: true }));
function write(contents: string): void {
fs.writeFileSync(path.join(folder, 'common', 'config', 'rush', 'experiments.json'), contents);
}
it('reads the opt-in and ignores commented-out settings', () => {
const rushJsonPath: string = path.join(folder, 'rush.json');
expect(readUseRushReporter(rushJsonPath)).toBe(false);
write('{\n // "useRushReporter": true,\n /* "useRushReporter": true */\n}\n');
expect(readUseRushReporter(rushJsonPath)).toBe(false);
write('{ "useRushReporter": false }');
expect(readUseRushReporter(rushJsonPath)).toBe(false);
write('{\n "useRushReporter": true\n}\n');
expect(readUseRushReporter(rushJsonPath)).toBe(true);
});
it('finds rush.json from a nested folder', () => {
const nested: string = path.join(folder, 'common', 'config');
expect(findRushJsonPath(nested)).toBe(path.join(folder, 'rush.json'));
});
});