Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Clear progress bar which overlays confirm prompt #8

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ const exec = async (opts) => {
const prompt = `Need to install the following packages:\n${
addList
}Ok to proceed? `
if (typeof log.clearProgress === 'function')
log.clearProgress()
const confirm = await read({ prompt, default: 'y' })
if (confirm.trim().toLowerCase().charAt(0) !== 'y')
throw new Error('canceled')
Expand Down
161 changes: 117 additions & 44 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,59 @@ t.test('prompt, accepts', async t => {
const runPath = path
const cache = resolve(testdir, 'cache')
const npxCache = resolve(testdir, 'npxCache')
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
read (opts, cb) {
cb(null, 'y')
},
'../lib/no-tty.js': () => false,
})
t.test('with clearProgress function', async t => {
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
'proc-log': {
clearProgress () {
t.ok(true, 'should call clearProgress function')
}
},
read (opts, cb) {
cb(null, 'y')
},
'../lib/no-tty.js': () => false,
})

await libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
await libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
})

const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')
t.ok(fs.statSync(installedDir).isFile(), 'installed required packages')
})

const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')
t.ok(fs.statSync(installedDir).isFile(), 'installed required packages')
t.test('without clearProgress function', async t => {
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
'proc-log': {},
read (opts, cb) {
cb(null, 'y')
},
'../lib/no-tty.js': () => false,
})

await libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
})

const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')
t.ok(fs.statSync(installedDir).isFile(), 'installed required packages')
})
})

t.test('prompt, refuses', async t => {
Expand All @@ -366,36 +398,77 @@ t.test('prompt, refuses', async t => {
const runPath = path
const cache = resolve(testdir, 'cache')
const npxCache = resolve(testdir, 'npxCache')
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
read (opts, cb) {
cb(null, 'n')
},
'../lib/no-tty.js': () => false,
t.test('with clearProgress function', async t => {
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
'proc-log': {
clearProgress () {
t.ok(true, 'should call clearProgress function')
}
},
read (opts, cb) {
cb(null, 'n')
},
'../lib/no-tty.js': () => false,
})

await t.rejects(
libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
}),
/canceled/,
'should throw with canceled error'
)

const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')

t.throws(
() => fs.statSync(installedDir),
{ code: 'ENOENT' },
'should not have installed required packages'
)
})

await t.rejects(
libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
}),
/canceled/,
'should throw with canceled error'
)
t.test('without clearProgress function', async t => {
const libexec = t.mock('../lib/index.js', {
'@npmcli/ci-detect': () => false,
'proc-log': {},
read (opts, cb) {
cb(null, 'n')
},
'../lib/no-tty.js': () => false,
})

const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')
await t.rejects(
libexec({
...baseOpts,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
yes: undefined,
}),
/canceled/,
'should throw with canceled error'
)

t.throws(
() => fs.statSync(installedDir),
{ code: 'ENOENT' },
'should not have installed required packages'
)
const installedDir = resolve(npxCache,
'0e8e15840a234288/node_modules/@ruyadorno/create-index/package.json')

t.throws(
() => fs.statSync(installedDir),
{ code: 'ENOENT' },
'should not have installed required packages'
)
})
})

t.test('prompt, -n', async t => {
Expand Down