Skip to content
Open
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
14 changes: 13 additions & 1 deletion lib/utils/key-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ function logObject (values, { chalk, json, predicate = defaultPredicate }) {
}

function logStageItem (item, { chalk }) {
const { id, packageName, version, tag, createdAt, actor, actorType, shasum, ...rest } = item
const {
id,
packageName,
version,
tag,
createdAt,
actor,
actorType,
shasum,
status,
...rest
} = item
logObject({
id,
'package name': packageName,
version,
status,
tag,
'date staged': createdAt,
'staged by': actorType ? `${actor} (${actorType})` : actor,
Expand Down
7 changes: 7 additions & 0 deletions test/lib/commands/stage/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const stageItems = [
actor: 'octocat',
actorType: 'user',
shasum: '4f7f5f1d5bcf2f72f6e4d6c4f3b2812d8a2f6c19',
status: 'validating',
},
{
id: 'f8e7a45b-7a5f-4f31-8e6d-9dd1c6ef38c0',
Expand All @@ -25,6 +26,7 @@ const stageItems = [
actor: 'npm-bot',
actorType: 'trusted automation',
shasum: '8eb3b4e9b6e3d0d2c86be1e6d4f43f4be62e80ad',
status: 'staged',
},
]

Expand All @@ -45,6 +47,9 @@ t.test('lists all staged packages', async t => {
t.match(out, 'package name: example-lib')
t.match(out, 'version: 1.2.3')
t.match(out, 'version: 0.4.0')
t.match(out, 'status: validating')
t.match(out, 'status: staged')
t.equal(out.match(/status:/g)?.length, 2, 'all server-provided statuses are shown')
})

t.test('lists with package filter', async t => {
Expand Down Expand Up @@ -80,6 +85,8 @@ t.test('lists with --json', async t => {
t.equal(out.length, 2)
t.equal(out[0].packageName, '@npmcli/example-package')
t.equal(out[0].id, '1de6f3db-2ed9-4d72-b3dd-8f0e2b474a2f', 'uuid id is not redacted')
t.equal(out[0].status, 'validating')
t.equal(out[1].status, 'staged')
})

t.test('shows message when no packages', async t => {
Expand Down
3 changes: 3 additions & 0 deletions test/lib/commands/stage/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const stageItem = {
actor: 'octocat',
actorType: 'user',
shasum: '4f7f5f1d5bcf2f72f6e4d6c4f3b2812d8a2f6c19',
status: 'awaiting_approval',
}

t.test('views a staged package', async t => {
Expand All @@ -31,6 +32,7 @@ t.test('views a staged package', async t => {
t.match(out, /id:/)
t.match(out, 'package name: @npmcli/example-package')
t.match(out, 'version: 1.2.3')
t.match(out, 'status: awaiting_approval')
})

t.test('views with --json', async t => {
Expand All @@ -47,6 +49,7 @@ t.test('views with --json', async t => {
const out = JSON.parse(joinedOutput())
t.ok(out.id)
t.equal(out.packageName, '@npmcli/example-package')
t.equal(out.status, 'awaiting_approval')
})

t.test('throws usageError without stage-id', async t => {
Expand Down
34 changes: 34 additions & 0 deletions test/lib/utils/key-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ t.test('logStageItem without actorType shows actor alone', async t => {
t.notMatch(out, /\(/)
})

t.test('logStageItem shows status returned by the server', async t => {
const { joinedOutput } = await loadMockNpm(t)
const chalk = { cyan: v => v, green: v => v }
const item = {
id: 'abc',
packageName: 'pkg',
version: '1.0.0',
tag: 'latest',
createdAt: '2026-01-01',
actor: 'user',
shasum: 'sha1',
}

logStageItem({ ...item, status: 'awaiting_approval' }, { chalk })
t.match(joinedOutput(), /status: awaiting_approval/)
})

t.test('logStageItem omits missing status', async t => {
const { joinedOutput } = await loadMockNpm(t)
const chalk = { cyan: v => v, green: v => v }
const item = {
id: 'abc',
packageName: 'pkg',
version: '1.0.0',
tag: 'latest',
createdAt: '2026-01-01',
actor: 'user',
shasum: 'sha1',
}

logStageItem(item, { chalk })
t.notMatch(joinedOutput(), /status:/)
})

t.test('logObject with all values skipped produces no output', async t => {
const { joinedOutput } = await loadMockNpm(t)
const chalk = { cyan: v => v, green: v => v }
Expand Down
Loading