From 27cd99de6c9160b90a5eaa92b0c6c0d456aafc89 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 8 Nov 2023 17:51:35 -0300 Subject: [PATCH] add test --- workspaces/libnpmexec/lib/run-script.js | 4 +-- workspaces/libnpmexec/test/index.js | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/workspaces/libnpmexec/lib/run-script.js b/workspaces/libnpmexec/lib/run-script.js index 57dacf4645d6b..f41af91dfe8bf 100644 --- a/workspaces/libnpmexec/lib/run-script.js +++ b/workspaces/libnpmexec/lib/run-script.js @@ -32,9 +32,7 @@ const run = async ({ }, } - if (stdio === 'inherit') { - npmlog.disableProgress() - } + npmlog.disableProgress() try { if (script === scriptShell) { diff --git a/workspaces/libnpmexec/test/index.js b/workspaces/libnpmexec/test/index.js index 008560efc7018..5bc8d7677eecd 100644 --- a/workspaces/libnpmexec/test/index.js +++ b/workspaces/libnpmexec/test/index.js @@ -14,3 +14,41 @@ t.test('no args', async t => { await exec() }) + +t.test('stdio value', t => { + t.test('stdio default value', t => { + const libexec = t.mock('../lib/index.js', { + '../lib/run-script.js': (opt) => { + t.equal(opt.stdio, 'inherit', 'should use expected stdio value') + }, + npmlog: { + disableProgress () { + t.ok('should disable progress') + }, + enableProgress () { + t.ok('should enable progress') + }, + }, + }) + libexec({ args: [], runPath: t.testDirName }) + }) + + t.test('stdio custom value', t => { + const libexec = t.mock('../lib/index.js', { + '../lib/run-script.js': (opt) => { + t.equal(opt.stdio, 'pipe', 'should use expected stdio value') + }, + npmlog: { + disableProgress () { + t.ok('should disable progress') + }, + enableProgress () { + t.fail('should not enable progress') + }, + }, + }) + libexec({ args: [], stdio: 'pipe', runPath: t.testDirName }) + }) + + t.end() +})