[tests] replace spinner messages with normal output during tests (#8634)

Convert spinner output to simple prints during test runs. This makes it easier to write tests against the output of commands.
This commit is contained in:
Sean Massa
2022-09-28 12:52:40 -05:00
committed by GitHub
parent 8814fc1515
commit a0ead28369
3 changed files with 27 additions and 24 deletions

View File

@@ -4,6 +4,8 @@ import wait, { StopSpinner } from './wait';
import type { WritableTTY } from '../../types'; import type { WritableTTY } from '../../types';
import { errorToString } from '../is-error'; import { errorToString } from '../is-error';
const IS_TEST = process.env.NODE_ENV === 'test';
export interface OutputOptions { export interface OutputOptions {
debug?: boolean; debug?: boolean;
} }
@@ -108,12 +110,15 @@ export class Output {
}; };
spinner = (message: string, delay: number = 300): void => { spinner = (message: string, delay: number = 300): void => {
this.spinnerMessage = message;
if (this.debugEnabled) { if (this.debugEnabled) {
this.debug(`Spinner invoked (${message}) with a ${delay}ms delay`); this.debug(`Spinner invoked (${message}) with a ${delay}ms delay`);
return; return;
} }
if (this.stream.isTTY) { if (IS_TEST || !this.stream.isTTY) {
this.print(`${message}\n`);
} else {
this.spinnerMessage = message;
if (this._spinner) { if (this._spinner) {
this._spinner.text = message; this._spinner.text = message;
} else { } else {
@@ -125,8 +130,6 @@ export class Output {
delay delay
); );
} }
} else {
this.print(`${message}\n`);
} }
}; };

View File

@@ -38,11 +38,11 @@ describe('list', () => {
await list(client); await list(client);
const output = await readOutputStream(client, 4); const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]); const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]); const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift(); data.shift();
expect(org).toEqual(team[0].slug); expect(org).toEqual(team[0].slug);
@@ -81,11 +81,11 @@ describe('list', () => {
client.setArgv('-S', user.username); client.setArgv('-S', user.username);
await list(client); await list(client);
const output = await readOutputStream(client, 4); const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]); const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]); const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift(); data.shift();
expect(org).toEqual(user.username); expect(org).toEqual(user.username);
@@ -116,11 +116,11 @@ describe('list', () => {
client.setArgv(deployment.name); client.setArgv(deployment.name);
await list(client); await list(client);
const output = await readOutputStream(client, 4); const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]); const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]); const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift(); data.shift();
expect(org).toEqual(teamSlug || team[0].slug); expect(org).toEqual(teamSlug || team[0].slug);

View File

@@ -22,10 +22,10 @@ describe('project', () => {
client.setArgv('project', 'ls'); client.setArgv('project', 'ls');
await projects(client); await projects(client);
const output = await readOutputStream(client, 2); const output = await readOutputStream(client, 3);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[1]);
const header: string[] = parseSpacedTableRow(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
data.pop(); data.pop();
expect(org).toEqual(user.username); expect(org).toEqual(user.username);
@@ -47,10 +47,10 @@ describe('project', () => {
client.setArgv('project', 'ls'); client.setArgv('project', 'ls');
await projects(client); await projects(client);
const output = await readOutputStream(client, 2); const output = await readOutputStream(client, 3);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[1]);
const header: string[] = parseSpacedTableRow(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
data.pop(); data.pop();
expect(org).toEqual(user.username); expect(org).toEqual(user.username);