Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize skipping and enabling tasks #566

Merged
merged 1 commit into from Oct 4, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions source/index.js
Expand Up @@ -117,7 +117,7 @@ module.exports = async (input = 'patch', options) => {
tasks.add([
{
title: 'Cleanup',
skip: () => hasLockFile,
enabled: () => !hasLockFile,
task: () => del('node_modules')
},
{
Expand Down Expand Up @@ -257,18 +257,18 @@ module.exports = async (input = 'patch', options) => {
}
});

tasks.add({
title: 'Creating release draft on GitHub',
enabled: () => isOnGitHub === true,
skip: () => {
if (options.preview) {
return '[Preview] GitHub Releases draft will not be opened in preview mode.';
}

return !options.releaseDraft;
},
task: () => releaseTaskHelper(options, pkg)
});
if (options.releaseDraft) {
tasks.add({
title: 'Creating release draft on GitHub',
enabled: () => isOnGitHub === true,
skip: () => {
if (options.preview) {
return '[Preview] GitHub Releases draft will not be opened in preview mode.';
}
},
task: () => releaseTaskHelper(options, pkg)
});
}

await tasks.run();

Expand Down
4 changes: 2 additions & 2 deletions source/prerequisite-tasks.js
Expand Up @@ -13,7 +13,7 @@ module.exports = (input, pkg, options) => {
const tasks = [
{
title: 'Ping npm registry',
skip: () => pkg.private || isExternalRegistry,
enabled: () => !pkg.private && !isExternalRegistry,
task: async () => npm.checkConnection()
},
{
Expand All @@ -30,7 +30,7 @@ module.exports = (input, pkg, options) => {
},
{
title: 'Verify user is authenticated',
skip: () => process.env.NODE_ENV === 'test' || pkg.private,
enabled: () => process.env.NODE_ENV !== 'test' && !pkg.private,
task: async () => {
const username = await npm.username({
externalRegistry: isExternalRegistry ? pkg.publishConfig.registry : false
Expand Down
12 changes: 6 additions & 6 deletions test/prerequisite-tasks.js
Expand Up @@ -38,7 +38,7 @@ test.serial('public-package published on npm registry: should fail when npm regi
t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && task.hasFailed()));
});

test.serial('private package: should skip task pinging npm registry', async t => {
test.serial('private package: should disable task pinging npm registry', async t => {
execaStub.createStub([
{
command: 'git rev-parse --quiet --verify refs/tags/v2.0.0',
Expand All @@ -47,10 +47,10 @@ test.serial('private package: should skip task pinging npm registry', async t =>
}
]);
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()));
t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && !task.isEnabled()));
});

test.serial('external registry: should skip task pinging npm registry', async t => {
test.serial('external registry: should disable task pinging npm registry', async t => {
execaStub.createStub([
{
command: 'git rev-parse --quiet --verify refs/tags/v2.0.0',
Expand All @@ -60,7 +60,7 @@ test.serial('external registry: should skip task pinging npm registry', async t
]);
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()));
t.true(SilentRenderer.tasks.some(task => task.title === 'Ping npm registry' && !task.isEnabled()));
});

test.serial('should fail when npm version does not match range in `package.json`', async t => {
Expand Down Expand Up @@ -141,7 +141,7 @@ test.serial('should fail when user is not authenticated at external registry', a
t.true(SilentRenderer.tasks.some(task => task.title === 'Verify user is authenticated' && task.hasFailed()));
});

test.serial('private package: should skip task `verify user is authenticated`', async t => {
test.serial('private package: should disable task `verify user is authenticated`', async t => {
execaStub.createStub([
{
command: 'git rev-parse --quiet --verify refs/tags/v2.0.0',
Expand All @@ -152,7 +152,7 @@ test.serial('private package: should skip task `verify user is authenticated`',
process.env.NODE_ENV = 'P';
await run(testedModule('2.0.0', {name: 'test', version: '1.0.0', private: true}, {yarn: false}));
process.env.NODE_ENV = 'test';
t.true(SilentRenderer.tasks.some(task => task.title === 'Verify user is authenticated' && task.isSkipped()));
t.true(SilentRenderer.tasks.some(task => task.title === 'Verify user is authenticated' && !task.isEnabled()));
});

test.serial('should fail when git version does not match range in `package.json`', async t => {
Expand Down