test.serial('should fail when version is lower as latest version', async t => { await t.throwsAsync(run(testedModule('0.1.0', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'New version `0.1.0` should be higher than current version `1.0.0`'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Validate version' && task.hasFailed())); });
test.serial('should fail when git tag already exists', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: 'vvb' } ]); await t.throwsAsync(run(testedModule('2.0.0', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'Git tag `v2.0.0` already exists.'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check git tag existence' && task.hasFailed())); });
test.serial('.error()', async t => { const promise = hookStd.stdout(output => { promise.unhook(); t.is(JSON.parse(output).items[0].title, 'Error: foo'); }); alfyInstance.error(new Error('foo')); await promise; });
test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => { const subprocess = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT}); subprocess.stdout.resume(); subprocess.stderr.resume(); const {timedOut} = await t.throwsAsync(subprocess); t.true(timedOut); });
test.serial('linkifyCommit returns raw commit hash if terminalLink is not supported', t => { mockTerminalLinkUnsupported(); t.is(linkifyCommit(MOCK_REPO_URL, MOCK_COMMIT_HASH), MOCK_COMMIT_HASH); });
test.serial('checks should pass', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: '' } ]); await t.notThrowsAsync(run(testedModule('2.0.0', {name: 'test', version: '1.0.0'}, {yarn: false}))); });
test.serial('linkifyIssues returns raw message if terminalLink is not supported', t => { mockTerminalLinkUnsupported(); const msg = 'Commit message - fixes #6'; t.is(linkifyIssues(MOCK_REPO_URL, msg), msg); });
test.serial('private package: should skip task pinging npm registry', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', exitCode: 0, stdout: '' } ]); await run(testedModule('2.0.0', {name: 'test', version: '1.0.0', private: true}, {yarn: false})); t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && task.isSkipped())); });
test.serial('should fail when release branch is not specified, current branch is not main/master and publishing from any branch not permitted', async t => { execaStub.createStub([ { command: 'git symbolic-ref --short HEAD', exitCode: 0, stdout: 'feature' } ]); await t.throwsAsync(run(testedModule({})), {message: 'Not on `main`/`master` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check current branch' && task.hasFailed())); });
test.serial('external registry: should skip task pinging npm registry', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', exitCode: 0, stdout: '' } ]); await run(testedModule('2.0.0', {name: 'test', version: '1.0.0', publishConfig: {registry: 'http://my.io'}}, {yarn: false})); t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && task.isSkipped())); });
test.serial('should fail when git remote does not exists', async t => { execaStub.createStub([ { command: 'git ls-remote origin HEAD', exitCode: 1, exitCodeName: 'EPERM', stderr: 'not found' } ]); await t.throwsAsync(run(testedModule('2.0.0', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'not found'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check git remote' && task.hasFailed())); });
test.serial('public-package published on npm registry: should fail when npm registry not pingable', async t => { execaStub.createStub([{ command: 'npm ping', exitCode: 1, exitCodeName: 'EPERM', stdout: '', stderr: 'failed' }]); await t.throwsAsync(run(testedModule('1.0.0', {name: 'test'}, {})), {message: 'Connection to npm registry failed'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && task.hasFailed())); });
test.serial('should fail when prerelease version of public package without dist tag given', async t => { await t.throwsAsync(run(testedModule('2.0.0-1', {name: 'test', version: '1.0.0'}, {yarn: false})), {message: 'You must specify a dist-tag using --tag when publishing a pre-release version. This prevents accidentally tagging unstable versions as "latest". https://docs.npmjs.com/cli/dist-tag'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check for pre-release version' && task.hasFailed())); });
test.serial('should not fail when prerelease version of public package with dist tag given', async t => { execaStub.createStub([ { command: 'git rev-parse --quiet --verify refs/tags/v2.0.0', stdout: '' } ]); await t.notThrowsAsync(run(testedModule('2.0.0-1', {name: 'test', version: '1.0.0'}, {yarn: false, tag: 'pre'}))); });
test.serial('should fail when current branch is not the specified release branch and publishing from any branch not permitted', async t => { execaStub.createStub([ { command: 'git symbolic-ref --short HEAD', exitCode: 0, stdout: 'feature' } ]); await t.throwsAsync(run(testedModule({branch: 'release'})), {message: 'Not on `release` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check current branch' && task.hasFailed())); });