forked from twilio/twilio-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move the plugin-install hook handler out of the init folder
The init folder is for init hook handlers.
- Loading branch information
Sam Harrison
committed
Jun 5, 2020
1 parent
6ce1c0b
commit bd8f030
Showing
4 changed files
with
62 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); |