-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: try out run integration tests without oclif/test
- Loading branch information
Showing
5 changed files
with
122 additions
and
36 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {getConfig} from './testInstances' | ||
import {Command} from '@heroku-cli/command-v9' | ||
import {stdout, stderr} from 'stdout-stderr' | ||
|
||
type CmdConstructorParams = ConstructorParameters<typeof Command> | ||
export type GenericCmd = new (...args: CmdConstructorParams) => Command | ||
|
||
const stopMock = () => { | ||
stdout.stop() | ||
stderr.stop() | ||
} | ||
|
||
const runCommand = async (Cmd: GenericCmd, args: string[] = [], printStd = false) => { | ||
const conf = await getConfig() | ||
const instance = new Cmd(args, conf) | ||
if (printStd) { | ||
stdout.print = true | ||
stderr.print = true | ||
} | ||
|
||
stdout.start() | ||
stderr.start() | ||
|
||
try { | ||
instance | ||
.run() | ||
.then(args => { | ||
stopMock() | ||
return args | ||
}) | ||
} catch (error: any) { | ||
stopMock() | ||
throw error | ||
} | ||
} | ||
|
||
export default runCommand |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {APIClient} from '@heroku-cli/command-v9' | ||
import {Config} from '@oclif/core-v1' | ||
|
||
export const getConfig = async () => { | ||
const pjsonPath = require.resolve('../../package.json') | ||
const conf = new Config({root: pjsonPath}) | ||
await conf.load() | ||
return conf | ||
} | ||
|
||
export const getHerokuAPI = async () => { | ||
const conf = await getConfig() | ||
return new APIClient(conf) | ||
} |
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,44 +1,67 @@ | ||
import {expect, test} from '@oclif/test' | ||
import {expect} from 'chai' | ||
import {stdout} from 'stdout-stderr' | ||
import Cmd from '../../src/commands/run/index' | ||
import runCommand from '../helpers/runCommand' | ||
|
||
const testFactory = () => { | ||
return test | ||
.stdout() | ||
.do(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
process.stdout.isTTY = false | ||
}) | ||
} | ||
// const testFactory = () => { | ||
// return test | ||
// .stdout() | ||
// .do(() => { | ||
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// // @ts-ignore | ||
// process.stdout.isTTY = false | ||
// }) | ||
// } | ||
|
||
describe('run', () => { | ||
testFactory() | ||
.command(['run', '--app=heroku-cli-ci-smoke-test-app', 'echo 1 2 3']) | ||
.it('runs a command', async ctx => { | ||
expect(ctx.stdout).to.include('1 2 3') | ||
}) | ||
it('runs a command', async () => { | ||
await runCommand(Cmd, ['--app=heroku-cli-ci-smoke-test-app', 'echo 1 2 3']) | ||
expect(stdout).to.include('1 2 3') | ||
}) | ||
// testFactory() | ||
// .command(['run', '--app=heroku-cli-ci-smoke-test-app', 'echo 1 2 3']) | ||
// .it('runs a command', async ctx => { | ||
// expect(ctx.stdout).to.include('1 2 3') | ||
// }) | ||
|
||
testFactory() | ||
.command(['run', '--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo": "bar"} " ']) | ||
.it('runs a command with spaces', ctx => { | ||
expect(ctx.stdout).to.contain('{foo: bar}') | ||
}) | ||
it('runs a command with spaces', async () => { | ||
await runCommand(Cmd, ['--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo": "bar"} " ']) | ||
expect(stdout).to.contain('{foo:bar}') | ||
}) | ||
// testFactory() | ||
// .command(['run', '--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo": "bar"} " ']) | ||
// .it('runs a command with spaces', ctx => { | ||
// expect(ctx.stdout).to.contain('{foo: bar}') | ||
// }) | ||
|
||
testFactory() | ||
.command(['run', '--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo":"bar"}"']) | ||
.it('runs a command with quotes', ctx => { | ||
expect(ctx.stdout).to.contain('{foo:bar}') | ||
}) | ||
it('runs a command with quotes', async () => { | ||
await runCommand(Cmd, ['--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo":"bar"}"']) | ||
expect(stdout).to.contain('{foo:bar}') | ||
}) | ||
// testFactory() | ||
// .command(['run', '--app=heroku-cli-ci-smoke-test-app', 'ruby -e "puts ARGV[0]" "{"foo":"bar"}"']) | ||
// .it('runs a command with quotes', ctx => { | ||
// expect(ctx.stdout).to.contain('{foo:bar}') | ||
// }) | ||
|
||
testFactory() | ||
.command(['run', '--app=heroku-cli-ci-smoke-test-app', '-e FOO=bar', 'env']) | ||
.it('runs a command with env vars', ctx => { | ||
expect(ctx.stdout).to.include('FOO=bar') | ||
}) | ||
it('runs a command with env vars', async () => { | ||
await runCommand(Cmd, ['--app=heroku-cli-ci-smoke-test-app', '-e FOO=bar', 'env']) | ||
expect(stdout).to.include('FOO=bar') | ||
}) | ||
// testFactory() | ||
// .command(['run', '--app=heroku-cli-ci-smoke-test-app', '-e FOO=bar', 'env']) | ||
// .it('runs a command with env vars', ctx => { | ||
// expect(ctx.stdout).to.include('FOO=bar') | ||
// }) | ||
|
||
testFactory() | ||
.command(['run', '--app=heroku-cli-ci-smoke-test-app', '--exit-code', 'invalid-command']) | ||
.exit(127) | ||
.it('gets 127 status for invalid command', ctx => { | ||
expect(ctx.stdout).to.include('invalid-command: command not found') | ||
}) | ||
it('prints an error for an invalid command', async () => { | ||
await runCommand(Cmd, ['--app=heroku-cli-ci-smoke-test-app', '--exit-code', 'invalid-command']) | ||
expect(stdout).to.include('invalid-command: command not found') | ||
}) | ||
// testFactory() | ||
// .command(['run', '--app=heroku-cli-ci-smoke-test-app', '--exit-code', 'invalid-command']) | ||
// .exit(127) | ||
// .it('gets 127 status for invalid command', ctx => { | ||
// expect(ctx.stdout).to.include('invalid-command: command not found') | ||
// }) | ||
}) |
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