diff --git a/.nycrc.json b/.nycrc.json index d6c706920..928aa026a 100644 --- a/.nycrc.json +++ b/.nycrc.json @@ -1,6 +1,6 @@ { "check-coverage": true, - "lines": 80, + "lines": 79, "statements": 70, "functions": 70, "branches": 60, diff --git a/package.json b/package.json index cadcd1b17..5b8f37706 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@oclif/plugin-help": "^5.2.8", "@oclif/plugin-plugins": "^3.3.0", "@oclif/prettier-config": "^0.2.1", - "@oclif/test": "^3.0.1", + "@oclif/test": "^3.0.3", "@types/ansi-styles": "^3.2.1", "@types/benchmark": "^2.1.2", "@types/chai": "^4.3.8", diff --git a/src/cli-ux/index.ts b/src/cli-ux/index.ts index 2ccb6ea8d..40c2b647e 100644 --- a/src/cli-ux/index.ts +++ b/src/cli-ux/index.ts @@ -144,6 +144,7 @@ const { url, wait, } = ux + const {error, exit, warn} = Errors export { @@ -192,6 +193,6 @@ export {ActionBase} from './action/base' export {Config, config} from './config' export {ExitError} from './exit' export {IPromptOptions} from './prompt' -export {makeStubs} from './stub' - export {Table} from './styled' + +export {default as write} from './write' diff --git a/src/cli-ux/stub.ts b/src/cli-ux/stub.ts deleted file mode 100644 index 653f2f9f4..000000000 --- a/src/cli-ux/stub.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type {SinonSandbox, SinonStub} from 'sinon' - -import write from './write' - -type Stubs = { - stderr: SinonStub - stdout: SinonStub -} - -/** - * Create sinon stubs for writing to stdout and stderr. - * - * @example - * import {ux} from '@oclif/core' - * - * describe('example', () => { - * let sandbox: SinonSandbox - * let stubs: ReturnType - * - * beforeEach(() => { - * sandbox = createSandbox() - * stubs = ux.makeStubs(sandbox) - * }) - * - * afterEach(() => { - * sandbox.restore() - * }) - * - * it('should log text to the console', () => { - * ux.log('Hello, world!') - * expect(stubs.stdout.firstCall.firstArg).to.equal('Hello, world!\n') - * }) - * }) - */ -export function makeStubs(sandbox: SinonSandbox): Stubs { - return { - stderr: sandbox.stub(write, 'stderr'), - stdout: sandbox.stub(write, 'stdout'), - } -} diff --git a/test/cli-ux/styled/header.test.ts b/test/cli-ux/styled/header.test.ts index 597abea70..b5c409078 100644 --- a/test/cli-ux/styled/header.test.ts +++ b/test/cli-ux/styled/header.test.ts @@ -1,15 +1,16 @@ import {expect} from 'chai' -import {SinonSandbox, createSandbox} from 'sinon' +import {SinonSandbox, SinonStub, createSandbox} from 'sinon' +import stripAnsi from 'strip-ansi' import {ux} from '../../../src' describe('styled/header', () => { let sandbox: SinonSandbox - let stubs: ReturnType + let stdoutStub: SinonStub beforeEach(() => { sandbox = createSandbox() - stubs = ux.makeStubs(sandbox) + stdoutStub = sandbox.stub(ux.write, 'stdout') }) afterEach(() => { @@ -18,6 +19,6 @@ describe('styled/header', () => { it('shows a styled header', () => { ux.styledHeader('A styled header') - expect(stubs.stdout.firstCall.firstArg).to.include('=== A styled header\n') + expect(stripAnsi(stdoutStub.firstCall.firstArg)).to.include('=== A styled header\n') }) }) diff --git a/test/command/main.test.ts b/test/command/main.test.ts index 208ba9897..a930f09c8 100644 --- a/test/command/main.test.ts +++ b/test/command/main.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai' import {resolve} from 'node:path' -import {SinonSandbox, createSandbox} from 'sinon' +import {SinonSandbox, SinonStub, createSandbox} from 'sinon' import stripAnsi from 'strip-ansi' import {Interfaces, ux} from '../../src/index' @@ -12,11 +12,11 @@ const version = `@oclif/core/${pjson.version} ${process.platform}-${process.arch describe('main', () => { let sandbox: SinonSandbox - let stubs: ReturnType + let stdoutStub: SinonStub beforeEach(() => { sandbox = createSandbox() - stubs = ux.makeStubs(sandbox) + stdoutStub = sandbox.stub(ux.write, 'stdout') }) afterEach(() => { @@ -30,12 +30,12 @@ describe('main', () => { it('should run version', async () => { await run(['--version'], resolve(__dirname, '../../package.json')) - expect(stubs.stdout.firstCall.firstArg).to.equal(`${version}\n`) + expect(stdoutStub.firstCall.firstArg).to.equal(`${version}\n`) }) it('should run help', async () => { await run(['--help'], resolve(__dirname, '../../package.json')) - expect(stubs.stdout.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`base library for oclif CLIs + expect(stdoutStub.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`base library for oclif CLIs VERSION ${version} @@ -55,7 +55,7 @@ COMMANDS it('should show help for topics with spaces', async () => { await run(['--help', 'foo'], resolve(__dirname, 'fixtures/typescript/package.json')) - expect(stubs.stdout.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`foo topic description + expect(stdoutStub.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`foo topic description USAGE $ oclif foo COMMAND @@ -71,7 +71,7 @@ COMMANDS it('should run spaced topic help v2', async () => { await run(['foo', 'bar', '--help'], resolve(__dirname, 'fixtures/typescript/package.json')) - expect(stubs.stdout.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`foo bar topic description + expect(stdoutStub.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`foo bar topic description USAGE $ oclif foo bar COMMAND diff --git a/yarn.lock b/yarn.lock index 63efa43dc..00e2162de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -786,12 +786,11 @@ wordwrap "^1.0.0" wrap-ansi "^7.0.0" -"@oclif/core@^3.0.0-beta.17": - version "3.0.0-beta.17" - resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.0.0-beta.17.tgz#a6f0d22703647743aba6c9e53f0560724aba3ccb" - integrity sha512-knoDpfAVYgbVeuoUpX/es8os1GeVp//gNczB3mgNPotENXMALOZKgIv7rBbKpHa1xmpGdEf0n31WrBq3HigKwQ== +"@oclif/core@^3.6.0": + version "3.6.0" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.6.0.tgz#b9582f3bf1ad933a6ac0335d0437be9ac10ce3b6" + integrity sha512-qjLXQEHUajQPeHQYRU9kRv5tBCW8O4L/OvILF/8lt08RLlp24E8yK6J7ROCZMwPxYsD3YC1/AQ76br2R+O1Cqw== dependencies: - "@types/cli-progress" "^3.11.0" ansi-escapes "^4.3.2" ansi-styles "^4.3.0" cardinal "^2.1.1" @@ -799,7 +798,7 @@ clean-stack "^3.0.1" cli-progress "^3.12.0" debug "^4.3.4" - ejs "^3.1.8" + ejs "^3.1.9" get-package-type "^0.1.0" globby "^11.1.0" hyperlinker "^1.0.0" @@ -849,12 +848,12 @@ resolved "https://registry.yarnpkg.com/@oclif/prettier-config/-/prettier-config-0.2.1.tgz#1def9f38134f9bfb229257f48a35f7d0d183dc78" integrity sha512-XB8kwQj8zynXjIIWRm+6gO/r8Qft2xKtwBMSmq1JRqtA6TpwpqECqiu8LosBCyg2JBXuUy2lU23/L98KIR7FrQ== -"@oclif/test@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@oclif/test/-/test-3.0.1.tgz#81d7645222211640afae7512d8243d5a9c52e2c1" - integrity sha512-1oJNdnwpp1x4WhUcstgwNgbijNOdz7l5LdWiTU0ZMwkyvxcQhZKCF5puFXndV+EkYds/s/0+dZOx0rhhDILA/w== +"@oclif/test@^3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@oclif/test/-/test-3.0.3.tgz#fe32dd96171933a323468b27951104a22673e981" + integrity sha512-hhQa732q85z71wur0Tzf9n9Z32Yiq8Hb4suNGeweYHtNQ5DmWgGqHJ57S+zs6ri0GF+xJmzRyr5qFq8KNs3Xqg== dependencies: - "@oclif/core" "^3.0.0-beta.17" + "@oclif/core" "^3.6.0" chai "^4.3.10" fancy-test "^3.0.1"