Skip to content

Commit dfc7510

Browse files
[terminal] Add a getAllOutputAsChunks function to StringBufferTerminalProvider that returns an array of chunks that were written to the terminal provider. (#5534)
* Add a StringBufferTerminalProvider.getAllOutputAsChunks function that returns an array of chunks that were written to the terminal provider. * fixup! Add a StringBufferTerminalProvider.getAllOutputAsChunks function that returns an array of chunks that were written to the terminal provider. * Update tests to use StringBufferTerminalProvider.getAllOutputAsChunks. * fixup! Update tests to use StringBufferTerminalProvider.getAllOutputAsChunks. * fixup! Update tests to use StringBufferTerminalProvider.getAllOutputAsChunks. * Remove the severityAsNames option. * fixup! Update tests to use StringBufferTerminalProvider.getAllOutputAsChunks. * fixup! Update tests to use StringBufferTerminalProvider.getAllOutputAsChunks. * Eliminate variadic function invocation. Co-authored-by: David Michon <[email protected]> * fixup! Eliminate variadic function invocation. * Combine sequential logging statements in getAllOutputAsChunks and replace 'asFlat' with 'asLines' * fixup! Combine sequential logging statements in getAllOutputAsChunks and replace 'asFlat' with 'asLines' * fixup! Combine sequential logging statements in getAllOutputAsChunks and replace 'asFlat' with 'asLines' * fixup! Combine sequential logging statements in getAllOutputAsChunks and replace 'asFlat' with 'asLines' --------- Co-authored-by: David Michon <[email protected]>
1 parent f361e45 commit dfc7510

File tree

35 files changed

+2103
-1043
lines changed

35 files changed

+2103
-1043
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-config-file",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-config-file"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/localization-utilities",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@rushstack/localization-utilities"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/operation-graph",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@rushstack/operation-graph"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/terminal",
5+
"comment": "Add a `getAllOutputAsChunks` function to `StringBufferTerminalProvider` that returns an array of chunks that were written to the terminal provider.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/terminal"
10+
}

common/reviews/api/terminal.api.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ export interface INormalizeNewlinesTextRewriterOptions {
151151
newlineKind: NewlineKind;
152152
}
153153

154+
// @beta (undocumented)
155+
export interface IOutputChunk {
156+
// (undocumented)
157+
severity: TerminalProviderSeverityName;
158+
// (undocumented)
159+
text: string;
160+
}
161+
154162
// @beta (undocumented)
155163
export type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions;
156164

@@ -192,9 +200,14 @@ export interface IStdioSummarizerOptions extends ITerminalWritableOptions {
192200
trailingLines?: number;
193201
}
194202

203+
// @beta (undocumented)
204+
export interface IStringBufferOutputChunksOptions extends IStringBufferOutputOptions {
205+
asLines?: boolean;
206+
}
207+
195208
// @beta (undocumented)
196209
export interface IStringBufferOutputOptions {
197-
normalizeSpecialCharacters: boolean;
210+
normalizeSpecialCharacters?: boolean;
198211
}
199212

