frontend/.pnpm-store/v3/files/e8/30b6fa4f55e332236da3a0d3454c240b3dafd03cb16df6277877e952bd31975eb6570e3b3f8df32eedd63d436a8002ab011c75dd823b1626e5b4fff86f1f54

98 lines
3.4 KiB
Plaintext

const test = require('ava');
const sinon = require('sinon');
const Prompt = require('../lib/prompt');
const Config = require('../lib/config');
const git = require('../lib/plugin/git/prompts');
const github = require('../lib/plugin/github/prompts');
const gitlab = require('../lib/plugin/gitlab/prompts');
const npm = require('../lib/plugin/npm/prompts');
const { factory } = require('./util');
const prompts = { git, github, gitlab, npm };
const yes = ([options]) => Promise.resolve({ [options.name]: true });
const no = ([options]) => Promise.resolve({ [options.name]: false });
test.beforeEach(t => {
t.context.getInquirer = stub => ({
prompt: stub
});
});
test('should not create prompt if disabled', async t => {
const task = sinon.spy();
const stub = sinon.stub().callsFake(yes);
const inquirer = t.context.getInquirer(stub);
const prompt = factory(Prompt, { container: { inquirer } });
prompt.register(prompts.git);
await prompt.show({ enabled: false, prompt: 'push', task });
t.is(stub.callCount, 0);
t.is(task.callCount, 0);
});
test('should create prompt', async t => {
const stub = sinon.stub().callsFake(yes);
const inquirer = t.context.getInquirer(stub);
const prompt = factory(Prompt, { container: { inquirer } });
prompt.register(prompts.git);
await prompt.show({ prompt: 'push' });
t.is(stub.callCount, 1);
t.deepEqual(stub.firstCall.args[0][0], {
type: 'confirm',
message: 'Push?',
name: 'push',
choices: false,
transformer: false,
default: true
});
});
[
['git', 'commit', 'Commit (Release 1.0.0)?'],
['git', 'tag', 'Tag (1.0.0)?'],
['git', 'push', 'Push?'],
['github', 'release', 'Create a pre-release on GitHub (Release 1.0.0)?'],
['gitlab', 'release', 'Create a release on GitLab (Release 1.0.0)?'],
['npm', 'publish', 'Publish my-pkg@next to npm?'],
['npm', 'otp', 'Please enter OTP for npm:']
].map(async ([namespace, prompt, message]) => {
test(`should create prompt and render template message (${namespace}.${prompt})`, async t => {
const stub = sinon.stub().callsFake(yes);
const config = new Config({
isPreRelease: true,
git: { tagName: 'v${version}' },
npm: { name: 'my-pkg', tag: 'next' }
});
config.setContext({ version: '1.0.0', git: { tagName: '1.0.0' } });
const inquirer = t.context.getInquirer(stub);
const p = factory(Prompt, { container: { inquirer } });
p.register(prompts[namespace], namespace);
await p.show({ namespace, prompt, context: config.getContext() });
t.is(stub.callCount, 1);
t.is(stub.firstCall.args[0][0].message, message);
});
});
test('should execute task after positive answer', async t => {
const task = sinon.spy();
const stub = sinon.stub().callsFake(yes);
const inquirer = t.context.getInquirer(stub);
const prompt = factory(Prompt, { container: { inquirer } });
prompt.register(prompts.git);
await prompt.show({ prompt: 'push', task });
t.is(stub.callCount, 1);
t.is(task.callCount, 1);
t.is(task.firstCall.args[0], true);
});
test('should not execute task after negative answer', async t => {
const task = sinon.spy();
const stub = sinon.stub().callsFake(no);
const inquirer = t.context.getInquirer(stub);
const prompt = factory(Prompt, { container: { inquirer } });
prompt.register(prompts.git);
await prompt.show({ prompt: 'push', task });
t.is(stub.callCount, 1);
t.is(task.callCount, 0);
});