-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): use custom REPL in console command (#38)
Co-authored-by: Brandon Bayer <b@bayer.ws>
- Loading branch information
Showing
2 changed files
with
20 additions
and
8 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
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) | ||
} | ||
} |
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,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.`) | ||
}) | ||
}) |