Skip to content

Commit

Permalink
feat(cli): use custom REPL in console command (#38)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Bayer <b@bayer.ws>
  • Loading branch information
flybayer authored Mar 5, 2020
1 parent 949e7eb commit d26be24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 12 additions & 4 deletions packages/cli/src/commands/console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {Command} from '@oclif/command'
import {spawn} from 'child_process'
import { Command } from '@oclif/command'
import { start } from 'repl'

export default class Console extends Command {
static description = 'Run project REPL'
static aliases = ['c']

async run() {
spawn('node', {stdio: 'inherit'})
static replOptions = {
prompt: '⚡️>',
useColors: true
}

async run () {
this.log(`Welcome to Blitz.js v0.0.1
Type ".help" for more information.`)

start(Console.replOptions)
}
}
12 changes: 8 additions & 4 deletions packages/cli/test/commands/console.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import childProcess from 'child_process'
import * as repl from 'repl'
import ConsoleCmd from '../../src/commands/console'

jest.mock('child_process')
jest.mock('repl')

describe('Console command', () => {
beforeEach(() => {
jest.resetAllMocks()
})

it('runs node', async () => {
it('runs REPL', async () => {
jest.spyOn(ConsoleCmd.prototype, 'log')

await ConsoleCmd.prototype.run()

expect(childProcess.spawn).toBeCalledWith('node', {stdio: 'inherit'})
expect(repl.start).toBeCalledWith(ConsoleCmd.replOptions)
expect(ConsoleCmd.prototype.log).toHaveBeenCalledWith(`Welcome to Blitz.js v0.0.1
Type ".help" for more information.`)
})
})

0 comments on commit d26be24

Please sign in to comment.