Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/command/history/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export class List extends HistoryCommand implements LeafCommand {

return
}

const useColors = Boolean(process.stdout.isTTY)

const table = new Table({
head: ['Index', 'Timestamp', 'Reference', 'Postage stamp batch ID', 'File path', 'Upload type'],
style: {
head: ['green', 'bold'],
head: useColors ? ['green', 'bold'] : [],
border: useColors ? ['grey'] : [],
Comment on lines +31 to +32

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please cover the isTTY = false case with spec(s)?

@Riki0923 Riki0923 Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests to history.spec.ts file

},
wordWrap: true,
})
Expand Down
40 changes: 40 additions & 0 deletions test/command/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import chalk from 'chalk'
import { randomUUID } from 'crypto'
import { describeCommand, invokeTestCli } from '../utility'
import { getStampOption } from '../utility/stamp'
import colors from '@colors/colors/safe'

const ANSI_PATTERN = /\u001B\[\d+m/ //adding this for testing the ansi disable part

async function uploadTestFile() {
const uploadFilePath = `${__dirname}/../testpage/images/swarm.png`
Expand Down Expand Up @@ -124,6 +127,43 @@ describeCommand(
await invokeTestCli(['history', 'disable', '--yes'])
})
})

describe('ansi: list colors', () => {
const originalIsTTY = process.stdout.isTTY
const colorsWereEnabled = colors.enabled

beforeAll(() => {
colors.enable()
})

afterAll(() => {
if (!colorsWereEnabled) {
colors.disable()
}
})

afterEach(() => {
process.stdout.isTTY = originalIsTTY
invokeTestCli(['history', 'disable', '--yes'])
})

it('should not use colors when stdout is not a TTY', async () => {
await invokeTestCli(['history', 'enable'])
process.stdout.isTTY = false
await invokeTestCli(['history', 'list'])

expect(consoleMessages[1]).not.toMatch(ANSI_PATTERN)
expect(consoleMessages[1]).toContain('Timestamp')
})

it('should use colors when stdout is a TTY', async () => {
await invokeTestCli(['history', 'enable'])
process.stdout.isTTY = true
await invokeTestCli(['history', 'list'])

expect(consoleMessages[1]).toMatch(ANSI_PATTERN)
})
})
},
{ configFileName: 'history' },
)
Loading