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

Updated Dependencies. Fixed eslint errors. #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
"extends": "airbnb-base",
"plugins": ["import"],
"rules": {
"func-names": "off",
extends: 'airbnb-base',
plugins: ['import'],
rules: {
'func-names': 'off',

// support for node v4
"strict": "off",
"prefer-rest-params": "off",
"react/require-extension" : "off",
"import/no-extraneous-dependencies" : "off"
strict: 'off',
'prefer-rest-params': 'off',
'react/require-extension': 'off',
'import/no-extraneous-dependencies': 'off',
},
env: {
jest: true,
},
"env": {
"jest": true
}
};
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prettier.eslintIntegration": true
}
6 changes: 3 additions & 3 deletions deploy/googleDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class GoogleDeploy {
monitorDeployment,
uploadArtifacts,
updateDeployment,
cleanupDeploymentBucket);
cleanupDeploymentBucket,
);

this.hooks = {
'before:deploy:deploy': () => BbPromise.bind(this)
Expand All @@ -39,8 +40,7 @@ class GoogleDeploy {
.then(this.uploadArtifacts)
.then(this.updateDeployment),

'after:deploy:deploy': () => BbPromise.bind(this)
.then(this.cleanupDeploymentBucket),
'after:deploy:deploy': () => BbPromise.bind(this).then(this.cleanupDeploymentBucket),
};
}
}
Expand Down
50 changes: 25 additions & 25 deletions deploy/googleDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ describe('GoogleDeploy', () => {
let cleanupDeploymentBucketStub;

beforeEach(() => {
validateStub = sinon.stub(googleDeploy, 'validate')
validateStub = sinon.stub(googleDeploy, 'validate').returns(BbPromise.resolve());
setDefaultsStub = sinon.stub(googleDeploy, 'setDefaults').returns(BbPromise.resolve());
createDeploymentStub = sinon
.stub(googleDeploy, 'createDeployment')
.returns(BbPromise.resolve());
setDefaultsStub = sinon.stub(googleDeploy, 'setDefaults')
setDeploymentBucketNameStub = sinon
.stub(googleDeploy, 'setDeploymentBucketName')
.returns(BbPromise.resolve());
createDeploymentStub = sinon.stub(googleDeploy, 'createDeployment')
uploadArtifactsStub = sinon
.stub(googleDeploy, 'uploadArtifacts')
.returns(BbPromise.resolve());
setDeploymentBucketNameStub = sinon.stub(googleDeploy, 'setDeploymentBucketName')
updateDeploymentStub = sinon
.stub(googleDeploy, 'updateDeployment')
.returns(BbPromise.resolve());
uploadArtifactsStub = sinon.stub(googleDeploy, 'uploadArtifacts')
.returns(BbPromise.resolve());
updateDeploymentStub = sinon.stub(googleDeploy, 'updateDeployment')
.returns(BbPromise.resolve());
cleanupDeploymentBucketStub = sinon.stub(googleDeploy, 'cleanupDeploymentBucket')
cleanupDeploymentBucketStub = sinon
.stub(googleDeploy, 'cleanupDeploymentBucket')
.returns(BbPromise.resolve());
});

Expand All @@ -71,24 +74,21 @@ describe('GoogleDeploy', () => {
googleDeploy.cleanupDeploymentBucket.restore();
});

it('should run "before:deploy:deploy" promise chain', () => googleDeploy
.hooks['before:deploy:deploy']().then(() => {
expect(validateStub.calledOnce).toEqual(true);
expect(setDefaultsStub.calledAfter(validateStub)).toEqual(true);
}));
it('should run "before:deploy:deploy" promise chain', () => googleDeploy.hooks['before:deploy:deploy']().then(() => {
expect(validateStub.calledOnce).toEqual(true);
expect(setDefaultsStub.calledAfter(validateStub)).toEqual(true);
}));

it('should run "deploy:deploy" promise chain', () => googleDeploy
.hooks['deploy:deploy']().then(() => {
expect(createDeploymentStub.calledOnce).toEqual(true);
expect(setDeploymentBucketNameStub.calledAfter(createDeploymentStub)).toEqual(true);
expect(uploadArtifactsStub.calledAfter(createDeploymentStub)).toEqual(true);
expect(updateDeploymentStub.calledAfter(uploadArtifactsStub)).toEqual(true);
}));
it('should run "deploy:deploy" promise chain', () => googleDeploy.hooks['deploy:deploy']().then(() => {
expect(createDeploymentStub.calledOnce).toEqual(true);
expect(setDeploymentBucketNameStub.calledAfter(createDeploymentStub)).toEqual(true);
expect(uploadArtifactsStub.calledAfter(createDeploymentStub)).toEqual(true);
expect(updateDeploymentStub.calledAfter(uploadArtifactsStub)).toEqual(true);
}));

it('should run "after:deploy:deploy" promise chain', () => googleDeploy
.hooks['after:deploy:deploy']().then(() => {
expect(cleanupDeploymentBucketStub.calledOnce).toEqual(true);
}));
it('should run "after:deploy:deploy" promise chain', () => googleDeploy.hooks['after:deploy:deploy']().then(() => {
expect(cleanupDeploymentBucketStub.calledOnce).toEqual(true);
}));
});
});
});
33 changes: 18 additions & 15 deletions deploy/lib/cleanupDeploymentBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,32 @@ module.exports = {
bucket: this.serverless.service.provider.deploymentBucketName,
};

