From 39a318b7d34b7f3001fccddba2a71ffedbc39667 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Tue, 27 Dec 2022 22:58:36 +0100 Subject: [PATCH] Fix specs for #966 --- test/npm.js | 17 ++++++++++++++--- test/tasks.js | 7 +++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/test/npm.js b/test/npm.js index 94606507..8bd02384 100644 --- a/test/npm.js +++ b/test/npm.js @@ -182,10 +182,21 @@ test('should throw if user is not authenticated', async t => { exec.restore(); }); -test('should throw if user is not a collaborator', async t => { +test('should throw if user is not a collaborator (v9)', async t => { const npmClient = factory(npm); const exec = sinon.stub(npmClient.shell, 'exec').resolves(); exec.withArgs('npm whoami').resolves('ada'); + exec.withArgs('npm --version').resolves('9.2.0'); + exec.withArgs('npm access list collaborators --json release-it').resolves(JSON.stringify({ john: ['write'] })); + await t.throwsAsync(runTasks(npmClient), { message: /^User ada is not a collaborator for release-it/ }); + exec.restore(); +}); + +test('should throw if user is not a collaborator (v8)', async t => { + const npmClient = factory(npm); + const exec = sinon.stub(npmClient.shell, 'exec').resolves(); + exec.withArgs('npm whoami').resolves('ada'); + exec.withArgs('npm --version').resolves('8.2.0'); exec.withArgs('npm access ls-collaborators release-it').resolves(JSON.stringify({ john: ['write'] })); await t.throwsAsync(runTasks(npmClient), { message: /^User ada is not a collaborator for release-it/ }); exec.restore(); @@ -307,7 +318,7 @@ test('should publish to a different/scoped registry', async t => { 'npm ping --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/', 'npm whoami --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/', 'npm show @my-scope/my-pkg@latest version --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/', - 'npm access ls-collaborators @my-scope/my-pkg --registry https://gitlab.com/api/v4/projects/my-scope%2Fmy-pkg/packages/npm/', + 'npm --version', 'npm version 1.0.1 --no-git-tag-version', 'npm publish . --tag latest' ]); @@ -341,7 +352,7 @@ test('should not publish when `npm version` fails', async t => { 'npm ping', 'npm whoami', 'npm show @my-scope/my-pkg@latest version', - 'npm access ls-collaborators @my-scope/my-pkg', + 'npm --version', 'npm version 1.0.1 --no-git-tag-version' ]); diff --git a/test/tasks.js b/test/tasks.js index 51701efd..9d4328ff 100644 --- a/test/tasks.js +++ b/test/tasks.js @@ -128,7 +128,7 @@ test.serial('should use pkg.version (in sub dir) w/o tagging repo', async t => { const { stdout } = sh.exec('git describe --tags --match=* --abbrev=0'); t.is(stdout.trim(), '1.0.0'); const npmArgs = getArgs(exec.args, 'npm'); - t.is(npmArgs[4], 'npm version 1.3.0 --no-git-tag-version'); + t.is(npmArgs[5], 'npm version 1.3.0 --no-git-tag-version'); exec.restore(); }); @@ -174,6 +174,7 @@ test.serial('should release all the things (basic)', async t => { 'npm ping', 'npm whoami', `npm show ${pkgName}@latest version`, + 'npm --version', `npm access ls-collaborators ${pkgName}`, 'npm version 1.0.1 --no-git-tag-version', 'npm publish . --tag latest' @@ -307,6 +308,7 @@ test.serial('should release all the things (pre-release, github, gitlab)', async 'npm ping', 'npm whoami', `npm show ${pkgName}@latest version`, + 'npm --version', `npm access ls-collaborators ${pkgName}`, 'npm version 1.1.0-alpha.0 --no-git-tag-version', 'npm publish . --tag alpha' @@ -346,6 +348,7 @@ test.serial('should publish pre-release without pre-id with different npm.tag', 'npm ping', 'npm whoami', `npm show ${pkgName}@latest version`, + 'npm --version', `npm access ls-collaborators ${pkgName}`, 'npm version 2.0.0-0 --no-git-tag-version', 'npm publish . --tag next' @@ -393,7 +396,7 @@ test.serial('should initially publish non-private scoped npm package privately', await runTasks({}, container); const npmArgs = getArgs(container.shell.exec.args, 'npm'); - t.is(npmArgs[5], 'npm publish . --tag latest'); + t.is(npmArgs[6], 'npm publish . --tag latest'); exec.restore(); });