Skip to content

Commit

Permalink
Merge pull request #435 from oclif/mdonnalley/oclif-test-v4
Browse files Browse the repository at this point in the history
test: use oclif/test v4
  • Loading branch information
mdonnalley authored May 22, 2024
2 parents 2cd0fdc + 20290a0 commit cf5a87a
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 620 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"ansis": "^3.2.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^18",
"@commitlint/config-conventional": "^19",
"@oclif/plugin-help": "^6",
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3",
"@oclif/test": "^4",
"@types/chai": "^4.3.11",
"@types/mocha": "^10",
"@types/node": "^18",
"chai": "^4.4.1",
"commitlint": "^18",
"commitlint": "^19",
"eslint": "^8.57.0",
"eslint-config-oclif": "^5",
"eslint-config-oclif-typescript": "^3",
Expand Down
107 changes: 45 additions & 62 deletions test/commands/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,51 @@
import {expect, test} from '@oclif/test'
import {Ansis} from 'ansis'
import {runCommand} from '@oclif/test'
import {expect} from 'chai'
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()
import {release, type} from 'node:os'
import {resolve} from 'node:path'

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

const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown'

describe('version', () => {
const stdout = `@oclif/plugin-version/${pjson.version} ${process.platform}-${process.arch} node-${process.version}
`

test
.stdout()
.command('version')
.end('runs version', (output) => {
expect(output.stdout).to.equal(stdout)
})

test
.stdout()
.command(['version', '--verbose'])
.end('runs version --verbose', (output) => {
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
.stdout()
.command(['version', '--json'])
.end('runs version --json', (output) => {
const json = JSON.parse(output.stdout)
expect(json).to.have.keys(['cliVersion', 'architecture', 'nodeVersion'])
})

test
.stdout()
.command(['version', '--json', '--verbose'])
.end('runs version --verbose --json', (output) => {
const json = JSON.parse(output.stdout)
expect(json).to.have.property('architecture', `${process.platform}-${process.arch}`)
expect(json).to.have.property('cliVersion', `@oclif/plugin-version/${pjson.version}`)
expect(json).to.have.property('nodeVersion', `node-${process.version}`)
expect(json).to.have.property('osVersion', `${osType()} ${osRelease()}`)
expect(json).to.have.property('pluginVersions')
expect(json.pluginVersions).to.an('array')
expect(json).to.have.property('shell')
expect(json.shell).to.be.equal(getShell(), `json.shell: ${json.shell} getShell(): ${getShell()}`)
expect(json).to.have.property('rootPath', process.cwd())
})
it('runs version', async () => {
const {stdout} = await runCommand('version')
expect(stdout).to.equal(
`@oclif/plugin-version/${pjson.version} ${process.platform}-${process.arch} node-${process.version}\n`,
)
})

it('runs version --verbose', async () => {
const {stdout} = await runCommand('version --verbose')
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${type()} ${release()}`)
expect(stdout).to.contain(' Shell:')
expect(stdout).to.contain(' Root Path:')
expect(stdout).to.contain(`\t${process.cwd()}`)
})

it('runs version --json', async () => {
const {stdout} = await runCommand('version --json')
const json = JSON.parse(stdout)
expect(json).to.have.keys(['cliVersion', 'architecture', 'nodeVersion'])
})

it('runs version --json --verbose', async () => {
const {stdout} = await runCommand('version --json --verbose')
const json = JSON.parse(stdout)
expect(json).to.have.property('architecture', `${process.platform}-${process.arch}`)
expect(json).to.have.property('cliVersion', `@oclif/plugin-version/${pjson.version}`)
expect(json).to.have.property('nodeVersion', `node-${process.version}`)
expect(json).to.have.property('osVersion', `${type()} ${release()}`)
expect(json).to.have.property('pluginVersions')
expect(json.pluginVersions).to.an('array')
expect(json).to.have.property('shell')
expect(json).to.have.property('rootPath', process.cwd())
})
})
// {"uid":1001,"gid":123,"username":"runner","homedir":"/home/runner","shell":"/bin/bash"}
Loading

0 comments on commit cf5a87a

Please sign in to comment.