From 5c324aacf84d2106cd72450f8b44a7b2d906415f Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Tue, 7 May 2024 10:15:02 -0600 Subject: [PATCH] test: strip ansi for tests --- src/commands/version.ts | 2 +- test/commands/version.test.ts | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/commands/version.ts b/src/commands/version.ts index f7766ec..014a621 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -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')}: diff --git a/test/commands/version.test.ts b/test/commands/version.test.ts index 47c13dc..0d7a7cb 100644 --- a/test/commands/version.test.ts +++ b/test/commands/version.test.ts @@ -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' @@ -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