Skip to content

Commit

Permalink
Cleaning up CLI exit codes (#193)
Browse files Browse the repository at this point in the history
Close #73
  • Loading branch information
mkucharz committed Mar 17, 2018
1 parent 19aefbd commit 5f28999
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/commands/socket-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SocketCreate {
} catch (err) {
debug(err)
error(err.message)
process.exit(1)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/socket-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class SocketPublishCmd {
error(4)(err.message)
echo()
}
process.exit(1)
}
}
}
2 changes: 2 additions & 0 deletions packages/tests/e2e/cli/anonymous.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ describe('CLI Anonymous User', function () {
testNixt()
.run(`${cliLocation} list`)
.stdout(/You are not logged in!/)
.code(1)
.end(done)
})

it('can run cli deploy command', function (done) {
testNixt()
.run(`${cliLocation} list`)
.stdout(/You are not logged in!/)
.code(1)
.end(done)
})
})
10 changes: 9 additions & 1 deletion packages/tests/e2e/cli/config.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import {cliLocation, projectTestTemplate, configTestTemplate} from '../utils'

describe('[E2E] CLI Config', function () {
describe('CLI Config', function () {
let testInstance = uniqueInstance()

const moveTestSocket = (template) => {
Expand All @@ -34,38 +34,44 @@ describe('[E2E] CLI Config', function () {
})
.run(`${cliLocation} deploy hello-config`)
.stdout(/socket synced:/)
.code(0)
.end(done)
})

it('can set first config option', function (done) {
testNixt()
.run(`${cliLocation} config-set hello-config TEST1 test1_value`)
.code(0)
.end(done)
})

it('can set second config option', function (done) {
testNixt()
.run(`${cliLocation} config-set hello-config TEST2 test2_value`)
.code(0)
.end(done)
})

it('can show config of the socket', function (done) {
testNixt()
.run(`${cliLocation} config-show hello-config`)
.stdout(/value: test2_value/)
.code(0)
.end(done)
})

it('can change first config option of the socket', function (done) {
testNixt()
.run(`${cliLocation} config-set hello-config TEST1 test1_value_new`)
.code(0)
.end(done)
})

it('can see new config option of the socket', function (done) {
testNixt()
.run(`${cliLocation} config-show hello-config`)
.stdout(/value: test1_value_new/)
.code(0)
.end(done)
})

Expand All @@ -78,13 +84,15 @@ describe('[E2E] CLI Config', function () {
.respond('test2\n')
.on(/TEST3/)
.respond('test2\n')
.code(0)
.end(done)
})

it('can call hello-config socket endpoint', function (done) {
testNixt()
.run(`${cliLocation} call hello-config/hello`)
.stdout(/test1 test2/)
.code(0)
.end(done)
})
})
9 changes: 7 additions & 2 deletions packages/tests/e2e/cli/deploy.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

import {cliLocation, projectTestTemplate} from '../utils'

describe('[E2E] CLI Deploy', function () {
describe('CLI Deploy', function () {
let testInstance = uniqueInstance()

const testNixt = () => nixt()
Expand All @@ -28,13 +28,15 @@ describe('[E2E] CLI Deploy', function () {
testNixt()
.run(`${cliLocation} list`)
.stdout(/No Socket was found on server nor in config!/)
.code(0)
.end(done)
})

it('can\'t list non existing Socket', function (done) {
testNixt()
.run(`${cliLocation} list ${getRandomString()}`)
.stdout(/No Socket was found on server nor in config!/)
.code(1)
.end(done)
})

Expand All @@ -51,6 +53,7 @@ describe('[E2E] CLI Deploy', function () {
testNixt()
.run(`${cliLocation} deploy hello`)
.stdout(/socket synced:/)
.code(0)
.end(done)
})

Expand All @@ -61,8 +64,8 @@ describe('[E2E] CLI Deploy', function () {
.respond('TEST\n')
.on(/Type in value for "lastname" parameter/)
.respond('CLI\n')
.code(0)
.stdout(/Hello TEST CLI/)
.code(0)
.end(done)
})

Expand All @@ -82,6 +85,7 @@ describe('[E2E] CLI Deploy', function () {
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} deploy --create-instance ${testInstance}`)
.stdout(/project synced:/)
.code(0)
.end(done)
})

Expand All @@ -104,6 +108,7 @@ describe('[E2E] CLI Deploy', function () {
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} deploy --create-instance ${testInstance}`)
.stdout(/Instance already exist!/)
.code(1)
.end(done)
})
})
13 changes: 12 additions & 1 deletion packages/tests/e2e/cli/hosting.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

import {cliLocation, projectTestTemplate, hostingAssets} from '../utils'

describe('[E2E] CLI Hosting', function () {
describe('CLI Hosting', function () {
let testInstance = uniqueInstance()
const hostingName = 'tests'
const hostingName2 = 'tests2'
Expand Down Expand Up @@ -41,6 +41,7 @@ describe('[E2E] CLI Hosting', function () {
.on(/sync files now/)
.respond('\n')
.stdout(/sync files use: syncano-cli hosting sync/)
.code(0)
.end(done)
})

Expand All @@ -56,6 +57,7 @@ describe('[E2E] CLI Hosting', function () {
.on(/sync files now/)
.respond('\n')
.stdout(/sync files use: syncano-cli hosting sync/)
.code(0)
.end(done)
})

Expand All @@ -65,6 +67,7 @@ describe('[E2E] CLI Hosting', function () {
.on(/Choose socket for which you you want to list hostings/)
.respond('\n')
.stdout(/name: tests/)
.code(0)
.end(done)
})

Expand All @@ -74,20 +77,23 @@ describe('[E2E] CLI Hosting', function () {
.on(/Choose a socket which hosting files you want to see/)
.respond('\n')
.stdout(/You have 1 files/)
.code(0)
.end(done)
})

it('can sync local hosting', function (done) {
testNixt()
.run(`${cliLocation} hosting sync ${hostingName}`)
.stdout(/files synchronized/)
.code(0)
.end(done)
})

it('can sync local hosting again', function (done) {
testNixt()
.run(`${cliLocation} hosting sync ${hostingName}`)
.stdout(/files synchronized/)
.code(0)
.end(done)
})

Expand All @@ -100,6 +106,7 @@ describe('[E2E] CLI Hosting', function () {
.respond('Y\n')
.stdout(/CNAME: http:\/\/my.dom.ain/)
.stdout(/BrowserRouter: ✓/)
.code(0)
.end(done)
})

Expand All @@ -108,6 +115,7 @@ describe('[E2E] CLI Hosting', function () {
.run(`${cliLocation} hosting config ${hostingName} --browser-router false --remove-cname my.dom.ain`)
.stdout(/^((?!CNAME: http:\/\/my.dom.ain)[\s\S])*$/)
.stdout(/BrowserRouter: x/)
.code(0)
.end(done)
})

Expand All @@ -117,6 +125,7 @@ describe('[E2E] CLI Hosting', function () {
.on(/Are you sure you/)
.respond('Y\n')
.stdout(/has been successfully deleted!/)
.code(0)
.end(done)
})

Expand All @@ -126,13 +135,15 @@ describe('[E2E] CLI Hosting', function () {
.on(/Are you sure you/)
.respond('Y\n')
.stdout(/has been successfully deleted!/)
.code(0)
.end(done)
})

it('can see there is not hosting containers', function (done) {
testNixt()
.run(`${cliLocation} hosting list`)
.stdout(/You don't have any hostings/)
.code(0)
.end(done)
})
})
7 changes: 6 additions & 1 deletion packages/tests/e2e/cli/init.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { email, password, syncanoYmlPath } = returnTestGlobals()
const tempPass = Date.now()
const tempEmail = createTempEmail(process.env.E2E_CLI_TEMP_EMAIL, tempPass)

describe('[E2E] CLI User', function () {
describe('CLI User', function () {
let testInstance = uniqueInstance()

before(cleanUpAccount)
Expand Down Expand Up @@ -50,6 +50,7 @@ describe('[E2E] CLI User', function () {
.stdout(/Project has been created from/)
.match(syncanoYmlPath, /auth_key/)
.match(syncanoYmlPath, /instance/)
.code(0)
.end(done)
})

Expand All @@ -59,6 +60,7 @@ describe('[E2E] CLI User', function () {
.run(`${cliLocation} logout`)
.stdout(/You have been logged out/)
.unlink(syncanoYmlPath)
.code(0)
.end(done)
})
// This is end of tests dependency
Expand All @@ -79,6 +81,7 @@ describe('[E2E] CLI User', function () {
.match(syncanoYmlPath, /auth_key/)
.match(syncanoYmlPath, new RegExp(testInstance))
.unlink(syncanoYmlPath)
.code(0)
.end(done)
})

Expand All @@ -99,6 +102,7 @@ describe('[E2E] CLI User', function () {
.match(syncanoYmlPath, /auth_key/)
.match(syncanoYmlPath, /instance/)
.unlink(syncanoYmlPath)
.code(0)
.end(done)
})

Expand All @@ -117,6 +121,7 @@ describe('[E2E] CLI User', function () {
.match(syncanoYmlPath, /auth_key/)
.match(syncanoYmlPath, /instance/)
.unlink(syncanoYmlPath)
.code(0)
.end(done)
})
})
7 changes: 6 additions & 1 deletion packages/tests/e2e/cli/instance.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import {cliLocation} from '../utils'

describe('[E2E] CLI Instance', function () {
describe('CLI Instance', function () {
const testNixt = () => nixt()
.env('SYNCANO_AUTH_KEY', process.env.E2E_CLI_ACCOUNT_KEY)

Expand All @@ -20,6 +20,7 @@ describe('[E2E] CLI Instance', function () {
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} instance create ${testInstance}`)
.stdout(/Instance already exist!/)
.code(1)
.end(done)
})

Expand All @@ -30,13 +31,15 @@ describe('[E2E] CLI Instance', function () {
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} instance create ${testInstance}`)
.stdout(/has been created/)
.code(0)
.end(done)
})

it.skip('can list if there is no instances', function (done) {
testNixt()
.run(`${cliLocation} instance list`)
.stdout(/You don't have any instances!/)
.code(0)
.end(done)
})

Expand All @@ -57,6 +60,7 @@ describe('[E2E] CLI Instance', function () {
.stdout(/Instances:/)
.stdout(new RegExp(testInstance1))
.stdout(new RegExp(testInstance2))
.code(0)
.end(done)
})

Expand All @@ -69,6 +73,7 @@ describe('[E2E] CLI Instance', function () {
})
.run(`${cliLocation} instance delete ${testInstance}`)
.stdout(/Instance was deleted successfully!/)
.code(0)
.end(done)
})
})
Loading

0 comments on commit 5f28999

Please sign in to comment.