diff --git a/src/cli/main.ts b/src/cli/main.ts index 6c88170..4520d11 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -52,21 +52,20 @@ export function parse (args: Iterable): Flags { export async function main ({ args = argv.slice(2), - input = stdin, + lines = createInterface(stdin), print = console.log, quit = exit, }: { args?: Iterable, - input?: NodeJS.ReadableStream, + lines?: AsyncIterable, print?: Fn, quit?: Fn, } = {}): Promise { const flags = parse(args); - const lines = createInterface(input); let code = 0; diff --git a/tests/cli/main.test.ts b/tests/cli/main.test.ts index 3920d0d..2676aec 100644 --- a/tests/cli/main.test.ts +++ b/tests/cli/main.test.ts @@ -1,7 +1,7 @@ import { describe, it } from '@std/testing/bdd'; import * as mock from '@std/testing/mock'; -import { Readable } from 'node:stream'; +import { make_lines } from '../utils.ts'; import { @@ -17,7 +17,7 @@ describe('main', function () { it('collect lodash and nolyfill with extra ignore', async function () { - const input = Readable.from(` + const lines = make_lines(` "version": "1.2.3", "lockfileVersion": 2, "node_modules/@babel/core/node_modules/convert-source-map": { @@ -28,7 +28,7 @@ describe('main', function () { "node_modules/lodash.merge": { "node_modules/buffer": { "version": "6.0.3", - }, + } `); const args = [ @@ -42,17 +42,19 @@ describe('main', function () { const quit = mock.spy(() => {}); - await main({ args, input, print, quit }); + await main({ args, lines, print, quit }); Array.of( + 'lodash.memoize', 'function-bind', 'buffer', + ).forEach(function (pkg, i) { + mock.assertSpyCallArg(print, i, 0, pkg); - }); - mock.assertSpyCalls(print, 3); + }); mock.assertSpyCallArg(quit, 0, 0, 1); mock.assertSpyCalls(quit, 1); diff --git a/tests/utils.ts b/tests/utils.ts index 593305b..291aad2 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -4,6 +4,16 @@ import { assertStrictEquals } from '@std/assert'; +export function make_lines (str: string): AsyncIterable { + + return ReadableStream.from(str.split('\n')); + +} + + + + + export function assert__true ( value: unknown,