Skip to content

Commit

Permalink
Merge pull request #564 from oclif/mdonnalley/stdin-example
Browse files Browse the repository at this point in the history
chore: add stdin example to migration guide
  • Loading branch information
mdonnalley committed Jun 11, 2024
2 parents 88298d4 + 1d84ad1 commit 3d1c1c9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,44 @@ describe('env tests', () => {

`.stdin()` allowed you mock stdin. There is no direct replacement for this in version 4. You can use [mock-stdin](https://www.npmjs.com/package/mock-stdin) directly if you need this functionality.

**Before**

```javascript
describe('stdin test', () => {
fancy
.stdin('whoa there!\n')
.stdout()
.it('mocks', () => {
process.stdin.setEncoding('utf8')
process.stdin.once('data', (data) => {
// data === 'whoa there!\n'
})
})
})
```

**After**

```typescript
import {captureOutput} from '@oclif/test'
import {expect} from 'chai'
import {stdin as fstdin} from 'mock-stdin'

import {MyCommand} from '../../src/commands/my/command.js'

const stdin = fstdin()

describe('stdin test', () => {
it('mocks', async () => {
const {result} = await captureOutput(async () => {
setTimeout(() => stdin.send('whoa there!\n'), 10)
return MyCommand.run()
})
expect(result).to.equal('whoa there!')
})
})
```

## `.retries()`

`.retries()` allowed you to retry the test. There is no direct replacement for this but most testing frameworks have functionality for this builtin.
Expand Down

0 comments on commit 3d1c1c9

Please sign in to comment.