Skip to content

Commit

Permalink
Fix interactive flag so that it forces REPL even when stdin is not a …
Browse files Browse the repository at this point in the history
…tty (#1019)

* Fix interactive flag so that it forces REPL even when stdin is not a tty

* Add test
  • Loading branch information
cspotcode authored Apr 26, 2020
1 parent 47a560b commit 9fee232
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ export function main (argv: string[]) {
Module.runMain()
} else {
// Piping of execution _only_ occurs when no other script is specified.
if (process.stdin.isTTY) {
// --interactive flag forces REPL
if (interactive || process.stdin.isTTY) {
startRepl(service, state, code)
} else {
let buffer = code || ''
Expand Down
15 changes: 15 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ describe('ts-node', function () {
cp.stdin!.end('true')
})

it('should run REPL when --interactive passed and stdin is not a TTY', function (done) {
const cp = exec(`${cmd} --interactive`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal(
'> 123\n' +
'undefined\n' +
'> '
)
return done()
})

cp.stdin!.end('console.log("123")\n')

})

it('should support require flags', function (done) {
exec(`${cmd} -r ./tests/hello-world -pe "console.log('success')"`, function (err, stdout) {
expect(err).to.equal(null)
Expand Down

0 comments on commit 9fee232

Please sign in to comment.