-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fa48c2
commit 5e9bbcd
Showing
9 changed files
with
321 additions
and
109 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
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,47 +1,38 @@ | ||
import {expect} from 'chai' | ||
import {join} from 'node:path' | ||
|
||
import {expect, test} from '../src' | ||
import {runCommand} from '../src' | ||
|
||
describe('command', () => { | ||
// eslint-disable-next-line unicorn/prefer-module | ||
const root = join(__dirname, 'fixtures/multi') | ||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.command(['foo:bar']) | ||
.do((output) => { | ||
expect(output.stdout).to.equal('hello world!\n') | ||
const {name} = output.returned as {name: string} | ||
expect(name).to.equal('world') | ||
}) | ||
.it() | ||
|
||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.command(['foo:bar', '--name=foo']) | ||
.do((output) => expect(output.stdout).to.equal('hello foo!\n')) | ||
.it() | ||
it('should run a command', async () => { | ||
const {result, stdout} = await runCommand<{name: string}>(['foo:bar'], {root}) | ||
expect(stdout).to.equal('hello world!\n') | ||
expect(result?.name).to.equal('world') | ||
}) | ||
|
||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.command(['foo bar', '--name=foo']) | ||
.do((output) => expect(output.stdout).to.equal('hello foo!\n')) | ||
.it() | ||
it('should run a command with a flag', async () => { | ||
const {result, stdout} = await runCommand<{name: string}>(['foo:bar', '--name=foo'], {root}) | ||
expect(stdout).to.equal('hello foo!\n') | ||
expect(result?.name).to.equal('foo') | ||
}) | ||
|
||
it('should run a command using spaces', async () => { | ||
const {result, stdout} = await runCommand<{name: string}>(['foo bar', '--name=foo'], {root}) | ||
expect(stdout).to.equal('hello foo!\n') | ||
expect(result?.name).to.equal('foo') | ||
}) | ||
}) | ||
|
||
describe('single command cli', () => { | ||
// eslint-disable-next-line unicorn/prefer-module | ||
const root = join(__dirname, 'fixtures/single') | ||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.command(['.']) | ||
.do((output) => { | ||
expect(output.stdout).to.equal('hello world!\n') | ||
const {name} = output.returned as {name: string} | ||
expect(name).to.equal('world') | ||
}) | ||
.it() | ||
|
||
it('should run a single command cli', async () => { | ||
const {result, stdout} = await runCommand<{name: string}>(['.'], {root}) | ||
expect(stdout).to.equal('hello world!\n') | ||
expect(result?.name).to.equal('world') | ||
}) | ||
}) |
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,16 +1,16 @@ | ||
import {expect} from 'chai' | ||
import {join} from 'node:path' | ||
|
||
import {expect, test} from '../src' | ||
import {runCommand} from '../src' | ||
|
||
// eslint-disable-next-line unicorn/prefer-module | ||
const root = join(__dirname, 'fixtures/multi') | ||
|
||
describe('exit', () => { | ||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.command(['exit', '--code=101']) | ||
.exit(101) | ||
.do(output => expect(output.stdout).to.equal('exiting with code 101\n')) | ||
.it() | ||
it('should handle expected exit codes', async () => { | ||
const {error, stdout} = await runCommand(['exit', '--code=101'], {root}) | ||
expect(stdout).to.equal('exiting with code 101\n') | ||
expect(error?.message).to.equal('EEXIT: 101') | ||
expect(error?.oclif?.exit).to.equal(101) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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,15 +1,14 @@ | ||
import {expect} from 'chai' | ||
import {join} from 'node:path' | ||
|
||
import {expect, test} from '../src' | ||
import {runHook} from '../src' | ||
|
||
// eslint-disable-next-line unicorn/prefer-module | ||
const root = join(__dirname, 'fixtures/multi') | ||
|
||
describe('hooks', () => { | ||
test | ||
.loadConfig({root}) | ||
.stdout() | ||
.hook('foo', {argv: ['arg']}, {root}) | ||
.do(output => expect(output.stdout).to.equal('foo hook args: arg\n')) | ||
.it() | ||
it('should run a hook', async () => { | ||
const {stdout} = await runHook('foo', {argv: ['arg']}, {root}) | ||
expect(stdout).to.equal('foo hook args: arg\n') | ||
}) | ||
}) |
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,48 +1,50 @@ | ||
import {expect, test} from '../src' | ||
import {Command, Flags} from '@oclif/core' | ||
import {expect} from 'chai' | ||
|
||
describe('stdout', () => { | ||
test | ||
.stdout() | ||
.end('logs', output => { | ||
console.log('foo') | ||
expect(output.stdout).to.equal('foo\n') | ||
}) | ||
import {captureOutput} from '../src' | ||
|
||
test | ||
.stdout() | ||
.end('logs twice', output => { | ||
console.log('foo') | ||
expect(output.stdout).to.equal('foo\n') | ||
console.log('bar') | ||
expect(output.stdout).to.equal('foo\nbar\n') | ||
}) | ||
}) | ||
class MyCommand extends Command { | ||
static flags = { | ||
channel: Flags.option({ | ||
char: 'c', | ||
multiple: true, | ||
options: ['stdout', 'stderr'] as const, | ||
required: true, | ||
})(), | ||
} | ||
|
||
describe('stdout + stderr', () => { | ||
test | ||
.stdout() | ||
.stderr() | ||
.end('logs and errors', output => { | ||
console.log('foo') | ||
console.error('bar') | ||
expect(output.stdout).to.equal('foo\n') | ||
expect(output.stderr).to.equal('bar\n') | ||
}) | ||
}) | ||
async run() { | ||
const {flags} = await this.parse(MyCommand) | ||
if (flags.channel.includes('stdout')) { | ||
this.log('hello world!') | ||
} | ||
|
||
// eslint-disable-next-line unicorn/no-static-only-class | ||
class MockOs { | ||
static platform() { | ||
return 'not-a-platform' | ||
if (flags.channel.includes('stderr')) { | ||
this.logToStderr('hello world!') | ||
} | ||
} | ||
} | ||
|
||
for (const os of ['darwin', 'win32', 'linux']) { | ||
describe(os, () => { | ||
test | ||
.stub(MockOs, 'platform', stub => stub.returns(os)) | ||
.end('sets os', () => { | ||
expect(MockOs.platform()).to.equal(os) | ||
describe('captureOutput', () => { | ||
it('should capture stdout', async () => { | ||
const {stdout} = await captureOutput(async () => { | ||
await MyCommand.run(['-c=stdout']) | ||
}) | ||
expect(stdout).to.equal('hello world!\n') | ||
}) | ||
} | ||
|
||
it('should capture stderr', async () => { | ||
const {stderr} = await captureOutput(async () => { | ||
await MyCommand.run(['-c=stderr']) | ||
}) | ||
expect(stderr).to.equal('hello world!\n') | ||
}) | ||
|
||
it('should capture both', async () => { | ||
const {stderr, stdout} = await captureOutput(async () => { | ||
await MyCommand.run(['-c=stdout', '-c=stderr']) | ||
}) | ||
expect(stdout).to.equal('hello world!\n') | ||
expect(stderr).to.equal('hello world!\n') | ||
}) | ||
}) |
Oops, something went wrong.