Skip to content

Commit

Permalink
main to accept line stream
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton committed Jul 7, 2024
1 parent 1e0dc2a commit 47f57ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,20 @@ export function parse (args: Iterable<string>): Flags {
export async function main ({

args = argv.slice(2),
input = stdin,
lines = createInterface(stdin),
print = console.log,
quit = exit,

}: {

args?: Iterable<string>,
input?: NodeJS.ReadableStream,
lines?: AsyncIterable<string>,
print?: Fn<unknown, void>,
quit?: Fn<number, void>,

} = {}): Promise<void> {

const flags = parse(args);
const lines = createInterface(input);

let code = 0;

Expand Down
8 changes: 4 additions & 4 deletions tests/cli/main.test.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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": {
Expand All @@ -28,7 +28,7 @@ describe('main', function () {
"node_modules/lodash.merge": {
"node_modules/buffer": {
"version": "6.0.3",
},
}
`);

const args = [
Expand All @@ -42,7 +42,7 @@ describe('main', function () {

const quit = mock.spy(() => {});

await main({ args, input, print, quit });
await main({ args, lines, print, quit });

Array.of(
'lodash.memoize',
Expand Down

0 comments on commit 47f57ae

Please sign in to comment.