jamesshore / test-console

A simple and pragmatic library for testing Node.js console output.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to mock isTTY

spraot opened this issue · comments

commented

For cases when expected output is different for different values of isTTY, we should be able to mock both cases. I can do the following:

        const isTTY = process.stdout.isTTY;
        process.stdout.isTTY = false;
        const output = stdout.inspectSync(
            () => doStuff()
        );
        process.stdout.isTTY = isTTY;

but I think this should be integrated in inspect and inspectSync as an option.

(thanks for the library, by the way)

commented

I can make a pull request sometime if you will consider merging it and making a new release

I'd be okay with a pull request.

Before you do that, can you describe what the API would look like? I understand the situation but I'm not sure what your solution is.

commented

I was thinking like this:

const output = stdout.inspectSync(() => doStuff(), {isTTY: false});

where the possible values for isTTY are true, false, or 'inherit', with a default of 'inherit' to avoid breaking anything downstream.

Make sense?

How about this instead?

const output = stdout.inspectSync({ isTTY: false }, () => doStuff());

where the possible values are true, false, and undefined.

Released in v1.1.