Skip to content

Commit

Permalink
test: strip ansi for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 7, 2024
1 parent a55930d commit 5c324aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class Version extends Command {
${ansis.bold('Node Version')}:
\t${versionDetail.nodeVersion}
${ansis.bold('Plugin Versions')}:
${ansis.bold('Plugin Version')}:
\t${(versionDetail.pluginVersions ?? []).join(EOL + '\t')}
${ansis.bold('OS and Version')}:
Expand Down
30 changes: 17 additions & 13 deletions test/commands/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {expect, test} from '@oclif/test'
import {Ansis} from 'ansis'
import {readFileSync} from 'node:fs'
import {release as osRelease, type as osType, userInfo as osUserInfo} from 'node:os'
import {resolve, sep} from 'node:path'

const ansis = new Ansis()

const pjson = JSON.parse(readFileSync(resolve('package.json'), 'utf8'))

const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown'
Expand All @@ -22,19 +25,20 @@ describe('version', () => {
.stdout()
.command(['version', '--verbose'])
.end('runs version --verbose', (output) => {
expect(output.stdout).to.contain(' CLI Version:')
expect(output.stdout).to.contain(`\t@oclif/plugin-version/${pjson.version}`)
expect(output.stdout).to.contain(' Architecture:')
expect(output.stdout).to.contain(`\t${process.platform}-${process.arch}`)
expect(output.stdout).to.contain(' Node Version:')
expect(output.stdout).to.contain(`\tnode-${process.version}`)
expect(output.stdout).to.contain(' Plugin Version:')
expect(output.stdout).to.contain(' OS and Version:')
expect(output.stdout).to.contain(`\t${osType()} ${osRelease()}`)
expect(output.stdout).to.contain(' Shell:')
expect(output.stdout).to.contain(`\t${getShell()}`)
expect(output.stdout).to.contain(' Root Path:')
expect(output.stdout).to.contain(`\t${process.cwd()}`)
const stdout = ansis.strip(output.stdout)
expect(stdout).to.contain(' CLI Version:')
expect(stdout).to.contain(`\t@oclif/plugin-version/${pjson.version}`)
expect(stdout).to.contain(' Architecture:')
expect(stdout).to.contain(`\t${process.platform}-${process.arch}`)
expect(stdout).to.contain(' Node Version:')
expect(stdout).to.contain(`\tnode-${process.version}`)
expect(stdout).to.contain(' Plugin Version:')
expect(stdout).to.contain(' OS and Version:')
expect(stdout).to.contain(`\t${osType()} ${osRelease()}`)
expect(stdout).to.contain(' Shell:')
expect(stdout).to.contain(`\t${getShell()}`)
expect(stdout).to.contain(' Root Path:')
expect(stdout).to.contain(`\t${process.cwd()}`)
})

test
Expand Down

0 comments on commit 5c324aa

Please sign in to comment.