Skip to content

Commit

Permalink
fix(bin): add the missing shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
trylovetom committed May 7, 2020
1 parent e53a996 commit 6e0a21d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 17 additions & 13 deletions packages/bin/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ import path from 'path'
import { TonApp, TonListenSocket, close } from '@tonjs/ton'
import bin from './index'

let logLevel = process.env.LOG_LEVEL
let instance: { app: TonApp; token: TonListenSocket }
const logLevel = process.env.LOG_LEVEL
process.env.LOG_LEVEL = 'silent'

beforeAll(() => {
logLevel = process.env.LOG_LEVEL
process.env.LOG_LEVEL = 'silent'
})
let instance: { app: TonApp; token: TonListenSocket }
const { exit } = process

afterAll(() => {
if (logLevel) {
process.env.LOG_LEVEL = logLevel
} else {
delete process.env.LOG_LEVEL
}
process.exit = exit
})

afterEach(() => {
close(instance.token)
process.exit = jest.fn() as any
})

describe('e2e', () => {
Expand Down Expand Up @@ -111,12 +113,14 @@ describe('e2e', () => {
expect(resPing.data).toEqual({ result: 'pong' })
})

it('should use index.js as default entry', async () => {
try {
await bin({ host: '0.0.0.0', port: 4000, _: [] })
} catch (err) {
// eslint-disable-next-line jest/no-try-expect
expect(err.moduleName).toBe(path.resolve(process.cwd(), 'index.js'))
}
it(`should use index.js as default entry.
index.js is missing, will exit with 1`, async () => {
const { exit } = process
process.exit = jest.fn() as any

const error: any = await bin({ host: '0.0.0.0', port: 4000, _: [] })
expect(process.exit).toBeCalledWith(1)
expect(error.moduleName).toBe(path.resolve(process.cwd(), 'index.js'))
process.exit = exit
})
})
4 changes: 3 additions & 1 deletion packages/bin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import path from 'path'
import {
TonHandler,
Expand Down Expand Up @@ -84,7 +85,8 @@ export default async function main(
} catch (err) {
logger.info(`failed to listen on ${argv.host}:${argv.port}`)
logger.error(err)
throw err
process.exit(1)
return err
}
}

Expand Down

0 comments on commit 6e0a21d

Please sign in to comment.