200213
// @beta (undocumented)
@@ -381,6 +394,13 @@ export class StringBufferTerminalProvider implements ITerminalProvider {
381394
getAllOutput(sparse?: false, options?: IStringBufferOutputOptions): IAllStringBufferOutput;
382395
// (undocumented)
383396
getAllOutput(sparse: true, options?: IStringBufferOutputOptions): Partial<IAllStringBufferOutput>;
397+
getAllOutputAsChunks(options?: IStringBufferOutputChunksOptions & {
398+
asLines?: false;
399+
}): IOutputChunk[];
400+
// (undocumented)
401+
getAllOutputAsChunks(options: IStringBufferOutputChunksOptions & {
402+
asLines: true;
403+
}): `[${string}] ${string}`[];
384404
getDebugOutput(options?: IStringBufferOutputOptions): string;
385405
getErrorOutput(options?: IStringBufferOutputOptions): string;
386406
getOutput(options?: IStringBufferOutputOptions): string;
@@ -389,7 +409,7 @@ export class StringBufferTerminalProvider implements ITerminalProvider {
389409
getVerboseOutput(options?: IStringBufferOutputOptions): string;
390410
getWarningOutput(options?: IStringBufferOutputOptions): string;
391411
readonly supportsColor: boolean;
392-
write(data: string, severity: TerminalProviderSeverity): void;
412+
write(text: string, severity: TerminalProviderSeverity): void;
393413
}
394414

395415
// @beta
@@ -429,6 +449,9 @@ export enum TerminalProviderSeverity {
429449
warning = 1
430450
}
431451

452+
// @beta (undocumented)
453+
export type TerminalProviderSeverityName = keyof typeof TerminalProviderSeverity;
454+
432455
// @beta
433456
export class TerminalStreamWritable extends Writable {
434457
constructor(options: ITerminalStreamWritableOptions);

libraries/heft-config-file/src/test/ConfigurationFile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('ConfigurationFile', () => {
2626
});
2727

2828
afterEach(() => {
29-
expect(terminalProvider.getAllOutput(true)).toMatchSnapshot();
29+
expect(terminalProvider.getAllOutputAsChunks({ asLines: true })).toMatchSnapshot();
3030
});
3131

3232
describe('A simple config file', () => {

libraries/heft-config-file/src/test/__snapshots__/ConfigurationFile.test.ts.snap

Lines changed: 106 additions & 102 deletions
Large diffs are not rendered by default.

libraries/localization-utilities/src/parsers/test/__snapshots__/parseResx.test.ts.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Array [
2222
]
2323
`;
2424

25-
exports[`parseResx correctly ignores a string: terminal output 1`] = `Object {}`;
25+
exports[`parseResx correctly ignores a string: terminal output 1`] = `Array []`;
2626

2727
exports[`parseResx fails to parse a RESX file with a duplicate string: Loc file 1`] = `
2828
Object {
@@ -34,9 +34,9 @@ Object {
3434
`;
3535

3636
exports[`parseResx fails to parse a RESX file with a duplicate string: terminal output 1`] = `
37-
Object {
38-
"error": "test.resx(6,45): Duplicate string value \\"stringA\\"[n]",
39-
}
37+
Array [
38+
"[ error] test.resx(6,45): Duplicate string value \\"stringA\\"[n]",
39+
]
4040
`;
4141

4242
exports[`parseResx ignoreMissingResxComments when set to false, warns on a missing comment: Loc file 1`] = `
@@ -49,9 +49,9 @@ Object {
4949
`;
5050

5151
exports[`parseResx ignoreMissingResxComments when set to false, warns on a missing comment: terminal output 1`] = `
52-
Object {
53-
"warning": "test.resx(3,59): Missing string comment in <data> element[n]",
54-
}
52+
Array [
53+
"[warning] test.resx(3,59): Missing string comment in <data> element[n]",
54+
]
5555
`;
5656
5757
exports[`parseResx ignoreMissingResxComments when set to true, ignores a missing comment: Loc file 1`] = `
@@ -63,7 +63,7 @@ Object {
6363
}
6464
`;
6565
66-
exports[`parseResx ignoreMissingResxComments when set to true, ignores a missing comment: terminal output 1`] = `Object {}`;
66+
exports[`parseResx ignoreMissingResxComments when set to true, ignores a missing comment: terminal output 1`] = `Array []`;
6767
6868
exports[`parseResx ignoreMissingResxComments when set to undefined, warns on a missing comment: Loc file 1`] = `
6969
Object {
@@ -74,7 +74,7 @@ Object {
7474
}
7575
`;
7676
77-
exports[`parseResx ignoreMissingResxComments when set to undefined, warns on a missing comment: terminal output 1`] = `Object {}`;
77+
exports[`parseResx ignoreMissingResxComments when set to undefined, warns on a missing comment: terminal output 1`] = `Array []`;
7878
7979
exports[`parseResx parses a valid file with a schema: Loc file 1`] = `
8080
Object {
@@ -89,7 +89,7 @@ Object {
8989
}
9090
`;
9191
92-
exports[`parseResx parses a valid file with a schema: terminal output 1`] = `Object {}`;
92+
exports[`parseResx parses a valid file with a schema: terminal output 1`] = `Array []`;
9393
9494
exports[`parseResx parses a valid file with quotemarks: Loc file 1`] = `
9595
Object {
@@ -100,7 +100,7 @@ Object {
100100
}
101101
`;
102102
103-
exports[`parseResx parses a valid file with quotemarks: terminal output 1`] = `Object {}`;
103+
exports[`parseResx parses a valid file with quotemarks: terminal output 1`] = `Array []`;
104104
105105
exports[`parseResx prints an error on invalid XML: Loc file 1`] = `
106106
Object {
@@ -112,9 +112,9 @@ Object {
112112
`;
113113
114114
exports[`parseResx prints an error on invalid XML: terminal output 1`] = `
115-
Object {
116-
"error": "test.resx(3,41): Found unexpected non-empty text node in RESX <data> element[n]",
117-
}
115+
Array [
116+
"[ error] test.resx(3,41): Found unexpected non-empty text node in RESX <data> element[n]",
117+
]
118118
`;
119119
120120
exports[`parseResx resxNewlineNormalization when set to CrLf, normalizes to CrLf: Loc file 1`] = `
@@ -128,7 +128,7 @@ Object {
128128
}
129129
`;
130130
131-
exports[`parseResx resxNewlineNormalization when set to CrLf, normalizes to CrLf: terminal output 1`] = `Object {}`;
131+
exports[`parseResx resxNewlineNormalization when set to CrLf, normalizes to CrLf: terminal output 1`] = `Array []`;
132132
133133
exports[`parseResx resxNewlineNormalization when set to Lf, normalizes to Lf: Loc file 1`] = `
134134
Object {
@@ -141,4 +141,4 @@ Object {
141141
}
142142
`;
143143
144-
exports[`parseResx resxNewlineNormalization when set to Lf, normalizes to Lf: terminal output 1`] = `Object {}`;
144+
exports[`parseResx resxNewlineNormalization when set to Lf, normalizes to Lf: terminal output 1`] = `Array []`;

libraries/localization-utilities/src/parsers/test/parseResx.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe(parseResx.name, () => {
1616
});
1717

1818
afterEach(() => {
19-
expect(terminalProvider.getAllOutput(true)).toMatchSnapshot('terminal output');
19+
expect(terminalProvider.getAllOutputAsChunks({ asLines: true })).toMatchSnapshot('terminal output');
2020
});
2121

2222
async function testResxAsync(

0 commit comments

Comments
 (0)