Last active
May 24, 2023 16:35
-
-
Save tluyben/2a1178b771798158d11c933198ebd27d to your computer and use it in GitHub Desktop.
Expect for TypeScript
This file contains hidden or 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
import { spawn as expectSpawn } from 'node-pty'; | |
export async function expect(cmd: string, expectations: { expected: string, retort: string }[], dir?: string) { | |
let cmdSplit = cmd.split(' ') | |
const p = expectSpawn(cmdSplit.shift()!, cmdSplit, { cwd: dir }) | |
p.onData((data) => { | |
console.log(data) | |
const expected = expectations.shift() | |
if (!expected) { | |
throw new Error('Unexpected output: ' + data) | |
} | |
if (data.includes(expected.expected)) { | |
p.write(expected.retort + '\n') | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added this to be able to use the Prisma CLI tools non-interactive.
Like:
expect('npx prisma migrate dev --name "my migration"', [{ expected: 'apply this migration?', retort: 'y' }], publishDir)