-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #435 from oclif/mdonnalley/oclif-test-v4
test: use oclif/test v4
- Loading branch information
Showing
3 changed files
with
285 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
Oops, something went wrong.