mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #3266 from zerkella/improve-breaking-changes-testing
Improved tests for `logBreakingChange()` function (see #3265):
This commit is contained in:
commit
08dc8864b7
@ -3,8 +3,14 @@ language: node_js
|
||||
matrix:
|
||||
include:
|
||||
- node_js: '4.4'
|
||||
env:
|
||||
SLS_IGNORE_WARNING=*
|
||||
- node_js: '5.11'
|
||||
env:
|
||||
SLS_IGNORE_WARNING=*
|
||||
- node_js: '6.2'
|
||||
env:
|
||||
SLS_IGNORE_WARNING=*
|
||||
- node_js: '6.2'
|
||||
env:
|
||||
- INTEGRATION_TEST=true
|
||||
|
||||
@ -307,67 +307,85 @@ describe('CLI', () => {
|
||||
|
||||
describe('#logBreakingChanges()', () => {
|
||||
let consoleLogStub;
|
||||
let origIgnoreWarning;
|
||||
|
||||
beforeEach(() => {
|
||||
cli = new CLI(serverless);
|
||||
consoleLogStub = sinon.stub(cli, 'consoleLog').returns();
|
||||
origIgnoreWarning = process.env.SLS_IGNORE_WARNING;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cli.consoleLog.restore();
|
||||
delete process.env.SLS_IGNORE_WARNING;
|
||||
if (origIgnoreWarning === undefined) {
|
||||
delete process.env.SLS_IGNORE_WARNING;
|
||||
} else {
|
||||
process.env.SLS_IGNORE_WARNING = origIgnoreWarning;
|
||||
}
|
||||
});
|
||||
|
||||
it('should log breaking changes when they are provided', () => {
|
||||
const nextVersion = 'Next';
|
||||
// Test all possible combinations of provided changes and "ignored" setting
|
||||
[
|
||||
{
|
||||
name: 'should NOT LOG breaking changes when changes are NOT PROVIDED and NOT IGNORED',
|
||||
isProvided: false,
|
||||
isIgnored: false,
|
||||
isLogExpected: false,
|
||||
},
|
||||
{
|
||||
name: 'should NOT LOG breaking changes when changes are NOT PROVIDED and IGNORED',
|
||||
isProvided: false,
|
||||
isIgnored: true,
|
||||
isLogExpected: false,
|
||||
},
|
||||
{
|
||||
name: 'should LOG breaking changes when changes are PROVIDED and NOT IGNORED',
|
||||
isProvided: true,
|
||||
isIgnored: false,
|
||||
isLogExpected: true,
|
||||
},
|
||||
{
|
||||
name: 'should NOT LOG breaking changes when changes are PROVIDED and IGNORED',
|
||||
isProvided: true,
|
||||
isIgnored: true,
|
||||
isLogExpected: false,
|
||||
},
|
||||
].forEach((testCase) => {
|
||||
it(testCase.name, () => {
|
||||
// Stubs
|
||||
const nextVersion = 'Next';
|
||||
|
||||
cli.breakingChanges = [
|
||||
'x is broken',
|
||||
'y will be updated',
|
||||
];
|
||||
let outMessage = '\n';
|
||||
outMessage += chalk.yellow(` WARNING: You are running v${serverlessVersion}. v${nextVersion} will include the following breaking changes:\n`); //eslint-disable-line
|
||||
outMessage += chalk.yellow(' - x is broken\n');
|
||||
outMessage += chalk.yellow(' - y will be updated\n');
|
||||
outMessage += '\n';
|
||||
outMessage += chalk.yellow(' You can opt-out from these warnings by setting the "SLS_IGNORE_WARNING=*" environment variable.\n'); //eslint-disable-line
|
||||
|
||||
let expectedMessage = '\n';
|
||||
expectedMessage += chalk.yellow(` WARNING: You are running v${serverlessVersion}. v${nextVersion} will include the following breaking changes:\n`); //eslint-disable-line
|
||||
expectedMessage += chalk.yellow(' - x is broken\n');
|
||||
expectedMessage += chalk.yellow(' - y will be updated\n');
|
||||
expectedMessage += '\n';
|
||||
expectedMessage += chalk.yellow(' You can opt-out from these warnings by setting the "SLS_IGNORE_WARNING=*" environment variable.\n'); //eslint-disable-line
|
||||
const breakingChanges = [
|
||||
'x is broken',
|
||||
'y will be updated',
|
||||
];
|
||||
|
||||
const message = cli.logBreakingChanges(nextVersion);
|
||||
// Prepare the test environment
|
||||
cli.breakingChanges = testCase.isProvided ? breakingChanges : [];
|
||||
|
||||
expect(consoleLogStub.calledOnce).to.equal(true);
|
||||
expect(message).to.equal(expectedMessage);
|
||||
});
|
||||
if (testCase.isIgnored) {
|
||||
process.env.SLS_IGNORE_WARNING = '*';
|
||||
} else {
|
||||
delete process.env.SLS_IGNORE_WARNING;
|
||||
}
|
||||
|
||||
it('should not log breaking changes when they are not provided', () => {
|
||||
cli.breakingChanges = [];
|
||||
// Test expectations
|
||||
const expectedResult = testCase.isLogExpected ? outMessage : '';
|
||||
const expectedLogCalled = testCase.isLogExpected;
|
||||
|
||||
const expectedMessage = '';
|
||||
// Carry the test
|
||||
const actualResult = cli.logBreakingChanges(nextVersion);
|
||||
|
||||
const message = cli.logBreakingChanges();
|
||||
|
||||
expect(consoleLogStub.calledOnce).to.equal(false);
|
||||
expect(message).to.equal(expectedMessage);
|
||||
});
|
||||
|
||||
it('should not log breaking changes when the "disable environment variable" is set', () => {
|
||||
// we have some breaking changes
|
||||
cli.breakingChanges = [
|
||||
'x is broken',
|
||||
'y will be updated',
|
||||
];
|
||||
|
||||
// this should prevent the breaking changes from being logged
|
||||
process.env.SLS_IGNORE_WARNING = '*';
|
||||
|
||||
cli.breakingChanges = [];
|
||||
|
||||
const expectedMessage = '';
|
||||
|
||||
const message = cli.logBreakingChanges();
|
||||
|
||||
expect(consoleLogStub.calledOnce).to.equal(false);
|
||||
expect(message).to.equal(expectedMessage);
|
||||
expect(actualResult).to.equal(expectedResult);
|
||||
expect(consoleLogStub.calledOnce).to.equal(expectedLogCalled);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user