return this.provider.request('storage', 'objects', 'list', params)
.then((response) => {
if (!response.items.length) return BbPromise.resolve([]);
return this.provider.request('storage', 'objects', 'list', params).then((response) => {
if (!response.items.length) return BbPromise.resolve([]);

const files = response.items;
const files = response.items;

// 4 old ones + the one which will be uploaded after the cleanup = 5
const objectsToKeepCount = 4;
// 4 old ones + the one which will be uploaded after the cleanup = 5
const objectsToKeepCount = 4;

const orderedObjects = _.orderBy(files, (file) => {
const orderedObjects = _.orderBy(
files,
(file) => {
const timestamp = file.name.match(/(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/)[4];
return timestamp;
}, ['asc']);
},
['asc'],
);

const objectsToKeep = _.takeRight(orderedObjects, objectsToKeepCount);
const objectsToRemove = _.pullAllWith(files, objectsToKeep, _.isEqual);
const objectsToKeep = _.takeRight(orderedObjects, objectsToKeepCount);
const objectsToRemove = _.pullAllWith(files, objectsToKeep, _.isEqual);

if (objectsToRemove.length) {
return BbPromise.resolve(objectsToRemove);
}
if (objectsToRemove.length) {
return BbPromise.resolve(objectsToRemove);
}

return BbPromise.resolve([]);
});
return BbPromise.resolve([]);
});
},

removeObjects(objectsToRemove) {
Expand Down
45 changes: 19 additions & 26 deletions deploy/lib/cleanupDeploymentBucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ describe('CleanupDeploymentBucket', () => {
let removeObjectsStub;

beforeEach(() => {
getObjectsToRemoveStub = sinon.stub(googleDeploy, 'getObjectsToRemove')
.returns(BbPromise.resolve());
removeObjectsStub = sinon.stub(googleDeploy, 'removeObjects')
getObjectsToRemoveStub = sinon
.stub(googleDeploy, 'getObjectsToRemove')
.returns(BbPromise.resolve());
removeObjectsStub = sinon.stub(googleDeploy, 'removeObjects').returns(BbPromise.resolve());
});

afterEach(() => {
googleDeploy.getObjectsToRemove.restore();
googleDeploy.removeObjects.restore();
});

it('should run promise chain', () => googleDeploy
.cleanupDeploymentBucket().then(() => {
expect(getObjectsToRemoveStub.calledOnce).toEqual(true);
expect(removeObjectsStub.calledAfter(getObjectsToRemoveStub));
}));
it('should run promise chain', () => googleDeploy.cleanupDeploymentBucket().then(() => {
expect(getObjectsToRemoveStub.calledOnce).toEqual(true);
expect(removeObjectsStub.calledAfter(getObjectsToRemoveStub));
}));
});

describe('#getObjectsToRemove()', () => {
Expand Down Expand Up @@ -112,13 +111,11 @@ describe('CleanupDeploymentBucket', () => {
bucket: 'sls-my-service-dev-12345678',
name: `${key}/903940390431-2016-08-18T23:42:08/artifact.zip`,
});
expect(requestStub.calledWithExactly(
'storage',
'objects',
'list',
{
expect(
requestStub.calledWithExactly('storage', 'objects', 'list', {
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
}),
).toEqual(true);
});
});

Expand Down Expand Up @@ -148,13 +145,11 @@ describe('CleanupDeploymentBucket', () => {
return googleDeploy.getObjectsToRemove().then((objects) => {
expect(objects.length).toEqual(0);
expect(objects).toEqual([]);
expect(requestStub.calledWithExactly(
'storage',
'objects',
'list',
{
expect(
requestStub.calledWithExactly('storage', 'objects', 'list', {
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
}),
).toEqual(true);
});
});

Expand All @@ -167,13 +162,11 @@ describe('CleanupDeploymentBucket', () => {
return googleDeploy.getObjectsToRemove().then((objects) => {
expect(objects.length).toEqual(0);
expect(objects).toEqual([]);
expect(requestStub.calledWithExactly(
'storage',
'objects',
'list',
{
expect(
requestStub.calledWithExactly('storage', 'objects', 'list', {
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
}),
).toEqual(true);
});
});
});
Expand Down
13 changes: 9 additions & 4 deletions deploy/lib/createDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
project: this.serverless.service.provider.project,
};

return this.provider.request('deploymentmanager', 'deployments', 'list', params)
return this.provider
.request('deploymentmanager', 'deployments', 'list', params)
.then((response) => {
let foundDeployment;

Expand All @@ -37,8 +38,11 @@ module.exports = {

this.serverless.cli.log('Creating deployment...');

const filePath = path.join(this.serverless.config.servicePath,
'.serverless', 'configuration-template-create.yml');
const filePath = path.join(
this.serverless.config.servicePath,
'.serverless',
'configuration-template-create.yml',
);

const deploymentName = `sls-${this.serverless.service.service}-${this.options.stage}`;

Expand All @@ -54,7 +58,8 @@ module.exports = {
},
};

return this.provider.request('deploymentmanager', 'deployments', 'insert', params)
return this.provider
.request('deploymentmanager', 'deployments', 'insert', params)
.then(() => this.monitorDeployment(deploymentName, 'create', 5000));
},
};
Loading