Skip to content

Commit

Permalink
fix: move the plugin-install hook handler out of the init folder
Browse files Browse the repository at this point in the history
The init folder is for init hook handlers.
  • Loading branch information
Sam Harrison committed Jun 5, 2020
1 parent 6ce1c0b commit bd8f030
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"./src/hooks/init/plugin-verification"
],
"plugins:preinstall": [
"./src/hooks/init/plugin-install"
"./src/hooks/plugin-install"
]
},
"macos": {
Expand Down
File renamed without changes.
63 changes: 0 additions & 63 deletions test/hooks/init/plugin-install.test.js

This file was deleted.

61 changes: 61 additions & 0 deletions test/hooks/plugin-install.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const sinon = require('sinon');
const inquirer = require('inquirer');
const pluginFunc = require('../../src/hooks/plugin-install');
const { expect, test } = require('@twilio/cli-test');

const getNonTwilioPlugin = () => ({
plugin: {
name: '@twilio-labs-h4x0r/plugin-serverless'
}
});

const getTwilioPlugin = () => ({
plugin: {
name: '@twilio/debugger'
}
});

const getTwilioLabsPlugin = () => ({
plugin: {
name: '@twilio-labs/debugger'
}
});

const getUndefinedPlugin = () => ({
plugin: {
name: undefined
}
});

describe('hooks', () => {
describe('plugin-install', () => {
before(() => {
inquirer._prompt = inquirer.prompt;
inquirer.prompt = sinon.stub().resolves({ continue: false });
});

after(() => {
inquirer.prompt = inquirer._prompt;
delete inquirer._prompt;
});

test.stderr().it('warning when non Twilio plugin is installed', async ctx => {
ctx.exit = sinon.stub().resolves(1);
await pluginFunc.call(ctx, getNonTwilioPlugin());
expect(ctx.stderr).to.contain('WARNING');
});

test.stderr().it('warning when plugin is undefined', async ctx => {
ctx.exit = sinon.stub().resolves(1);
await pluginFunc.call(ctx, getUndefinedPlugin());
expect(ctx.stderr).to.contain('WARNING');
});

test.stderr().it('outputs nothing when Twilio plugin is installed', async ctx => {
await pluginFunc.call(ctx, getTwilioPlugin());
expect(ctx.stderr).to.be.empty;
await pluginFunc.call(ctx, getTwilioLabsPlugin());
expect(ctx.stderr).to.be.empty;
});
});
});

0 comments on commit bd8f030

Please sign in to comment.