From 3dd63ccb47e140ee396e538e9f1c583e603b6de4 Mon Sep 17 00:00:00 2001 From: Doug Moscrop Date: Sun, 6 Nov 2016 14:25:06 -0500 Subject: [PATCH 01/24] Try to use avajs for faster integration tests --- package.json | 5 +- scripts/integration-test-cleanup.js | 93 +++++++ tests/integration/all.js | 37 --- .../api-keys/tests.js | 115 +++++---- .../integration-lambda-proxy/cors/tests.js | 89 ++++--- .../custom-authorizers/tests.js | 91 ++++--- .../simple-api/tests.js | 236 +++++++++--------- .../integration-lambda/api-keys/tests.js | 115 +++++---- .../integration-lambda/cors/tests.js | 89 ++++--- .../custom-authorizers/tests.js | 91 ++++--- .../integration-lambda/simple-api/tests.js | 235 +++++++++-------- .../aws/general/custom-resources/tests.js | 69 +++-- .../general/environment-variables/tests.js | 49 ++-- .../aws/general/nested-handlers/tests.js | 33 ++- .../aws/general/overwrite-resources/tests.js | 57 ++--- .../tests.js | 55 ++-- .../tests.js | 47 ++-- .../tests.js | 43 ++-- .../tests.js | 39 ++- .../tests.js | 45 ++-- .../tests.js | 49 ++-- .../multiple-topics-single-function/tests.js | 43 ++-- .../single-topic-multiple-functions/tests.js | 47 ++-- .../sns/single-topic-single-function/tests.js | 39 ++- .../general/custom-plugins/tests.js | 49 ++-- .../general/local-plugins/tests.js | 33 ++- tests/integration/simple-integration-test.js | 153 ++++++------ tests/utils/index.js | 3 +- 28 files changed, 1009 insertions(+), 1040 deletions(-) create mode 100644 scripts/integration-test-cleanup.js delete mode 100644 tests/integration/all.js diff --git a/package.json b/package.json index 0e21f8542..fbecd44c9 100644 --- a/package.json +++ b/package.json @@ -49,10 +49,11 @@ "scripts": { "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", - "simple-integration-test": "mocha tests/integration/simple-integration-test", - "complex-integration-test": "mocha tests/integration/all" + "simple-integration-test": "ava tests/integration/simple-integration-test.js", + "complex-integration-test": "ava -c 8 tests/integration/**/tests.js" }, "devDependencies": { + "ava": "^0.16.0", "chai": "^3.5.0", "coveralls": "^2.11.12", "eslint": "^3.3.1", diff --git a/scripts/integration-test-cleanup.js b/scripts/integration-test-cleanup.js new file mode 100644 index 000000000..23cea15f4 --- /dev/null +++ b/scripts/integration-test-cleanup.js @@ -0,0 +1,93 @@ +const BbPromise = require('bluebird'); +const AWS = require('aws-sdk'); + +const CF = new AWS.CloudFormation({ region: 'us-east-1' }); +const S3 = new AWS.S3({ region: 'us-east-1' }); + +BbPromise.promisifyAll(CF, { suffix: 'Promised' }); +BbPromise.promisifyAll(S3, { suffix: 'Promised' }); + +const logger = console; +const pattern = process.env.MATCH || '(test)-[0-9]+-[0-9]+-dev.+'; +const regex = new RegExp(`^${pattern}/i`); + +function emptyS3Bucket(bucket) { + return S3.listObjectsPromised({ Bucket: bucket }) + .then(data => { + logger.log('Bucket', bucket, 'has', data.Contents.length, 'items'); + if (data.Contents.length) { + const keys = data.Contents.map(item => Object.assign({}, { Key: item.Key })); + return S3.deleteObjectsPromised({ + Bucket: bucket, + Delete: { + Objects: keys, + }, + }); + } + return Promise.resolve(); + }); +} + +function deleteS3Bucket(bucket) { + return emptyS3Bucket(bucket) + .then(() => { + logger.log('Bucket', bucket, 'is now empty, deleting ...'); + return S3.deleteBucketPromised({ Bucket: bucket }); + }); +} + +function cleanupS3Buckets(token) { + logger.log('Looking through buckets ...'); + + const params = {}; + + if (token) { + params.NextToken = token; + } + + return S3.listBucketsPromised() + .then(response => + response.Buckets.reduce((memo, bucket) => { + if (bucket.Name.match(regex)) { + return memo.then(() => deleteS3Bucket(bucket.Name)); + } + return memo; + }, Promise.resolve()) + .then(() => { + if (response.NextToken) { + return cleanupS3Buckets(response.NextToken); + } + return Promise.resolve(); + }) + ); +} + +function cleanupCFStacks(token) { + const params = {}; + + if (token) { + params.NextToken = token; + } + + logger.log('Looking through stacks ...'); + return CF.listStacksPromised(params) + .then(response => + response.StackSummaries.reduce((memo, stack) => { + if (stack.StackName.match(regex)) { + if (['DELETE_COMPLETE', 'DELETE_IN_PROGRESS'].indexOf(stack.StackStatus) === -1) { + logger.log('Deleting stack', stack.StackName); + return memo.then(() => CF.deleteStackPromised({ StackName: stack.StackName })); + } + } + return memo; + }, Promise.resolve()) + .then(() => { + if (response.NextToken) { + return cleanupCFStacks(response.NextToken); + } + return Promise.resolve(); + }) + ); +} + +cleanupS3Buckets().then(cleanupCFStacks); diff --git a/tests/integration/all.js b/tests/integration/all.js deleted file mode 100644 index eff001cd9..000000000 --- a/tests/integration/all.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -// AWS -// General -require('./aws/general/nested-handlers/tests'); -require('./aws/general/custom-resources/tests'); -require('./aws/general/overwrite-resources/tests'); -require('./aws/general/environment-variables/tests'); - -// API Gateway -// Integration: Lambda -require('./aws/api-gateway/integration-lambda/simple-api/tests'); -require('./aws/api-gateway/integration-lambda/custom-authorizers/tests'); -require('./aws/api-gateway/integration-lambda/cors/tests'); -// Integration: Lambda Proxy -require('./aws/api-gateway/integration-lambda-proxy/simple-api/tests'); -require('./aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests'); -require('./aws/api-gateway/integration-lambda-proxy/cors/tests'); - -// Schedule -require('./aws/schedule/multiple-schedules-multiple-functions/tests'); - -// SNS -require('./aws/sns/single-topic-single-function/tests'); -require('./aws/sns/single-topic-multiple-functions/tests'); -require('./aws/sns/multiple-topics-single-function/tests'); -require('./aws/sns/multiple-topics-multiple-functions/tests'); - -// S3 -require('./aws/s3/single-event-single-function-single-bucket/tests'); -require('./aws/s3/multiple-events-single-function-single-bucket/tests'); -require('./aws/s3/multiple-events-multiple-functions-single-bucket/tests'); -require('./aws/s3/multiple-events-multiple-functions-multiple-buckets/tests'); - -// General -require('./general/custom-plugins/tests'); -require('./general/local-plugins/tests'); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index 42b645560..dd6843d3b 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -17,69 +18,65 @@ const APIG = new AWS.APIGateway({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', function () { - this.timeout(0); +let stackName; +let endpoint; +let apiKey; - let stackName; - let endpoint; - let apiKey; +test.before('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + // replace name of the API key with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + const apiKeyName = crypto.randomBytes(8).toString('hex'); - const apiKeyName = crypto.randomBytes(8).toString('hex'); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); - - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - - expect(apiKey.length).to.be.above(0); - }); - - it('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) - ); - - it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) - ); - - after(() => { - Utils.removeService(); - }); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) +); + +test.before('should expose the API key(s) with its values when running the info command', () => { + const info = execSync(`${Utils.serverlessExec} info`); + + const stringifiedOutput = (new Buffer(info, 'base64').toString()); + + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + + expect(apiKey.length).to.be.above(0); +}); + +test('should reject a request with an invalid API Key', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) +); + +test('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js index 5781519f0..1ee75cebf 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,51 +13,47 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda Proxy): CORS test', function () { - this.timeout(0); +let stackName; +let endpointBase; - let stackName; - let endpointBase; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) - ); - - it('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + }) +); + +test.before('should setup CORS support with simple string config', () => + fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) +); + +test('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js index ce9676147..80319f8b3 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,52 +13,48 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', function () { - this.timeout(0); +let stackName; +let endpoint; - let stackName; - let endpoint; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) +); + +test('should reject requests without authorization', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) +); + +test('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) +); + +test('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js index 44cbb7f80..53729c98f 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,130 +13,117 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', function () { - this.timeout(0); +let stackName; +let endpoint; - let stackName; - let endpoint; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }) - ); - - describe('when having a "without-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +test.before(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + return CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}`; }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/with-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - after(() => { - Utils.removeService(); - }); +}); + +test('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index 615058232..9788a9c9b 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -17,69 +18,65 @@ const APIG = new AWS.APIGateway({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda): API keys test', function () { - this.timeout(0); +let stackName; +let endpoint; +let apiKey; - let stackName; - let endpoint; - let apiKey; +test.before('AWS - API Gateway (Integration: Lambda): API keys test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + // replace name of the API key with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + const apiKeyName = crypto.randomBytes(8).toString('hex'); - const apiKeyName = crypto.randomBytes(8).toString('hex'); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); - - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - - expect(apiKey.length).to.be.above(0); - }); - - it('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) - ); - - it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) - ); - - after(() => { - Utils.removeService(); - }); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) +); + +test.before('should expose the API key(s) with its values when running the info command', () => { + const info = execSync(`${Utils.serverlessExec} info`); + + const stringifiedOutput = (new Buffer(info, 'base64').toString()); + + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + + expect(apiKey.length).to.be.above(0); +}); + +test('should reject a request with an invalid API Key', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) +); + +test('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js index f2252cd8e..0257fd9fa 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,51 +13,47 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda): CORS test', function () { - this.timeout(0); +let stackName; +let endpointBase; - let stackName; - let endpointBase; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) - ); - - it('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - API Gateway (Integration: Lambda): CORS test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + }) +); + +test('should setup CORS support with simple string config', () => + fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) +); + +test('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js index a58f8a4b1..b382c6d04 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,52 +13,48 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda): Custom authorizers test', function () { - this.timeout(0); +let stackName; +let endpoint; - let stackName; - let endpoint; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - API Gateway (Integration: Lambda): Custom authorizers test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) +); + +test('should reject requests without authorization', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) +); + +test('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) +); + +test('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js index a91c03ada..608db9c3c 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -12,130 +13,118 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('AWS - API Gateway (Integration: Lambda): Simple API test', function () { - this.timeout(0); +let stackName; +let endpoint; - let stackName; - let endpoint; +test.before(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }) - ); - - describe('when having a "without-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + return CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}`; }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/with-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - after(() => { - Utils.removeService(); - }); +}); + +test('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); +}); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index 3dee13db5..57ad53ef9 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const AWS = require('aws-sdk'); @@ -15,46 +16,42 @@ const S3 = new AWS.S3({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(S3, { suffix: 'Promised' }); -describe('AWS - General: Custom resources test', function () { - this.timeout(0); +let stackName; +let s3BucketName; - let stackName; - let s3BucketName; +test.before('AWS - General: Custom resources test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + // replace name of bucket which is created through custom resources with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - // replace name of bucket which is created through custom resources with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + s3BucketName = crypto.randomBytes(8).toString('hex'); - s3BucketName = crypto.randomBytes(8).toString('hex'); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, s3BucketName); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, s3BucketName); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - it('should add the custom outputs to the Outputs section', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'MyCustomOutput' }).OutputValue) - .then((endpointOutput) => { - expect(endpointOutput).to.equal('SomeValue'); - }) - ); - - it('should create the custom resources (a S3 bucket)', () => - S3.listBucketsPromised() - .then((result) => !!_.find(result.Buckets, - { Name: s3BucketName })) - .then((found) => expect(found).to.equal(true)) - ); - - after(() => { - Utils.removeService(); - }); + Utils.deployService(); +}); + +test('should add the custom outputs to the Outputs section', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'MyCustomOutput' }).OutputValue) + .then((endpointOutput) => { + expect(endpointOutput).to.equal('SomeValue'); + }) +); + +test('should create the custom resources (a S3 bucket)', () => + S3.listBucketsPromised() + .then((result) => !!_.find(result.Buckets, + { Name: s3BucketName })) + .then((found) => expect(found).to.equal(true)) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/general/environment-variables/tests.js b/tests/integration/aws/general/environment-variables/tests.js index 21d94a73f..3e1604969 100644 --- a/tests/integration/aws/general/environment-variables/tests.js +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -1,35 +1,32 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -describe('AWS - General: Environment variables test', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose environment variables', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - - expect(result.environment_variables.provider_level_variable_1) - .to.be.equal('provider_level_1'); - expect(result.environment_variables.function_level_variable_1) - .to.be.equal('function_level_1'); - expect(result.environment_variables.function_level_variable_2) - .to.be.equal('function_level_2'); - expect(result.environment_variables.provider_level_variable_2) - .to.be.equal('overwritten_by_function'); - }); - - after(() => { - Utils.removeService(); - }); +test.before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should expose environment variables', () => { + const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); + + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + + expect(result.environment_variables.provider_level_variable_1) + .to.be.equal('provider_level_1'); + expect(result.environment_variables.function_level_variable_1) + .to.be.equal('function_level_1'); + expect(result.environment_variables.function_level_variable_2) + .to.be.equal('function_level_2'); + expect(result.environment_variables.provider_level_variable_2) + .to.be.equal('overwritten_by_function'); +}); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/general/nested-handlers/tests.js b/tests/integration/aws/general/nested-handlers/tests.js index 3525462e5..83d5ba9c0 100644 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ b/tests/integration/aws/general/nested-handlers/tests.js @@ -1,27 +1,24 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -describe('AWS - General: Nested handlers test', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should invoke the nested handler function from AWS', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); - }); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - General: Nested handlers test', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should invoke the nested handler function from AWS', () => { + const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); + + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); +}); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/general/overwrite-resources/tests.js b/tests/integration/aws/general/overwrite-resources/tests.js index bb1cb7338..309c62a32 100644 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ b/tests/integration/aws/general/overwrite-resources/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const AWS = require('aws-sdk'); @@ -10,35 +11,31 @@ const Utils = require('../../../../utils/index'); const Lambda = new AWS.Lambda({ region: 'us-east-1' }); BbPromise.promisifyAll(Lambda, { suffix: 'Promised' }); -describe('AWS - General: Overwrite resources test', function () { - this.timeout(0); +let stackName; - let stackName; - - before(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should overwrite timeout config for hello function', () => { - const helloFunctionName = `${stackName}-hello`; - return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(10); - }); - }); - - it('should NOT overwrite timeout config for world function', () => { - const worldFunctionName = `${stackName}-world`; - return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(6); - }); - }); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - General: Overwrite resources test', () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should overwrite timeout config for hello function', () => { + const helloFunctionName = `${stackName}-hello`; + return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) + .then(data => { + const timeout = data.Configuration.Timeout; + expect(timeout).to.equal(10); + }); +}); + +test('should NOT overwrite timeout config for world function', () => { + const worldFunctionName = `${stackName}-world`; + return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) + .then(data => { + const timeout = data.Configuration.Timeout; + expect(timeout).to.equal(6); + }); +}); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js index 7a38a6722..fa2a35f80 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js @@ -1,36 +1,33 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - S3: Multiple events in multiple functions with multiple buckets', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions when object created or deleted in buckets', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:s3/g.test(helloLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(helloLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(helloLogs)).to.equal(true); - - expect(/aws:s3/g.test(worldLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(worldLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(worldLogs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger functions when object created or deleted in buckets', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:s3/g.test(helloLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(helloLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(helloLogs)).to.equal(true); + + expect(/aws:s3/g.test(worldLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(worldLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(worldLogs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js index e93dba618..6befa093a 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js @@ -1,32 +1,29 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - S3: Multiple events in multiple functions with a single bucket', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger create/remove functions on object create / remove', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const createLogs = Utils.getFunctionLogs('create'); - const removeLogs = Utils.getFunctionLogs('remove'); - - expect(/aws:s3/g.test(createLogs)).to.equal(true); - expect(/aws:s3/g.test(removeLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(createLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(removeLogs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger create/remove functions on object create / remove', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const createLogs = Utils.getFunctionLogs('create'); + const removeLogs = Utils.getFunctionLogs('remove'); + + expect(/aws:s3/g.test(createLogs)).to.equal(true); + expect(/aws:s3/g.test(removeLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(createLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(removeLogs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js index 71f0727fe..51e8ff2a1 100644 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js @@ -1,30 +1,27 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - S3: Multiple events in a single function with a single bucket', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when object created or deleted in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(logs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when object created or deleted in bucket', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + + expect(/aws:s3/g.test(logs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(logs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js index 87ff53529..0e5b01352 100644 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js @@ -1,28 +1,25 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - S3: Single event in a single function with a single bucket', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when object created in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when object created in bucket', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:s3/g.test(logs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js index 5ea854aec..08091f27d 100644 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js +++ b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js @@ -1,32 +1,29 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); const BbPromise = require('bluebird'); -describe('AWS - Schedule: Multiple schedules with multiple functions', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions every minute', () => BbPromise.resolve() - .delay(100000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/Scheduled Event/g.test(helloLogs)).to.equal(true); - expect(/aws\.events/g.test(helloLogs)).to.equal(true); - expect(/Scheduled Event/g.test(worldLogs)).to.equal(true); - expect(/aws\.events/g.test(worldLogs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - Schedule: Multiple schedules with multiple functions', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger functions every minute', () => BbPromise.resolve() + .delay(100000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/Scheduled Event/g.test(helloLogs)).to.equal(true); + expect(/aws\.events/g.test(helloLogs)).to.equal(true); + expect(/Scheduled Event/g.test(worldLogs)).to.equal(true); + expect(/aws\.events/g.test(worldLogs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js index b15b0907b..72b32d79e 100644 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js +++ b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js @@ -1,33 +1,30 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - SNS: Multiple topics with multiple functions', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/topic1/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/topic2/g.test(worldLogs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - SNS: Multiple topics with multiple functions', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'topic1') + .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:sns/g.test(helloLogs)).to.equal(true); + expect(/topic1/g.test(helloLogs)).to.equal(true); + expect(/aws:sns/g.test(worldLogs)).to.equal(true); + expect(/topic2/g.test(worldLogs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-single-function/tests.js b/tests/integration/aws/sns/multiple-topics-single-function/tests.js index 3866f9aa7..0c5269d26 100644 --- a/tests/integration/aws/sns/multiple-topics-single-function/tests.js +++ b/tests/integration/aws/sns/multiple-topics-single-function/tests.js @@ -1,30 +1,27 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - SNS: Multiple topics single function', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/topic1/g.test(logs)).to.equal(true); - expect(/topic2/g.test(logs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - SNS: Multiple topics single function', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'topic1') + .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:sns/g.test(logs)).to.equal(true); + expect(/topic1/g.test(logs)).to.equal(true); + expect(/topic2/g.test(logs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js index 19c8adf69..5e92d87c4 100644 --- a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js +++ b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js @@ -1,32 +1,29 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - SNS: Single topic with multiple functions', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/hello world/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/hello world/g.test(worldLogs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - SNS: Single topic with multiple functions', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'hello world') + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:sns/g.test(helloLogs)).to.equal(true); + expect(/hello world/g.test(helloLogs)).to.equal(true); + expect(/aws:sns/g.test(worldLogs)).to.equal(true); + expect(/hello world/g.test(worldLogs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/aws/sns/single-topic-single-function/tests.js b/tests/integration/aws/sns/single-topic-single-function/tests.js index 7af1ff575..8e8690024 100644 --- a/tests/integration/aws/sns/single-topic-single-function/tests.js +++ b/tests/integration/aws/sns/single-topic-single-function/tests.js @@ -1,28 +1,25 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -describe('AWS - SNS: Single topic with single function', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/hello world/g.test(logs)).to.equal(true); - }) - ); - - after(() => { - Utils.removeService(); - }); +test.before('AWS - SNS: Single topic with single function', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + +test('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'hello world') + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:sns/g.test(logs)).to.equal(true); + expect(/hello world/g.test(logs)).to.equal(true); + }) +); + +test.after(() => { + Utils.removeService(); }); diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index 3ef77e3d6..af82ad69b 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -1,38 +1,35 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -describe('General: Custom plugins test', function () { - this.timeout(0); +test.before('General: Custom plugins test', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + // cd into the plugins directory + execSync('cd serverless-plugin-greeter'); - // cd into the plugins directory - execSync('cd serverless-plugin-greeter'); + // link and install the npm package / plugin + execSync('npm link serverless-plugin-greeter && npm install --save serverless-plugin-greeter'); - // link and install the npm package / plugin - execSync('npm link serverless-plugin-greeter && npm install --save serverless-plugin-greeter'); - - // cd back into the service directory - execSync('cd ..'); - }); - - it('should successfully run the greet command of the custom plugin', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} greet`); - - // note: the result will return a newline at the end - const result = new Buffer(pluginExecution, 'base64').toString(); - - expect(result).to.equal('Hello from the greeter plugin!'); - }); - - after(() => { - // unlink the npm package - execSync('npm r serverless-plugin-greeter -g'); - }); + // cd back into the service directory + execSync('cd ..'); +}); + +test.after(() => { + // unlink the npm package + execSync('npm r serverless-plugin-greeter -g'); +}); + +test('should successfully run the greet command of the custom plugin', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} greet`); + + // note: the result will return a newline at the end + const result = new Buffer(pluginExecution, 'base64').toString(); + + expect(result).to.equal('Hello from the greeter plugin!'); }); diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js index ec1bc3a41..06a17685c 100644 --- a/tests/integration/general/local-plugins/tests.js +++ b/tests/integration/general/local-plugins/tests.js @@ -1,27 +1,24 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -describe('General: Local plugins test', function () { - this.timeout(0); - - before(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - }); - - it('should successfully run the one command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} one`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin one ran successfully/g.test(result)).to.equal(true); - }); - - it('should successfully run the two command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} two`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin two ran successfully/g.test(result)).to.equal(true); - }); +test.before('General: Local plugins test', () => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); +}); + +test('should successfully run the one command', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} one`); + const result = new Buffer(pluginExecution, 'base64').toString(); + expect(/plugin one ran successfully/g.test(result)).to.equal(true); +}); + +test('should successfully run the two command', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} two`); + const result = new Buffer(pluginExecution, 'base64').toString(); + expect(/plugin two ran successfully/g.test(result)).to.equal(true); }); diff --git a/tests/integration/simple-integration-test.js b/tests/integration/simple-integration-test.js index 40c990119..6adcc1b14 100644 --- a/tests/integration/simple-integration-test.js +++ b/tests/integration/simple-integration-test.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const expect = require('chai').expect; const path = require('path'); const fse = require('fs-extra'); @@ -24,82 +25,78 @@ const stackName = `${newServiceName}-dev`; const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -describe('Service Lifecyle Integration Test', function () { - this.timeout(0); - - it('should create service in tmp directory', () => { - execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); - execSync(`sed -i.bak s/${templateName}/${newServiceName}/g serverless.yml`); - execSync("sed -i.bak '/provider:/a \\ cfLogs: true' serverless.yml"); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); - }); - - it('should deploy service to aws', () => { - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); - - return CF.describeStacksPromised({ StackName: stackName }) - .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); - }); - - it('should invoke function from aws', () => { - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - // parse it once again because the body is stringified to be LAMBDA-PROXY ready - const message = JSON.parse(result.body).message; - expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); - }); - - it('should deploy updated service to aws', () => { - const newHandler = - ` - 'use strict'; - - module.exports.hello = (event, context, cb) => cb(null, - { message: 'Service Update Succeeded' } - ); - `; - - serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); - }); - - it('should invoke updated function from aws', () => { - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.message).to.be.equal('Service Update Succeeded'); - }); - - it('should list existing deployments and roll back to first deployment', () => { - let timestamp; - const listDeploys = execSync(`${serverlessExec} deploy list`); - const output = listDeploys.toString(); - const match = output.match(new RegExp('Timestamp: (.+)')); - if (match) { - timestamp = match[1]; - } - // eslint-disable-next-line no-unused-expressions - expect(timestamp).to.not.undefined; - - execSync(`${serverlessExec} rollback -t ${timestamp}`); - - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - // parse it once again because the body is stringified to be LAMBDA-PROXY ready - const message = JSON.parse(result.body).message; - expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); - }); - - it('should remove service from aws', () => { - execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); - - return CF.describeStacksPromised({ StackName: stackName }) - .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) - .catch(e => { - if (e.message.indexOf('does not exist') > -1) return BbPromise.resolve(); - throw new serverless.classes.Error(e); - }); - }); +test.serial('should create service in tmp directory', () => { + execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); + execSync(`sed -i.bak s/${templateName}/${newServiceName}/g serverless.yml`); + execSync("sed -i.bak '/provider:/a \\ cfLogs: true' serverless.yml"); + expect(serverless.utils + .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); + expect(serverless.utils + .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); +}); + +test.serial('should deploy service to aws', () => { + execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); + + return CF.describeStacksPromised({ StackName: stackName }) + .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); +}); + +test.serial('should invoke function from aws', () => { + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + // parse it once again because the body is stringified to be LAMBDA-PROXY ready + const message = JSON.parse(result.body).message; + expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); +}); + +test.serial('should deploy updated service to aws', () => { + const newHandler = + ` + 'use strict'; + + module.exports.hello = (event, context, cb) => cb(null, + { message: 'Service Update Succeeded' } + ); + `; + + serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); + execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); +}); + +test.serial('should invoke updated function from aws', () => { + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + expect(result.message).to.be.equal('Service Update Succeeded'); +}); + +test.serial('should list existing deployments and roll back to first deployment', () => { + let timestamp; + const listDeploys = execSync(`${serverlessExec} deploy list`); + const output = listDeploys.toString(); + const match = output.match(new RegExp('Timestamp: (.+)')); + if (match) { + timestamp = match[1]; + } + // eslint-disable-next-line no-unused-expressions + expect(timestamp).to.not.undefined; + + execSync(`${serverlessExec} rollback -t ${timestamp}`); + + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + // parse it once again because the body is stringified to be LAMBDA-PROXY ready + const message = JSON.parse(result.body).message; + expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); +}); + +test.serial('should remove service from aws', () => { + execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); + + return CF.describeStacksPromised({ StackName: stackName }) + .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) + .catch(e => { + if (e.message.indexOf('does not exist') > -1) return BbPromise.resolve(); + throw new serverless.classes.Error(e); + }); }); diff --git a/tests/utils/index.js b/tests/utils/index.js index b3195db4e..df7496407 100644 --- a/tests/utils/index.js +++ b/tests/utils/index.js @@ -24,7 +24,8 @@ module.exports = { getTmpFilePath, createTestService: (templateName, testServiceDir) => { - const serviceName = `service-${(new Date()).getTime().toString()}`; + const hrtime = process.hrtime(); + const serviceName = `test-${hrtime[0]}-${hrtime[1]}`; const tmpDir = path.join(os.tmpdir(), 'tmpdirs-serverless', 'integration-test-suite', From b5b1ac18f127fe3cc00edaffe9ff9cbab1abf31f Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 12:25:09 +0100 Subject: [PATCH 02/24] migrate new package test --- .../integration/aws/general/package/tests.js | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index d2a858bcb..28090b5f6 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -1,5 +1,6 @@ 'use strict'; +const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; @@ -10,33 +11,30 @@ const fs = require('fs'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); const Utils = require('../../../../utils/index'); -describe('AWS - General: Deployment with --noDeploy', function () { - this.timeout(0); - let serviceName; - let deploy; +let serviceName; +let deploy; - before(() => { - serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); - }); +test.before('AWS - General: Deployment with --noDeploy', () => { + serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); +}); - it('should deploy package with --noDeploy flag', () => { - const result = new Buffer(deploy, 'base64').toString(); - const resultLines = result.split(EOL); - expect(resultLines[1]).to.have.string('--noDeploy'); - }); +test('should deploy package with --noDeploy flag', () => { + const result = new Buffer(deploy, 'base64').toString(); + const resultLines = result.split(EOL); + expect(resultLines[1]).to.have.string('--noDeploy'); +}); - it('should have create cloudformation files and functions zip', () => { - const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); - expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); - expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); - expect(deployedFiles[2]).to.match(/service-[0-9]{13}.zip/); - }); +test('should have create cloudformation files and functions zip', () => { + const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); + expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); + expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); + expect(deployedFiles[2]).to.match(/test-[0-9]{6}-[0-9]{9}.zip/); +}); - it('should not found stack from AWS', (done) => { - CF.describeStackResources({ StackName: serviceName }, (error) => { - expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); - done(); - }); +test('should not found stack from AWS', (done) => { + CF.describeStackResources({ StackName: serviceName }, (error) => { + expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); + done(); }); }); From d477f3605ee7ae14f4feedfecdc3bfc8727e8174 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 12:51:34 +0100 Subject: [PATCH 03/24] add jest --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 211dd8520..df70086e5 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint-plugin-jsx-a11y": "^2.1.0", "eslint-plugin-react": "^6.1.1", "istanbul": "^0.4.4", + "jest-cli": "^18.0.0", "jszip": "^3.1.2", "markdown-magic": "0.1.0", "mocha": "^3.0.2", From 8f895ce3b412d1e01ccd8ad8f806a86cb0f56cb6 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 14:42:33 +0100 Subject: [PATCH 04/24] migrate to jest --- .../api-keys/tests.js | 53 ++++++++++--------- .../integration-lambda-proxy/cors/tests.js | 32 +++++------ .../custom-authorizers/tests.js | 52 +++++++++--------- .../simple-api/tests.js | 29 +++++----- .../integration-lambda/api-keys/tests.js | 53 ++++++++++--------- .../integration-lambda/cors/tests.js | 44 ++++++++------- .../custom-authorizers/tests.js | 52 +++++++++--------- .../integration-lambda/simple-api/tests.js | 29 +++++----- .../aws/general/custom-resources/tests.js | 27 +++++----- .../general/environment-variables/tests.js | 7 ++- .../aws/general/nested-handlers/tests.js | 7 ++- .../aws/general/overwrite-resources/tests.js | 9 ++-- .../integration/aws/general/package/tests.js | 9 ++-- .../tests.js | 7 ++- .../tests.js | 7 ++- .../tests.js | 7 ++- .../tests.js | 7 ++- .../tests.js | 7 ++- .../tests.js | 7 ++- .../multiple-topics-single-function/tests.js | 7 ++- .../single-topic-multiple-functions/tests.js | 7 ++- .../sns/single-topic-single-function/tests.js | 7 ++- .../general/custom-plugins/tests.js | 7 ++- .../general/local-plugins/tests.js | 7 ++- tests/integration/simple-integration-test.js | 52 +++++++++--------- tests/setupTests.js | 2 + 26 files changed, 259 insertions(+), 275 deletions(-) create mode 100644 tests/setupTests.js diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index dd6843d3b..92cdc4843 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -22,7 +21,7 @@ let stackName; let endpoint; let apiKey; -test.before('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { +beforeAll('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -39,8 +38,9 @@ test.before('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () = Utils.deployService(); }); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -49,34 +49,35 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test.before('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); +beforeAll( + 'should expose the API key(s) with its values when running the info command', + () => { + const info = execSync(`${Utils.serverlessExec} info`); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); + const stringifiedOutput = (new Buffer(info, 'base64').toString()); - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - expect(apiKey.length).to.be.above(0); -}); - -test('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) + expect(apiKey.length).to.be.above(0); + } ); -test('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) +it('should reject a request with an invalid API Key', () => fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) ); -test.after(() => { +it('should succeed if correct API key is given', () => fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) +); + +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js index 1ee75cebf..4f5da273f 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,13 +15,14 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpointBase; -test.before('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { +beforeAll('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -30,8 +30,9 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test.before('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) +beforeAll( + 'should setup CORS support with simple string config', + () => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) .then((response) => { const headers = response.headers; @@ -42,18 +43,17 @@ test.before('should setup CORS support with simple string config', () => }) ); -test('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with complex object config', () => fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js index 80319f8b3..b6cff121e 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,13 +15,17 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -test.before('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', () => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +beforeAll( + 'AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', + () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + } +); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -31,30 +34,27 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests without authorization', () => fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -test('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests with wrong authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -test('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) +it('should authorize requests with correct authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js index 53729c98f..08deae6d2 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,7 +15,7 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -test.before(() => { +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); return CF.describeStacksPromised({ StackName: stackName }) @@ -28,7 +27,7 @@ test.before(() => { }); }); -test('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'POST' }) @@ -36,7 +35,7 @@ test('a "without-slash" path should expose an accessible POST HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint) @@ -44,7 +43,7 @@ test('a "without-slash" path should expose an accessible GET HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'PUT' }) @@ -52,7 +51,7 @@ test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -60,7 +59,7 @@ test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'POST' }) @@ -68,7 +67,7 @@ test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () = .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint) @@ -76,7 +75,7 @@ test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'PUT' }) @@ -84,7 +83,7 @@ test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -92,7 +91,7 @@ test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible POST HTTP endpoint', () => { +it('a "/" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'POST' }) @@ -100,7 +99,7 @@ test('a "/" path should expose an accessible POST HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible GET HTTP endpoint', () => { +it('a "/" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint) @@ -108,7 +107,7 @@ test('a "/" path should expose an accessible GET HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible PUT HTTP endpoint', () => { +it('a "/" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'PUT' }) @@ -116,7 +115,7 @@ test('a "/" path should expose an accessible PUT HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -124,6 +123,6 @@ test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index 9788a9c9b..4349594fa 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -22,7 +21,7 @@ let stackName; let endpoint; let apiKey; -test.before('AWS - API Gateway (Integration: Lambda): API keys test', () => { +beforeAll('AWS - API Gateway (Integration: Lambda): API keys test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -39,8 +38,9 @@ test.before('AWS - API Gateway (Integration: Lambda): API keys test', () => { Utils.deployService(); }); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -49,34 +49,35 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test.before('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); +beforeAll( + 'should expose the API key(s) with its values when running the info command', + () => { + const info = execSync(`${Utils.serverlessExec} info`); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); + const stringifiedOutput = (new Buffer(info, 'base64').toString()); - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - expect(apiKey.length).to.be.above(0); -}); - -test('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) + expect(apiKey.length).to.be.above(0); + } ); -test('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) +it('should reject a request with an invalid API Key', () => fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) ); -test.after(() => { +it('should succeed if correct API key is given', () => fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) +); + +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js index 0257fd9fa..9a00f5311 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,13 +15,14 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpointBase; -test.before('AWS - API Gateway (Integration: Lambda): CORS test', () => { +beforeAll('AWS - API Gateway (Integration: Lambda): CORS test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -30,30 +30,28 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with simple string config', () => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); -test('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with complex object config', () => fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js index b382c6d04..90592eec2 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,13 +15,17 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -test.before('AWS - API Gateway (Integration: Lambda): Custom authorizers test', () => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +beforeAll( + 'AWS - API Gateway (Integration: Lambda): Custom authorizers test', + () => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + } +); -test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) +beforeAll( + 'should expose the endpoint(s) in the CloudFormation Outputs', + () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -31,30 +34,27 @@ test.before('should expose the endpoint(s) in the CloudFormation Outputs', () => }) ); -test('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests without authorization', () => fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -test('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests with wrong authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -test('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) +it('should authorize requests with correct authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js index 608db9c3c..c0b32d62e 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const BbPromise = require('bluebird'); @@ -16,7 +15,7 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -test.before(() => { +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); @@ -29,7 +28,7 @@ test.before(() => { }); }); -test('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'POST' }) @@ -37,7 +36,7 @@ test('a "without-slash" path should expose an accessible POST HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint) @@ -45,7 +44,7 @@ test('a "without-slash" path should expose an accessible GET HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'PUT' }) @@ -53,7 +52,7 @@ test('a "without-slash" path should expose an accessible PUT HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}/without-slash`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -61,7 +60,7 @@ test('a "without-slash" path should expose an accessible DELETE HTTP endpoint', .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'POST' }) @@ -69,7 +68,7 @@ test('a "/with-slash" path should expose an accessible POST HTTP endpoint', () = .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint) @@ -77,7 +76,7 @@ test('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'PUT' }) @@ -85,7 +84,7 @@ test('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}/with-slash`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -93,7 +92,7 @@ test('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible POST HTTP endpoint', () => { +it('a "/" path should expose an accessible POST HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'POST' }) @@ -101,7 +100,7 @@ test('a "/" path should expose an accessible POST HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible GET HTTP endpoint', () => { +it('a "/" path should expose an accessible GET HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint) @@ -109,7 +108,7 @@ test('a "/" path should expose an accessible GET HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible PUT HTTP endpoint', () => { +it('a "/" path should expose an accessible PUT HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'PUT' }) @@ -117,7 +116,7 @@ test('a "/" path should expose an accessible PUT HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { +it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { const testEndpoint = `${endpoint}`; return fetch(testEndpoint, { method: 'DELETE' }) @@ -125,6 +124,6 @@ test('a "/" path should expose an accessible DELETE HTTP endpoint', () => { .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); }); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index 57ad53ef9..fa687b908 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const AWS = require('aws-sdk'); @@ -19,7 +18,7 @@ BbPromise.promisifyAll(S3, { suffix: 'Promised' }); let stackName; let s3BucketName; -test.before('AWS - General: Custom resources test', () => { +beforeAll('AWS - General: Custom resources test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of bucket which is created through custom resources with something unique @@ -36,22 +35,20 @@ test.before('AWS - General: Custom resources test', () => { Utils.deployService(); }); -test('should add the custom outputs to the Outputs section', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'MyCustomOutput' }).OutputValue) - .then((endpointOutput) => { - expect(endpointOutput).to.equal('SomeValue'); - }) +it('should add the custom outputs to the Outputs section', () => CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'MyCustomOutput' }).OutputValue) + .then((endpointOutput) => { + expect(endpointOutput).to.equal('SomeValue'); + }) ); -test('should create the custom resources (a S3 bucket)', () => - S3.listBucketsPromised() - .then((result) => !!_.find(result.Buckets, - { Name: s3BucketName })) - .then((found) => expect(found).to.equal(true)) +it('should create the custom resources (a S3 bucket)', () => S3.listBucketsPromised() + .then((result) => !!_.find(result.Buckets, + { Name: s3BucketName })) + .then((found) => expect(found).to.equal(true)) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/general/environment-variables/tests.js b/tests/integration/aws/general/environment-variables/tests.js index 3e1604969..892f8f001 100644 --- a/tests/integration/aws/general/environment-variables/tests.js +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -1,18 +1,17 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -test.before(() => { +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should expose environment variables', () => { +it('should expose environment variables', () => { const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); const result = JSON.parse(new Buffer(invoked, 'base64').toString()); @@ -27,6 +26,6 @@ test('should expose environment variables', () => { .to.be.equal('overwritten_by_function'); }); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/general/nested-handlers/tests.js b/tests/integration/aws/general/nested-handlers/tests.js index 83d5ba9c0..3b407fa11 100644 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ b/tests/integration/aws/general/nested-handlers/tests.js @@ -1,24 +1,23 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -test.before('AWS - General: Nested handlers test', () => { +beforeAll('AWS - General: Nested handlers test', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should invoke the nested handler function from AWS', () => { +it('should invoke the nested handler function from AWS', () => { const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); const result = JSON.parse(new Buffer(invoked, 'base64').toString()); expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); }); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/general/overwrite-resources/tests.js b/tests/integration/aws/general/overwrite-resources/tests.js index 309c62a32..5cd0be8e9 100644 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ b/tests/integration/aws/general/overwrite-resources/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const AWS = require('aws-sdk'); @@ -13,12 +12,12 @@ BbPromise.promisifyAll(Lambda, { suffix: 'Promised' }); let stackName; -test.before('AWS - General: Overwrite resources test', () => { +beforeAll('AWS - General: Overwrite resources test', () => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should overwrite timeout config for hello function', () => { +it('should overwrite timeout config for hello function', () => { const helloFunctionName = `${stackName}-hello`; return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) .then(data => { @@ -27,7 +26,7 @@ test('should overwrite timeout config for hello function', () => { }); }); -test('should NOT overwrite timeout config for world function', () => { +it('should NOT overwrite timeout config for world function', () => { const worldFunctionName = `${stackName}-world`; return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) .then(data => { @@ -36,6 +35,6 @@ test('should NOT overwrite timeout config for world function', () => { }); }); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index 28090b5f6..6888a3646 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; @@ -14,25 +13,25 @@ const Utils = require('../../../../utils/index'); let serviceName; let deploy; -test.before('AWS - General: Deployment with --noDeploy', () => { +beforeAll('AWS - General: Deployment with --noDeploy', () => { serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); }); -test('should deploy package with --noDeploy flag', () => { +it('should deploy package with --noDeploy flag', () => { const result = new Buffer(deploy, 'base64').toString(); const resultLines = result.split(EOL); expect(resultLines[1]).to.have.string('--noDeploy'); }); -test('should have create cloudformation files and functions zip', () => { +it('should have create cloudformation files and functions zip', () => { const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); expect(deployedFiles[2]).to.match(/test-[0-9]{6}-[0-9]{9}.zip/); }); -test('should not found stack from AWS', (done) => { +it('should not found stack from AWS', () => { CF.describeStackResources({ StackName: serviceName }, (error) => { expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); done(); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js index fa2a35f80..b0dc3cc63 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before(() => { +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger functions when object created or deleted in buckets', () => Utils +it('should trigger functions when object created or deleted in buckets', () => Utils .createAndRemoveInBucket(process.env.BUCKET_1) .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) .delay(60000) @@ -28,6 +27,6 @@ test('should trigger functions when object created or deleted in buckets', () => }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js index 6befa093a..b542658b1 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before(() => { +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger create/remove functions on object create / remove', () => Utils +it('should trigger create/remove functions on object create / remove', () => Utils .createAndRemoveInBucket(process.env.BUCKET_1) .delay(60000) .then(() => { @@ -24,6 +23,6 @@ test('should trigger create/remove functions on object create / remove', () => U }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js index 51e8ff2a1..cda4a0e8e 100644 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before(() => { +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when object created or deleted in bucket', () => Utils +it('should trigger function when object created or deleted in bucket', () => Utils .createAndRemoveInBucket(process.env.BUCKET_1) .delay(60000) .then(() => { @@ -22,6 +21,6 @@ test('should trigger function when object created or deleted in bucket', () => U }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js index 0e5b01352..ea9ef28b9 100644 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before(() => { +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when object created in bucket', () => Utils +it('should trigger function when object created in bucket', () => Utils .createAndRemoveInBucket(process.env.BUCKET_1) .delay(60000) .then(() => { @@ -20,6 +19,6 @@ test('should trigger function when object created in bucket', () => Utils }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js index 08091f27d..78118b938 100644 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js +++ b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js @@ -1,17 +1,16 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); const BbPromise = require('bluebird'); -test.before('AWS - Schedule: Multiple schedules with multiple functions', () => { +beforeAll('AWS - Schedule: Multiple schedules with multiple functions', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger functions every minute', () => BbPromise.resolve() +it('should trigger functions every minute', () => BbPromise.resolve() .delay(100000) .then(() => { const helloLogs = Utils.getFunctionLogs('hello'); @@ -24,6 +23,6 @@ test('should trigger functions every minute', () => BbPromise.resolve() }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js index 72b32d79e..eea8d35eb 100644 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js +++ b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before('AWS - SNS: Multiple topics with multiple functions', () => { +beforeAll('AWS - SNS: Multiple topics with multiple functions', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when new message is published', () => Utils +it('should trigger function when new message is published', () => Utils .publishSnsMessage(process.env.TOPIC_1, 'topic1') .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) .delay(60000) @@ -25,6 +24,6 @@ test('should trigger function when new message is published', () => Utils }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-single-function/tests.js b/tests/integration/aws/sns/multiple-topics-single-function/tests.js index 0c5269d26..e1fefbe28 100644 --- a/tests/integration/aws/sns/multiple-topics-single-function/tests.js +++ b/tests/integration/aws/sns/multiple-topics-single-function/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before('AWS - SNS: Multiple topics single function', () => { +beforeAll('AWS - SNS: Multiple topics single function', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when new message is published', () => Utils +it('should trigger function when new message is published', () => Utils .publishSnsMessage(process.env.TOPIC_1, 'topic1') .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) .delay(60000) @@ -22,6 +21,6 @@ test('should trigger function when new message is published', () => Utils }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js index 5e92d87c4..04d6a8e42 100644 --- a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js +++ b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before('AWS - SNS: Single topic with multiple functions', () => { +beforeAll('AWS - SNS: Single topic with multiple functions', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when new message is published', () => Utils +it('should trigger function when new message is published', () => Utils .publishSnsMessage(process.env.TOPIC_1, 'hello world') .delay(60000) .then(() => { @@ -24,6 +23,6 @@ test('should trigger function when new message is published', () => Utils }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/aws/sns/single-topic-single-function/tests.js b/tests/integration/aws/sns/single-topic-single-function/tests.js index 8e8690024..09ae586dd 100644 --- a/tests/integration/aws/sns/single-topic-single-function/tests.js +++ b/tests/integration/aws/sns/single-topic-single-function/tests.js @@ -1,16 +1,15 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -test.before('AWS - SNS: Single topic with single function', () => { +beforeAll('AWS - SNS: Single topic with single function', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -test('should trigger function when new message is published', () => Utils +it('should trigger function when new message is published', () => Utils .publishSnsMessage(process.env.TOPIC_1, 'hello world') .delay(60000) .then(() => { @@ -20,6 +19,6 @@ test('should trigger function when new message is published', () => Utils }) ); -test.after(() => { +afterAll(() => { Utils.removeService(); }); diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index af82ad69b..639c825d1 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -1,13 +1,12 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -test.before('General: Custom plugins test', () => { +beforeAll('General: Custom plugins test', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // cd into the plugins directory @@ -20,12 +19,12 @@ test.before('General: Custom plugins test', () => { execSync('cd ..'); }); -test.after(() => { +afterAll(() => { // unlink the npm package execSync('npm r serverless-plugin-greeter -g'); }); -test('should successfully run the greet command of the custom plugin', () => { +it('should successfully run the greet command of the custom plugin', () => { const pluginExecution = execSync(`${Utils.serverlessExec} greet`); // note: the result will return a newline at the end diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js index 06a17685c..ee13450e1 100644 --- a/tests/integration/general/local-plugins/tests.js +++ b/tests/integration/general/local-plugins/tests.js @@ -1,23 +1,22 @@ 'use strict'; -const test = require('ava'); const path = require('path'); const expect = require('chai').expect; const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -test.before('General: Local plugins test', () => { +beforeAll('General: Local plugins test', () => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); }); -test('should successfully run the one command', () => { +it('should successfully run the one command', () => { const pluginExecution = execSync(`${Utils.serverlessExec} one`); const result = new Buffer(pluginExecution, 'base64').toString(); expect(/plugin one ran successfully/g.test(result)).to.equal(true); }); -test('should successfully run the two command', () => { +it('should successfully run the two command', () => { const pluginExecution = execSync(`${Utils.serverlessExec} two`); const result = new Buffer(pluginExecution, 'base64').toString(); expect(/plugin two ran successfully/g.test(result)).to.equal(true); diff --git a/tests/integration/simple-integration-test.js b/tests/integration/simple-integration-test.js index b0ab127bf..187904f5e 100644 --- a/tests/integration/simple-integration-test.js +++ b/tests/integration/simple-integration-test.js @@ -1,6 +1,5 @@ 'use strict'; -const test = require('ava'); const expect = require('chai').expect; const path = require('path'); const fse = require('fs-extra'); @@ -25,7 +24,7 @@ const stackName = `${newServiceName}-dev`; const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -test.serial('should create service in tmp directory', () => { +it('should create service in tmp directory', () => { execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); @@ -35,14 +34,14 @@ test.serial('should create service in tmp directory', () => { .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); }); -test.serial('should deploy service to aws', () => { +it('should deploy service to aws', () => { execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); return CF.describeStacksPromised({ StackName: stackName }) .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); }); -test.serial('should invoke function from aws', () => { +it('should invoke function from aws', () => { const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); const result = JSON.parse(new Buffer(invoked, 'base64').toString()); // parse it once again because the body is stringified to be LAMBDA-PROXY ready @@ -50,7 +49,7 @@ test.serial('should invoke function from aws', () => { expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); }); -test.serial('should deploy updated service to aws', () => { +it('should deploy updated service to aws', () => { const newHandler = ` 'use strict'; @@ -64,33 +63,36 @@ test.serial('should deploy updated service to aws', () => { execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); }); -test.serial('should invoke updated function from aws', () => { +it('should invoke updated function from aws', () => { const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); const result = JSON.parse(new Buffer(invoked, 'base64').toString()); expect(result.message).to.be.equal('Service Update Succeeded'); }); -test.serial('should list existing deployments and roll back to first deployment', () => { - let timestamp; - const listDeploys = execSync(`${serverlessExec} deploy list`); - const output = listDeploys.toString(); - const match = output.match(new RegExp('Timestamp: (.+)')); - if (match) { - timestamp = match[1]; +it( + 'should list existing deployments and roll back to first deployment', + () => { + let timestamp; + const listDeploys = execSync(`${serverlessExec} deploy list`); + const output = listDeploys.toString(); + const match = output.match(new RegExp('Timestamp: (.+)')); + if (match) { + timestamp = match[1]; + } + // eslint-disable-next-line no-unused-expressions + expect(timestamp).to.not.undefined; + + execSync(`${serverlessExec} rollback -t ${timestamp}`); + + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + // parse it once again because the body is stringified to be LAMBDA-PROXY ready + const message = JSON.parse(result.body).message; + expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); } - // eslint-disable-next-line no-unused-expressions - expect(timestamp).to.not.undefined; +); - execSync(`${serverlessExec} rollback -t ${timestamp}`); - - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - // parse it once again because the body is stringified to be LAMBDA-PROXY ready - const message = JSON.parse(result.body).message; - expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); -}); - -test.serial('should remove service from aws', () => { +it('should remove service from aws', () => { execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); return CF.describeStacksPromised({ StackName: stackName }) diff --git a/tests/setupTests.js b/tests/setupTests.js new file mode 100644 index 000000000..d7292bedb --- /dev/null +++ b/tests/setupTests.js @@ -0,0 +1,2 @@ +// timeout is set to 5 minutes +jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; From e41c643ee1d7f667bb1551b1cbde8c45f31ccd7a Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 15:51:11 +0100 Subject: [PATCH 05/24] simplify finding the path --- tests/utils/index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/utils/index.js b/tests/utils/index.js index 0b02b9790..ac026fe12 100644 --- a/tests/utils/index.js +++ b/tests/utils/index.js @@ -8,12 +8,9 @@ const BbPromise = require('bluebird'); const fse = require('fs-extra'); const execSync = require('child_process').execSync; const AWS = require('aws-sdk'); -const Serverless = require('../../lib/Serverless'); - -const serverless = new Serverless(); -serverless.init(); -const serverlessExec = path.join(serverless.config.serverlessPath, '..', 'bin', 'serverless'); +const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); +// const getTmpDirPath = () => path.join(os.tmpdir(), 'tmpdirs-serverless', 'serverless', crypto.randomBytes(8).toString('hex')); From bdd161e35363a0715926c42085c4097785719ace Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 15:53:22 +0100 Subject: [PATCH 06/24] run complex integration test suite with jest --- package.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index df70086e5..0b3dd27a9 100644 --- a/package.json +++ b/package.json @@ -51,10 +51,14 @@ "lint": "eslint .", "docs": "node scripts/generate-readme.js", "simple-integration-test": "ava tests/integration/simple-integration-test.js", - "complex-integration-test": "ava -c 8 tests/integration/**/tests.js" + "complex-integration-test": "jest" + }, + "jest": { + "testPathDirs": ["/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys"], + "testRegex": "(\\.|/)(tests)\\.js$", + "setupTestFrameworkScriptFile": "/tests/setupTests.js" }, "devDependencies": { - "ava": "^0.16.0", "chai": "^3.5.0", "coveralls": "^2.11.12", "eslint": "^3.3.1", From a33f7f61e1e790fdeb61cd20bcf945303ed7c440 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 16:05:20 +0100 Subject: [PATCH 07/24] fix all beforeAll --- .../api-keys/tests.js | 26 ++++++------- .../integration-lambda-proxy/cors/tests.js | 15 +++---- .../custom-authorizers/tests.js | 19 +++++---- .../integration-lambda/api-keys/tests.js | 39 ++++++++++--------- .../integration-lambda/cors/tests.js | 8 ++-- .../custom-authorizers/tests.js | 17 ++++---- .../aws/general/custom-resources/tests.js | 3 +- .../aws/general/nested-handlers/tests.js | 3 +- .../aws/general/overwrite-resources/tests.js | 3 +- .../integration/aws/general/package/tests.js | 5 ++- .../tests.js | 3 +- .../tests.js | 3 +- .../multiple-topics-single-function/tests.js | 3 +- .../single-topic-multiple-functions/tests.js | 3 +- .../sns/single-topic-single-function/tests.js | 3 +- .../general/custom-plugins/tests.js | 3 +- .../general/local-plugins/tests.js | 3 +- 17 files changed, 83 insertions(+), 76 deletions(-) diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index 92cdc4843..f5b6ac1c4 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -21,7 +21,8 @@ let stackName; let endpoint; let apiKey; -beforeAll('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { +// AWS - API Gateway (Integration: Lambda Proxy): API keys test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -38,9 +39,8 @@ beforeAll('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => Utils.deployService(); }); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -49,19 +49,17 @@ beforeAll( }) ); -beforeAll( - 'should expose the API key(s) with its values when running the info command', - () => { - const info = execSync(`${Utils.serverlessExec} info`); +// should expose the API key(s) with its values when running the info command +beforeAll(() => { + const info = execSync(`${Utils.serverlessExec} info`); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); + const stringifiedOutput = (new Buffer(info, 'base64').toString()); - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - expect(apiKey.length).to.be.above(0); - } -); + expect(apiKey.length).to.be.above(0); +}); it('should reject a request with an invalid API Key', () => fetch(endpoint) .then((response) => { diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js index 4f5da273f..4f555a597 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js @@ -15,14 +15,15 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpointBase; -beforeAll('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { +// AWS - API Gateway (Integration: Lambda Proxy): CORS test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) + +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { @@ -30,9 +31,9 @@ beforeAll( }) ); -beforeAll( - 'should setup CORS support with simple string config', - () => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + +// should setup CORS support with simple string config +beforeAll(() => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) .then((response) => { const headers = response.headers; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js index b6cff121e..014a8e98f 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js @@ -15,17 +15,16 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -beforeAll( - 'AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', - () => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - } -); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) +// AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test' +beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); + + +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index 4349594fa..ecc9424a6 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -21,7 +21,8 @@ let stackName; let endpoint; let apiKey; -beforeAll('AWS - API Gateway (Integration: Lambda): API keys test', () => { +// AWS - API Gateway (Integration: Lambda): API keys test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -38,29 +39,29 @@ beforeAll('AWS - API Gateway (Integration: Lambda): API keys test', () => { Utils.deployService(); }); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) + +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) ); -beforeAll( - 'should expose the API key(s) with its values when running the info command', - () => { - const info = execSync(`${Utils.serverlessExec} info`); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); +// should expose the API key(s) with its values when running the info command +beforeAll(() => { + const info = execSync(`${Utils.serverlessExec} info`); - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + const stringifiedOutput = (new Buffer(info, 'base64').toString()); - expect(apiKey.length).to.be.above(0); - } + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + + expect(apiKey.length).to.be.above(0); +} ); it('should reject a request with an invalid API Key', () => fetch(endpoint) diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js index 9a00f5311..146d0732a 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js @@ -15,14 +15,14 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpointBase; -beforeAll('AWS - API Gateway (Integration: Lambda): CORS test', () => { +// AWS - API Gateway (Integration: Lambda): CORS test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js index 90592eec2..e9e29d4fa 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js @@ -15,17 +15,14 @@ BbPromise.promisifyAll(CF, { suffix: 'Promised' }); let stackName; let endpoint; -beforeAll( - 'AWS - API Gateway (Integration: Lambda): Custom authorizers test', - () => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - } -); +// AWS - API Gateway (Integration: Lambda): Custom authorizers test +beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); +}); -beforeAll( - 'should expose the endpoint(s) in the CloudFormation Outputs', - () => CF.describeStacksPromised({ StackName: stackName }) +// should expose the endpoint(s) in the CloudFormation Outputs +beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index fa687b908..9141c4031 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -18,7 +18,8 @@ BbPromise.promisifyAll(S3, { suffix: 'Promised' }); let stackName; let s3BucketName; -beforeAll('AWS - General: Custom resources test', () => { +// AWS - General: Custom resources test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of bucket which is created through custom resources with something unique diff --git a/tests/integration/aws/general/nested-handlers/tests.js b/tests/integration/aws/general/nested-handlers/tests.js index 3b407fa11..ba3ebd752 100644 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ b/tests/integration/aws/general/nested-handlers/tests.js @@ -6,7 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -beforeAll('AWS - General: Nested handlers test', () => { +// AWS - General: Nested handlers test +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/general/overwrite-resources/tests.js b/tests/integration/aws/general/overwrite-resources/tests.js index 5cd0be8e9..8da12de2e 100644 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ b/tests/integration/aws/general/overwrite-resources/tests.js @@ -12,7 +12,8 @@ BbPromise.promisifyAll(Lambda, { suffix: 'Promised' }); let stackName; -beforeAll('AWS - General: Overwrite resources test', () => { +// AWS - General: Overwrite resources test +beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index 6888a3646..7d1f8e794 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -13,7 +13,8 @@ const Utils = require('../../../../utils/index'); let serviceName; let deploy; -beforeAll('AWS - General: Deployment with --noDeploy', () => { +// AWS - General: Deployment with --noDeploy +beforeAll(() => { serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); }); @@ -31,7 +32,7 @@ it('should have create cloudformation files and functions zip', () => { expect(deployedFiles[2]).to.match(/test-[0-9]{6}-[0-9]{9}.zip/); }); -it('should not found stack from AWS', () => { +it('should not found stack from AWS', (done) => { CF.describeStackResources({ StackName: serviceName }, (error) => { expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); done(); diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js index 78118b938..5286d300d 100644 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js +++ b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js @@ -5,7 +5,8 @@ const expect = require('chai').expect; const Utils = require('../../../../utils/index'); const BbPromise = require('bluebird'); -beforeAll('AWS - Schedule: Multiple schedules with multiple functions', () => { +// AWS - Schedule: Multiple schedules with multiple functions +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js index eea8d35eb..e84995ad6 100644 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js +++ b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js @@ -4,7 +4,8 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll('AWS - SNS: Multiple topics with multiple functions', () => { +// AWS - SNS: Multiple topics with multiple functions +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/sns/multiple-topics-single-function/tests.js b/tests/integration/aws/sns/multiple-topics-single-function/tests.js index e1fefbe28..11884b20e 100644 --- a/tests/integration/aws/sns/multiple-topics-single-function/tests.js +++ b/tests/integration/aws/sns/multiple-topics-single-function/tests.js @@ -4,7 +4,8 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll('AWS - SNS: Multiple topics single function', () => { +// AWS - SNS: Multiple topics single function +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js index 04d6a8e42..e4cd2c762 100644 --- a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js +++ b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js @@ -4,7 +4,8 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll('AWS - SNS: Single topic with multiple functions', () => { +// AWS - SNS: Single topic with multiple functions +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/aws/sns/single-topic-single-function/tests.js b/tests/integration/aws/sns/single-topic-single-function/tests.js index 09ae586dd..3c57d7a7b 100644 --- a/tests/integration/aws/sns/single-topic-single-function/tests.js +++ b/tests/integration/aws/sns/single-topic-single-function/tests.js @@ -4,7 +4,8 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll('AWS - SNS: Single topic with single function', () => { +// AWS - SNS: Single topic with single function +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index 639c825d1..b3ef47f00 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -6,7 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -beforeAll('General: Custom plugins test', () => { +// General: Custom plugins test +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // cd into the plugins directory diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js index ee13450e1..35fe66994 100644 --- a/tests/integration/general/local-plugins/tests.js +++ b/tests/integration/general/local-plugins/tests.js @@ -6,7 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -beforeAll('General: Local plugins test', () => { +// General: Local plugins test +beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); }); From 6297068f0875243c7b650312db20424f83dfcf42 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 16:24:04 +0100 Subject: [PATCH 08/24] make sure the simple test suite works wih jest --- package.json | 5 ++--- .../simple-integration-test.js => simple-suite/tests.js} | 0 2 files changed, 2 insertions(+), 3 deletions(-) rename tests/{integration/simple-integration-test.js => simple-suite/tests.js} (100%) diff --git a/package.json b/package.json index 0b3dd27a9..440767788 100644 --- a/package.json +++ b/package.json @@ -50,11 +50,10 @@ "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", "docs": "node scripts/generate-readme.js", - "simple-integration-test": "ava tests/integration/simple-integration-test.js", - "complex-integration-test": "jest" + "simple-integration-test": "jest simple-suite", + "complex-integration-test": "jest integration" }, "jest": { - "testPathDirs": ["/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys"], "testRegex": "(\\.|/)(tests)\\.js$", "setupTestFrameworkScriptFile": "/tests/setupTests.js" }, diff --git a/tests/integration/simple-integration-test.js b/tests/simple-suite/tests.js similarity index 100% rename from tests/integration/simple-integration-test.js rename to tests/simple-suite/tests.js From d32a9bade4fe02360330fff12cf655f2cb5489d6 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 16:26:13 +0100 Subject: [PATCH 09/24] temporarily run the test suite on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 28a51328e..2dceead1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: - if [[ -z "$INTEGRATION_TEST" && -z "$DISABLE_TESTS" ]]; then npm test; fi - if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" && -z "$INTEGRATION_TEST" ]]; then npm run lint; fi - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "simple" ]]; then npm run simple-integration-test; fi - - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run complex-integration-test; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run complex-integration-test; fi after_success: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage From 53de3b9a6394530fbb25bfa96fa858a3743c34b3 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 16:48:10 +0100 Subject: [PATCH 10/24] add max workers --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 440767788..c88ccacc4 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", "docs": "node scripts/generate-readme.js", - "simple-integration-test": "jest simple-suite", - "complex-integration-test": "jest integration" + "simple-integration-test": "jest --maxWorkers=8 simple-suite", + "complex-integration-test": "jest --maxWorkers=8 integration" }, "jest": { "testRegex": "(\\.|/)(tests)\\.js$", From 6f9883da8a8d5c29520b89ca93595d63494682d7 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 17:03:53 +0100 Subject: [PATCH 11/24] also run travis on push --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2dceead1f..448d313b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: - if [[ -z "$INTEGRATION_TEST" && -z "$DISABLE_TESTS" ]]; then npm test; fi - if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" && -z "$INTEGRATION_TEST" ]]; then npm run lint; fi - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "simple" ]]; then npm run simple-integration-test; fi - - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run complex-integration-test; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" ]]; then npm run complex-integration-test; fi after_success: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage From 55bec543b4b031281b93684ce9c753d4b1afc521 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 17:32:02 +0100 Subject: [PATCH 12/24] fix package test --- tests/integration/aws/general/package/tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index 7d1f8e794..989e9980b 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -29,7 +29,8 @@ it('should have create cloudformation files and functions zip', () => { const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); - expect(deployedFiles[2]).to.match(/test-[0-9]{6}-[0-9]{9}.zip/); + // Note: noticed the seconds section can vary a lot + expect(deployedFiles[2]).to.match(/test-[0-9]{1,}-[0-9]{9}.zip/); }); it('should not found stack from AWS', (done) => { From e896755b541cd02c7a8edf461472d183642970d2 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 18:39:37 +0100 Subject: [PATCH 13/24] reduce max workers --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c88ccacc4..ca8ca4757 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", "docs": "node scripts/generate-readme.js", - "simple-integration-test": "jest --maxWorkers=8 simple-suite", - "complex-integration-test": "jest --maxWorkers=8 integration" + "simple-integration-test": "jest --maxWorkers=5 simple-suite", + "complex-integration-test": "jest --maxWorkers=5 single-event-single-function" }, "jest": { "testRegex": "(\\.|/)(tests)\\.js$", From 1b43983dc8c2dc7a7f10c8d01b5627c96cf2c548 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 22:49:28 +0100 Subject: [PATCH 14/24] fix linting issues --- .eslintrc.js | 3 +- .../api-keys/tests.js | 15 ++++---- .../integration-lambda-proxy/cors/tests.js | 17 +++++----- .../custom-authorizers/tests.js | 24 +++++++------ .../integration-lambda/api-keys/tests.js | 15 ++++---- .../integration-lambda/cors/tests.js | 34 ++++++++++--------- .../custom-authorizers/tests.js | 24 +++++++------ .../aws/general/custom-resources/tests.js | 13 +++---- tests/setupTests.js | 1 + 9 files changed, 79 insertions(+), 67 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 80d525476..84d634b03 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,6 +11,7 @@ module.exports = { "import/no-extraneous-dependencies" : "off" }, "env": { - "mocha": true + "mocha": true, + "jest": true } }; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index f5b6ac1c4..fc8bf40c3 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -67,13 +67,14 @@ it('should reject a request with an invalid API Key', () => fetch(endpoint) }) ); -it('should succeed if correct API key is given', () => fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) +it('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) ); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js index 4f555a597..19cc08983 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js @@ -44,15 +44,16 @@ beforeAll(() => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) }) ); -it('should setup CORS support with complex object config', () => fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js index 014a8e98f..d12abef07 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js @@ -39,19 +39,21 @@ it('should reject requests without authorization', () => fetch(endpoint) }) ); -it('should reject requests with wrong authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -it('should authorize requests with correct authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) +it('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) ); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index ecc9424a6..6fcc2ffd6 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -70,13 +70,14 @@ it('should reject a request with an invalid API Key', () => fetch(endpoint) }) ); -it('should succeed if correct API key is given', () => fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) +it('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) ); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js index 146d0732a..78f62da4e 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js @@ -30,26 +30,28 @@ beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) }) ); -it('should setup CORS support with simple string config', () => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with simple string config', () => + fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); -it('should setup CORS support with complex object config', () => fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; +it('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) ); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js index e9e29d4fa..40e2cf0b5 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js @@ -37,19 +37,21 @@ it('should reject requests without authorization', () => fetch(endpoint) }) ); -it('should reject requests with wrong authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) +it('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) ); -it('should authorize requests with correct authorization', () => fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) +it('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) ); afterAll(() => { diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index 9141c4031..7c802df83 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -36,12 +36,13 @@ beforeAll(() => { Utils.deployService(); }); -it('should add the custom outputs to the Outputs section', () => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'MyCustomOutput' }).OutputValue) - .then((endpointOutput) => { - expect(endpointOutput).to.equal('SomeValue'); - }) +it('should add the custom outputs to the Outputs section', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'MyCustomOutput' }).OutputValue) + .then((endpointOutput) => { + expect(endpointOutput).to.equal('SomeValue'); + }) ); it('should create the custom resources (a S3 bucket)', () => S3.listBucketsPromised() diff --git a/tests/setupTests.js b/tests/setupTests.js index d7292bedb..4da8b0798 100644 --- a/tests/setupTests.js +++ b/tests/setupTests.js @@ -1,2 +1,3 @@ // timeout is set to 5 minutes +// eslint-disable-next-line no-undef jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; From a0bf079b2208cb8734521a15a153ec2826a57e20 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 22:58:17 +0100 Subject: [PATCH 15/24] run full integration test suite --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ca8ca4757..9d97a96fc 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", "docs": "node scripts/generate-readme.js", - "simple-integration-test": "jest --maxWorkers=5 simple-suite", - "complex-integration-test": "jest --maxWorkers=5 single-event-single-function" + "simple-integration-test": "jest --maxWorkers=6 simple-suite", + "complex-integration-test": "jest --maxWorkers=6 integration" }, "jest": { "testRegex": "(\\.|/)(tests)\\.js$", From 5c98851a194f0343b99bf7ecd9f77c17d5c9353f Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 23:04:53 +0100 Subject: [PATCH 16/24] reduce parallel workers --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9d97a96fc..214315ac4 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive", "lint": "eslint .", "docs": "node scripts/generate-readme.js", - "simple-integration-test": "jest --maxWorkers=6 simple-suite", - "complex-integration-test": "jest --maxWorkers=6 integration" + "simple-integration-test": "jest --maxWorkers=5 simple-suite", + "complex-integration-test": "jest --maxWorkers=5 integration" }, "jest": { "testRegex": "(\\.|/)(tests)\\.js$", From f53596884a254bf87bb80d4736e7061b589023c1 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 23:17:06 +0100 Subject: [PATCH 17/24] refactor test --- .../api-keys/tests.js | 105 +++++++++--------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index fc8bf40c3..81038533a 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -17,66 +17,67 @@ const APIG = new AWS.APIGateway({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); -let stackName; -let endpoint; -let apiKey; +describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { + let stackName; + let endpoint; + let apiKey; -// AWS - API Gateway (Integration: Lambda Proxy): API keys test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + // replace name of the API key with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - const apiKeyName = crypto.randomBytes(8).toString('hex'); + const apiKeyName = crypto.randomBytes(8).toString('hex'); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - Utils.deployService(); -}); + Utils.deployService(); + }); -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + // TODO set an expect here + }) + ); + + it('should expose the API key(s) with its values when running the info command', () => { + const info = execSync(`${Utils.serverlessExec} info`); + + const stringifiedOutput = (new Buffer(info, 'base64').toString()); + + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + + expect(apiKey.length).to.be.above(0); + }); + + it('should reject a request with an invalid API Key', () => fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); }) -); + ); -// should expose the API key(s) with its values when running the info command -beforeAll(() => { - const info = execSync(`${Utils.serverlessExec} info`); + it('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) + ); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - - expect(apiKey.length).to.be.above(0); -}); - -it('should reject a request with an invalid API Key', () => fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) -); - -it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) -); - -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); From 9c54957e8a982ba30d55f45774f2fe051691cb60 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 23:45:43 +0100 Subject: [PATCH 18/24] wrap tests in describe blocks --- .../api-keys/tests.js | 9 +- .../integration-lambda-proxy/cors/tests.js | 89 ++++--- .../custom-authorizers/tests.js | 89 +++---- .../simple-api/tests.js | 226 +++++++++--------- .../integration-lambda/api-keys/tests.js | 110 +++++---- .../integration-lambda/cors/tests.js | 87 +++---- .../custom-authorizers/tests.js | 88 +++---- .../integration-lambda/simple-api/tests.js | 226 +++++++++--------- .../aws/general/custom-resources/tests.js | 65 ++--- .../general/environment-variables/tests.js | 46 ++-- .../aws/general/nested-handlers/tests.js | 25 +- .../aws/general/overwrite-resources/tests.js | 49 ++-- .../integration/aws/general/package/tests.js | 47 ++-- .../tests.js | 52 ++-- .../tests.js | 44 ++-- .../tests.js | 40 ++-- .../tests.js | 32 +-- .../tests.js | 43 ++-- .../tests.js | 47 ++-- .../multiple-topics-single-function/tests.js | 37 +-- .../single-topic-multiple-functions/tests.js | 45 ++-- .../sns/single-topic-single-function/tests.js | 33 +-- .../general/custom-plugins/tests.js | 47 ++-- .../general/local-plugins/tests.js | 27 ++- tests/simple-suite/tests.js | 136 +++++------ 25 files changed, 884 insertions(+), 855 deletions(-) diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index 81038533a..58a3e8f0f 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -61,10 +61,11 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { expect(apiKey.length).to.be.above(0); }); - it('should reject a request with an invalid API Key', () => fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) + it('should reject a request with an invalid API Key', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) ); it('should succeed if correct API key is given', () => diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js index 19cc08983..21b70d2d8 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js @@ -12,50 +12,49 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpointBase; +describe('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { + let stackName; + let endpointBase; -// AWS - API Gateway (Integration: Lambda Proxy): CORS test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - - -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) -); - - -// should setup CORS support with simple string config -beforeAll(() => fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) -); - -it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) -); - -afterAll(() => { - Utils.removeService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + }) + ); + + it('should setup CORS support with simple string config', () => + fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) + ); + + it('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js index d12abef07..ffe2ec57b 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js @@ -12,50 +12,51 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpoint; +describe('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', () => { + let stackName; + let endpoint; -// AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test' -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - - -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) -); - -it('should reject requests without authorization', () => fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) -); - -it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) -); - -it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) -); - -afterAll(() => { - Utils.removeService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) + ); + + it('should reject requests without authorization', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) + ); + + it('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) + ); + + it('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js index 08deae6d2..a3fae6be1 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js @@ -12,117 +12,119 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpoint; +describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', () => { + let stackName; + let endpoint; -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - return CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }); -}); - -it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -afterAll(() => { - Utils.removeService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + return CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}`; + }); + }); + + it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index 6fcc2ffd6..c1093bea6 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -21,65 +21,63 @@ let stackName; let endpoint; let apiKey; -// AWS - API Gateway (Integration: Lambda): API keys test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); +describe('AWS - API Gateway (Integration: Lambda): API keys test', () => { + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + // replace name of the API key with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - const apiKeyName = crypto.randomBytes(8).toString('hex'); + const apiKeyName = crypto.randomBytes(8).toString('hex'); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - Utils.deployService(); -}); - - -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) -); - - -// should expose the API key(s) with its values when running the info command -beforeAll(() => { - const info = execSync(`${Utils.serverlessExec} info`); - - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - - expect(apiKey.length).to.be.above(0); -} -); - -it('should reject a request with an invalid API Key', () => fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) -); - -it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) -); - -afterAll(() => { - Utils.removeService(); + Utils.deployService(); + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) + ); + + it('should expose the API key(s) with its values when running the info command', () => { + const info = execSync(`${Utils.serverlessExec} info`); + + const stringifiedOutput = (new Buffer(info, 'base64').toString()); + + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + + expect(apiKey.length).to.be.above(0); + }); + + it('should reject a request with an invalid API Key', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(403); + }) + ); + + it('should succeed if correct API key is given', () => + fetch(endpoint, { headers: { 'x-api-key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway!'); + expect(json.event.identity.apiKey).to.equal(apiKey); + expect(json.event.headers['x-api-key']).to.equal(apiKey); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js index 78f62da4e..8c52f7298 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js @@ -12,48 +12,49 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpointBase; +describe('AWS - API Gateway (Integration: Lambda): CORS test', () => { + let stackName; + let endpointBase; -// AWS - API Gateway (Integration: Lambda): CORS test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) -); - -it('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) -); - -it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) -); - -afterAll(() => { - Utils.removeService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + }) + ); + + it('should setup CORS support with simple string config', () => + fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) + ); + + it('should setup CORS support with complex object config', () => + fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + + expect(headers.get('access-control-allow-headers')) + .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js index 40e2cf0b5..33a4f9706 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js @@ -12,48 +12,50 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpoint; +describe('AWS - API Gateway (Integration: Lambda): Custom authorizers test', () => { + let stackName; + let endpoint; -// AWS - API Gateway (Integration: Lambda): Custom authorizers test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -// should expose the endpoint(s) in the CloudFormation Outputs -beforeAll(() => CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) -); - -it('should reject requests without authorization', () => fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) -); - -it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) -); - -it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) -); - -afterAll(() => { - Utils.removeService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}/hello`; + }) + ); + + it('should reject requests without authorization', () => + fetch(endpoint) + .then((response) => { + expect(response.status).to.equal(401); + }) + ); + + it('should reject requests with wrong authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }) + ); + + it('should authorize requests with correct authorization', () => + fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Successfully authorized!'); + expect(json.event.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js index c0b32d62e..56b7ae558 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js @@ -12,118 +12,120 @@ const Utils = require('../../../../../utils/index'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -let stackName; -let endpoint; +describe('AWS - API Gateway (Integration: Lambda): Simple API test', () => { + let stackName; + let endpoint; -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); - return CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }); -}); - -it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); -}); - -afterAll(() => { - Utils.removeService(); + return CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}`; + }); + }); + + it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index 7c802df83..f91b377f7 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -15,42 +15,43 @@ const S3 = new AWS.S3({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(S3, { suffix: 'Promised' }); -let stackName; -let s3BucketName; +describe('AWS - General: Custom resources test', () => { + let stackName; + let s3BucketName; -// AWS - General: Custom resources test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - // replace name of bucket which is created through custom resources with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); + // replace name of bucket which is created through custom resources with something unique + const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); + let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - s3BucketName = crypto.randomBytes(8).toString('hex'); + s3BucketName = crypto.randomBytes(8).toString('hex'); - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, s3BucketName); + serverlessYmlFileContent = serverlessYmlFileContent + .replace(/WillBeReplacedBeforeDeployment/, s3BucketName); - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); + fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - Utils.deployService(); -}); - -it('should add the custom outputs to the Outputs section', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'MyCustomOutput' }).OutputValue) - .then((endpointOutput) => { - expect(endpointOutput).to.equal('SomeValue'); - }) -); - -it('should create the custom resources (a S3 bucket)', () => S3.listBucketsPromised() - .then((result) => !!_.find(result.Buckets, - { Name: s3BucketName })) - .then((found) => expect(found).to.equal(true)) -); - -afterAll(() => { - Utils.removeService(); + Utils.deployService(); + }); + + it('should add the custom outputs to the Outputs section', () => + CF.describeStacksPromised({ StackName: stackName }) + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'MyCustomOutput' }).OutputValue) + .then((endpointOutput) => { + expect(endpointOutput).to.equal('SomeValue'); + }) + ); + + it('should create the custom resources (a S3 bucket)', () => S3.listBucketsPromised() + .then((result) => !!_.find(result.Buckets, + { Name: s3BucketName })) + .then((found) => expect(found).to.equal(true)) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/general/environment-variables/tests.js b/tests/integration/aws/general/environment-variables/tests.js index 892f8f001..af1dcb368 100644 --- a/tests/integration/aws/general/environment-variables/tests.js +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -6,26 +6,28 @@ const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should expose environment variables', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - - expect(result.environment_variables.provider_level_variable_1) - .to.be.equal('provider_level_1'); - expect(result.environment_variables.function_level_variable_1) - .to.be.equal('function_level_1'); - expect(result.environment_variables.function_level_variable_2) - .to.be.equal('function_level_2'); - expect(result.environment_variables.provider_level_variable_2) - .to.be.equal('overwritten_by_function'); -}); - -afterAll(() => { - Utils.removeService(); +describe('AWS - General: Environment variables test', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose environment variables', () => { + const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); + + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + + expect(result.environment_variables.provider_level_variable_1) + .to.be.equal('provider_level_1'); + expect(result.environment_variables.function_level_variable_1) + .to.be.equal('function_level_1'); + expect(result.environment_variables.function_level_variable_2) + .to.be.equal('function_level_2'); + expect(result.environment_variables.provider_level_variable_2) + .to.be.equal('overwritten_by_function'); + }); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/general/nested-handlers/tests.js b/tests/integration/aws/general/nested-handlers/tests.js index ba3ebd752..ed4083d95 100644 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ b/tests/integration/aws/general/nested-handlers/tests.js @@ -6,19 +6,20 @@ const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -// AWS - General: Nested handlers test -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +describe('AWS - General: Nested handlers test', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); -it('should invoke the nested handler function from AWS', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); + it('should invoke the nested handler function from AWS', () => { + const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); -}); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); + }); -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/general/overwrite-resources/tests.js b/tests/integration/aws/general/overwrite-resources/tests.js index 8da12de2e..06e615005 100644 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ b/tests/integration/aws/general/overwrite-resources/tests.js @@ -10,32 +10,33 @@ const Utils = require('../../../../utils/index'); const Lambda = new AWS.Lambda({ region: 'us-east-1' }); BbPromise.promisifyAll(Lambda, { suffix: 'Promised' }); -let stackName; +describe('AWS - General: Overwrite resources test', () => { + let stackName; -// AWS - General: Overwrite resources test -beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); + beforeAll(() => { + stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); -it('should overwrite timeout config for hello function', () => { - const helloFunctionName = `${stackName}-hello`; - return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(10); - }); -}); + it('should overwrite timeout config for hello function', () => { + const helloFunctionName = `${stackName}-hello`; + return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) + .then(data => { + const timeout = data.Configuration.Timeout; + expect(timeout).to.equal(10); + }); + }); -it('should NOT overwrite timeout config for world function', () => { - const worldFunctionName = `${stackName}-world`; - return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(6); - }); -}); + it('should NOT overwrite timeout config for world function', () => { + const worldFunctionName = `${stackName}-world`; + return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) + .then(data => { + const timeout = data.Configuration.Timeout; + expect(timeout).to.equal(6); + }); + }); -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index 989e9980b..a3d0a8f9f 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -10,32 +10,33 @@ const fs = require('fs'); const CF = new AWS.CloudFormation({ region: 'us-east-1' }); const Utils = require('../../../../utils/index'); -let serviceName; -let deploy; +describe('AWS - General: Deployment with --noDeploy', () => { + let serviceName; + let deploy; -// AWS - General: Deployment with --noDeploy -beforeAll(() => { - serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); -}); + beforeAll(() => { + serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); + }); -it('should deploy package with --noDeploy flag', () => { - const result = new Buffer(deploy, 'base64').toString(); - const resultLines = result.split(EOL); - expect(resultLines[1]).to.have.string('--noDeploy'); -}); + it('should deploy package with --noDeploy flag', () => { + const result = new Buffer(deploy, 'base64').toString(); + const resultLines = result.split(EOL); + expect(resultLines[1]).to.have.string('--noDeploy'); + }); -it('should have create cloudformation files and functions zip', () => { - const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); - expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); - expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); - // Note: noticed the seconds section can vary a lot - expect(deployedFiles[2]).to.match(/test-[0-9]{1,}-[0-9]{9}.zip/); -}); + it('should have create cloudformation files and functions zip', () => { + const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); + expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); + expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); + // Note: noticed the seconds section can vary a lot + expect(deployedFiles[2]).to.match(/test-[0-9]{1,}-[0-9]{9}.zip/); + }); -it('should not found stack from AWS', (done) => { - CF.describeStackResources({ StackName: serviceName }, (error) => { - expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); - done(); + it('should not found stack from AWS', (done) => { + CF.describeStackResources({ StackName: serviceName }, (error) => { + expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); + done(); + }); }); }); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js index b0dc3cc63..1b667c068 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js @@ -4,29 +4,31 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger functions when object created or deleted in buckets', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:s3/g.test(helloLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(helloLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(helloLogs)).to.equal(true); - - expect(/aws:s3/g.test(worldLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(worldLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(worldLogs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - S3: Multiple events in multiple functions with multiple buckets', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger functions when object created or deleted in buckets', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:s3/g.test(helloLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(helloLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(helloLogs)).to.equal(true); + + expect(/aws:s3/g.test(worldLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(worldLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(worldLogs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js index b542658b1..03a0aab68 100644 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js @@ -4,25 +4,27 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger create/remove functions on object create / remove', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const createLogs = Utils.getFunctionLogs('create'); - const removeLogs = Utils.getFunctionLogs('remove'); - - expect(/aws:s3/g.test(createLogs)).to.equal(true); - expect(/aws:s3/g.test(removeLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(createLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(removeLogs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - S3: Multiple events in multiple functions with a single bucket', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger create/remove functions on object create / remove', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const createLogs = Utils.getFunctionLogs('create'); + const removeLogs = Utils.getFunctionLogs('remove'); + + expect(/aws:s3/g.test(createLogs)).to.equal(true); + expect(/aws:s3/g.test(removeLogs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(createLogs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(removeLogs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js index cda4a0e8e..e7db28191 100644 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js @@ -4,23 +4,25 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger function when object created or deleted in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(logs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - S3: Multiple events in a single function with a single bucket', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger function when object created or deleted in bucket', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + + expect(/aws:s3/g.test(logs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); + expect(/ObjectRemoved:Delete/g.test(logs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js index ea9ef28b9..7c09075a2 100644 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js +++ b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js @@ -4,21 +4,23 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +describe('AWS - S3: Single event in a single function with a single bucket', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); -it('should trigger function when object created in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - }) -); + it('should trigger function when object created in bucket', () => Utils + .createAndRemoveInBucket(process.env.BUCKET_1) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:s3/g.test(logs)).to.equal(true); + expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); + }) + ); -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js index 5286d300d..51ae9cb57 100644 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js +++ b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js @@ -5,25 +5,26 @@ const expect = require('chai').expect; const Utils = require('../../../../utils/index'); const BbPromise = require('bluebird'); -// AWS - Schedule: Multiple schedules with multiple functions -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger functions every minute', () => BbPromise.resolve() - .delay(100000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/Scheduled Event/g.test(helloLogs)).to.equal(true); - expect(/aws\.events/g.test(helloLogs)).to.equal(true); - expect(/Scheduled Event/g.test(worldLogs)).to.equal(true); - expect(/aws\.events/g.test(worldLogs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - Schedule: Multiple schedules with multiple functions', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger functions every minute', () => BbPromise.resolve() + .delay(100000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/Scheduled Event/g.test(helloLogs)).to.equal(true); + expect(/aws\.events/g.test(helloLogs)).to.equal(true); + expect(/Scheduled Event/g.test(worldLogs)).to.equal(true); + expect(/aws\.events/g.test(worldLogs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js index e84995ad6..df3420898 100644 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js +++ b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js @@ -4,27 +4,28 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -// AWS - SNS: Multiple topics with multiple functions -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/topic1/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/topic2/g.test(worldLogs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - SNS: Multiple topics with multiple functions', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'topic1') + .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:sns/g.test(helloLogs)).to.equal(true); + expect(/topic1/g.test(helloLogs)).to.equal(true); + expect(/aws:sns/g.test(worldLogs)).to.equal(true); + expect(/topic2/g.test(worldLogs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/sns/multiple-topics-single-function/tests.js b/tests/integration/aws/sns/multiple-topics-single-function/tests.js index 11884b20e..6c6122cce 100644 --- a/tests/integration/aws/sns/multiple-topics-single-function/tests.js +++ b/tests/integration/aws/sns/multiple-topics-single-function/tests.js @@ -4,24 +4,25 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -// AWS - SNS: Multiple topics single function -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +describe('AWS - SNS: Multiple topics single function', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); -it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/topic1/g.test(logs)).to.equal(true); - expect(/topic2/g.test(logs)).to.equal(true); - }) -); + it('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'topic1') + .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:sns/g.test(logs)).to.equal(true); + expect(/topic1/g.test(logs)).to.equal(true); + expect(/topic2/g.test(logs)).to.equal(true); + }) + ); -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js index e4cd2c762..03b4977ca 100644 --- a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js +++ b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js @@ -4,26 +4,27 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -// AWS - SNS: Single topic with multiple functions -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); - -it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/hello world/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/hello world/g.test(worldLogs)).to.equal(true); - }) -); - -afterAll(() => { - Utils.removeService(); +describe('AWS - SNS: Single topic with multiple functions', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'hello world') + .delay(60000) + .then(() => { + const helloLogs = Utils.getFunctionLogs('hello'); + const worldLogs = Utils.getFunctionLogs('world'); + + expect(/aws:sns/g.test(helloLogs)).to.equal(true); + expect(/hello world/g.test(helloLogs)).to.equal(true); + expect(/aws:sns/g.test(worldLogs)).to.equal(true); + expect(/hello world/g.test(worldLogs)).to.equal(true); + }) + ); + + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/aws/sns/single-topic-single-function/tests.js b/tests/integration/aws/sns/single-topic-single-function/tests.js index 3c57d7a7b..fcf655144 100644 --- a/tests/integration/aws/sns/single-topic-single-function/tests.js +++ b/tests/integration/aws/sns/single-topic-single-function/tests.js @@ -4,22 +4,23 @@ const path = require('path'); const expect = require('chai').expect; const Utils = require('../../../../utils/index'); -// AWS - SNS: Single topic with single function -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); -}); +describe('AWS - SNS: Single topic with single function', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); -it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/hello world/g.test(logs)).to.equal(true); - }) -); + it('should trigger function when new message is published', () => Utils + .publishSnsMessage(process.env.TOPIC_1, 'hello world') + .delay(60000) + .then(() => { + const logs = Utils.getFunctionLogs('hello'); + expect(/aws:sns/g.test(logs)).to.equal(true); + expect(/hello world/g.test(logs)).to.equal(true); + }) + ); -afterAll(() => { - Utils.removeService(); + afterAll(() => { + Utils.removeService(); + }); }); diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index b3ef47f00..6d5f28ade 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -6,30 +6,31 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -// General: Custom plugins test -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); +describe('General: Custom plugins test', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - // cd into the plugins directory - execSync('cd serverless-plugin-greeter'); + // cd into the plugins directory + execSync('cd serverless-plugin-greeter'); - // link and install the npm package / plugin - execSync('npm link serverless-plugin-greeter && npm install --save serverless-plugin-greeter'); + // link and install the npm package / plugin + execSync('npm link serverless-plugin-greeter && npm install --save serverless-plugin-greeter'); - // cd back into the service directory - execSync('cd ..'); -}); - -afterAll(() => { - // unlink the npm package - execSync('npm r serverless-plugin-greeter -g'); -}); - -it('should successfully run the greet command of the custom plugin', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} greet`); - - // note: the result will return a newline at the end - const result = new Buffer(pluginExecution, 'base64').toString(); - - expect(result).to.equal('Hello from the greeter plugin!'); + // cd back into the service directory + execSync('cd ..'); + }); + + afterAll(() => { + // unlink the npm package + execSync('npm r serverless-plugin-greeter -g'); + }); + + it('should successfully run the greet command of the custom plugin', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} greet`); + + // note: the result will return a newline at the end + const result = new Buffer(pluginExecution, 'base64').toString(); + + expect(result).to.equal('Hello from the greeter plugin!'); + }); }); diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js index 35fe66994..54594cf22 100644 --- a/tests/integration/general/local-plugins/tests.js +++ b/tests/integration/general/local-plugins/tests.js @@ -6,19 +6,20 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -// General: Local plugins test -beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); -}); +describe('General: Local plugins test', () => { + beforeAll(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + }); -it('should successfully run the one command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} one`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin one ran successfully/g.test(result)).to.equal(true); -}); + it('should successfully run the one command', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} one`); + const result = new Buffer(pluginExecution, 'base64').toString(); + expect(/plugin one ran successfully/g.test(result)).to.equal(true); + }); -it('should successfully run the two command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} two`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin two ran successfully/g.test(result)).to.equal(true); + it('should successfully run the two command', () => { + const pluginExecution = execSync(`${Utils.serverlessExec} two`); + const result = new Buffer(pluginExecution, 'base64').toString(); + expect(/plugin two ran successfully/g.test(result)).to.equal(true); + }); }); diff --git a/tests/simple-suite/tests.js b/tests/simple-suite/tests.js index 187904f5e..91baf2fc2 100644 --- a/tests/simple-suite/tests.js +++ b/tests/simple-suite/tests.js @@ -24,81 +24,83 @@ const stackName = `${newServiceName}-dev`; const CF = new AWS.CloudFormation({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -it('should create service in tmp directory', () => { - execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); - testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); - testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); -}); +describe('Service Lifecyle Integration Test', () => { + it('should create service in tmp directory', () => { + execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); + testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); + testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); + expect(serverless.utils + .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); + expect(serverless.utils + .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); + }); -it('should deploy service to aws', () => { - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); + it('should deploy service to aws', () => { + execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); - return CF.describeStacksPromised({ StackName: stackName }) - .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); -}); - -it('should invoke function from aws', () => { - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - // parse it once again because the body is stringified to be LAMBDA-PROXY ready - const message = JSON.parse(result.body).message; - expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); -}); - -it('should deploy updated service to aws', () => { - const newHandler = - ` - 'use strict'; - - module.exports.hello = (event, context, cb) => cb(null, - { message: 'Service Update Succeeded' } - ); - `; - - serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); -}); - -it('should invoke updated function from aws', () => { - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.message).to.be.equal('Service Update Succeeded'); -}); - -it( - 'should list existing deployments and roll back to first deployment', - () => { - let timestamp; - const listDeploys = execSync(`${serverlessExec} deploy list`); - const output = listDeploys.toString(); - const match = output.match(new RegExp('Timestamp: (.+)')); - if (match) { - timestamp = match[1]; - } - // eslint-disable-next-line no-unused-expressions - expect(timestamp).to.not.undefined; - - execSync(`${serverlessExec} rollback -t ${timestamp}`); + return CF.describeStacksPromised({ StackName: stackName }) + .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); + }); + it('should invoke function from aws', () => { const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); const result = JSON.parse(new Buffer(invoked, 'base64').toString()); // parse it once again because the body is stringified to be LAMBDA-PROXY ready const message = JSON.parse(result.body).message; expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); - } -); + }); -it('should remove service from aws', () => { - execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); + it('should deploy updated service to aws', () => { + const newHandler = + ` + 'use strict'; - return CF.describeStacksPromised({ StackName: stackName }) - .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) - .catch(e => { - if (e.message.indexOf('does not exist') > -1) return BbPromise.resolve(); - throw new serverless.classes.Error(e); - }); + module.exports.hello = (event, context, cb) => cb(null, + { message: 'Service Update Succeeded' } + ); + `; + + serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); + execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); + }); + + it('should invoke updated function from aws', () => { + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + expect(result.message).to.be.equal('Service Update Succeeded'); + }); + + it( + 'should list existing deployments and roll back to first deployment', + () => { + let timestamp; + const listDeploys = execSync(`${serverlessExec} deploy list`); + const output = listDeploys.toString(); + const match = output.match(new RegExp('Timestamp: (.+)')); + if (match) { + timestamp = match[1]; + } + // eslint-disable-next-line no-unused-expressions + expect(timestamp).to.not.undefined; + + execSync(`${serverlessExec} rollback -t ${timestamp}`); + + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + // parse it once again because the body is stringified to be LAMBDA-PROXY ready + const message = JSON.parse(result.body).message; + expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); + } + ); + + it('should remove service from aws', () => { + execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); + + return CF.describeStacksPromised({ StackName: stackName }) + .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) + .catch(e => { + if (e.message.indexOf('does not exist') > -1) return BbPromise.resolve(); + throw new serverless.classes.Error(e); + }); + }); }); From a149ac70038157ff77dc01de32253a5b313280e3 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 16 Dec 2016 23:53:49 +0100 Subject: [PATCH 19/24] reformat some tests --- .../integration/aws/general/custom-resources/tests.js | 9 +++++---- tests/integration/general/custom-plugins/tests.js | 10 +++++----- tests/simple-suite/tests.js | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index f91b377f7..ed3e6d854 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -45,10 +45,11 @@ describe('AWS - General: Custom resources test', () => { }) ); - it('should create the custom resources (a S3 bucket)', () => S3.listBucketsPromised() - .then((result) => !!_.find(result.Buckets, - { Name: s3BucketName })) - .then((found) => expect(found).to.equal(true)) + it('should create the custom resources (a S3 bucket)', () + => S3.listBucketsPromised() + .then((result) => !!_.find(result.Buckets, + { Name: s3BucketName })) + .then((found) => expect(found).to.equal(true)) ); afterAll(() => { diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index 6d5f28ade..6da6213f6 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -20,11 +20,6 @@ describe('General: Custom plugins test', () => { execSync('cd ..'); }); - afterAll(() => { - // unlink the npm package - execSync('npm r serverless-plugin-greeter -g'); - }); - it('should successfully run the greet command of the custom plugin', () => { const pluginExecution = execSync(`${Utils.serverlessExec} greet`); @@ -33,4 +28,9 @@ describe('General: Custom plugins test', () => { expect(result).to.equal('Hello from the greeter plugin!'); }); + + afterAll(() => { + // unlink the npm package + execSync('npm r serverless-plugin-greeter -g'); + }); }); diff --git a/tests/simple-suite/tests.js b/tests/simple-suite/tests.js index 91baf2fc2..2a132ee1b 100644 --- a/tests/simple-suite/tests.js +++ b/tests/simple-suite/tests.js @@ -11,7 +11,7 @@ const testUtils = require('../utils/index'); const serverless = new Serverless(); serverless.init(); -const serverlessExec = path.join(serverless.config.serverlessPath, '..', 'bin', 'serverless'); +const serverlessExec = path.join(__dirname, '..', 'bin', 'serverless'); const tmpDir = testUtils.getTmpDirPath(); fse.mkdirsSync(tmpDir); From 276692458c61e481bc51dc76561024dcadf4d271 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Sat, 17 Dec 2016 08:40:03 +0100 Subject: [PATCH 20/24] cleanup tests --- .../api-keys/tests.js | 5 +- .../simple-api/tests.js | 181 +++++++++--------- .../integration-lambda/api-keys/tests.js | 8 +- .../integration-lambda/simple-api/tests.js | 180 ++++++++--------- .../aws/general/custom-resources/tests.js | 4 +- tests/simple-suite/tests.js | 39 ++-- 6 files changed, 215 insertions(+), 202 deletions(-) diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index 58a3e8f0f..77e119870 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -44,9 +44,8 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - // TODO set an expect here + const matched = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${matched}/hello`; }) ); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js index a3fae6be1..49b09b77e 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js @@ -19,109 +19,118 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', () => beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); - return CF.describeStacksPromised({ StackName: stackName }) + }); + + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; endpoint = `${endpoint}`; - }); + }) + ); + + describe('when having a "without-slash" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); - it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + describe('when having a "/with-slash" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); - it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + describe('when having a "/" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); afterAll(() => { diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js index c1093bea6..3f21813db 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js @@ -17,11 +17,11 @@ const APIG = new AWS.APIGateway({ region: 'us-east-1' }); BbPromise.promisifyAll(CF, { suffix: 'Promised' }); BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); -let stackName; -let endpoint; -let apiKey; - describe('AWS - API Gateway (Integration: Lambda): API keys test', () => { + let stackName; + let endpoint; + let apiKey; + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js index 56b7ae558..6050c13f3 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js @@ -19,110 +19,118 @@ describe('AWS - API Gateway (Integration: Lambda): Simple API test', () => { beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); + }); - return CF.describeStacksPromised({ StackName: stackName }) + it('should expose the endpoint(s) in the CloudFormation Outputs', () => + CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; endpoint = `${endpoint}`; - }); + }) + ); + + describe('when having a "without-slash" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/without-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); - it('a "without-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + describe('when having a "/with-slash" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); + + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/with-slash`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); - it('a "without-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + describe('when having a "/" path setup', () => { + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "without-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "without-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); - it('a "/with-slash" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/with-slash" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('a "/" path should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); + }); }); afterAll(() => { diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js index ed3e6d854..66222e495 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -45,8 +45,8 @@ describe('AWS - General: Custom resources test', () => { }) ); - it('should create the custom resources (a S3 bucket)', () - => S3.listBucketsPromised() + it('should create the custom resources (a S3 bucket)', () => + S3.listBucketsPromised() .then((result) => !!_.find(result.Buckets, { Name: s3BucketName })) .then((found) => expect(found).to.equal(true)) diff --git a/tests/simple-suite/tests.js b/tests/simple-suite/tests.js index 2a132ee1b..c3bd1e9d1 100644 --- a/tests/simple-suite/tests.js +++ b/tests/simple-suite/tests.js @@ -70,28 +70,25 @@ describe('Service Lifecyle Integration Test', () => { expect(result.message).to.be.equal('Service Update Succeeded'); }); - it( - 'should list existing deployments and roll back to first deployment', - () => { - let timestamp; - const listDeploys = execSync(`${serverlessExec} deploy list`); - const output = listDeploys.toString(); - const match = output.match(new RegExp('Timestamp: (.+)')); - if (match) { - timestamp = match[1]; - } - // eslint-disable-next-line no-unused-expressions - expect(timestamp).to.not.undefined; - - execSync(`${serverlessExec} rollback -t ${timestamp}`); - - const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - // parse it once again because the body is stringified to be LAMBDA-PROXY ready - const message = JSON.parse(result.body).message; - expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); + it('should list existing deployments and roll back to first deployment', () => { + let timestamp; + const listDeploys = execSync(`${serverlessExec} deploy list`); + const output = listDeploys.toString(); + const match = output.match(new RegExp('Timestamp: (.+)')); + if (match) { + timestamp = match[1]; } - ); + // eslint-disable-next-line no-unused-expressions + expect(timestamp).to.not.undefined; + + execSync(`${serverlessExec} rollback -t ${timestamp}`); + + const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + // parse it once again because the body is stringified to be LAMBDA-PROXY ready + const message = JSON.parse(result.body).message; + expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); + }); it('should remove service from aws', () => { execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); From bbcbf85b34b81700591a82b882398ef22649603a Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Sat, 17 Dec 2016 08:55:46 +0100 Subject: [PATCH 21/24] fix simple integration test suite --- tests/simple-suite/tests.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/simple-suite/tests.js b/tests/simple-suite/tests.js index c3bd1e9d1..1d1d37008 100644 --- a/tests/simple-suite/tests.js +++ b/tests/simple-suite/tests.js @@ -1,17 +1,24 @@ 'use strict'; +const fs = require('fs'); const expect = require('chai').expect; const path = require('path'); const fse = require('fs-extra'); const BbPromise = require('bluebird'); const execSync = require('child_process').execSync; -const Serverless = require('../../lib/Serverless'); const AWS = require('aws-sdk'); const testUtils = require('../utils/index'); -const serverless = new Serverless(); -serverless.init(); -const serverlessExec = path.join(__dirname, '..', 'bin', 'serverless'); +const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); + +const fileExistsSync = (filePath) => { + try { + const stats = fse.lstatSync(filePath); + return stats.isFile(); + } catch (e) { + return false; + } +}; const tmpDir = testUtils.getTmpDirPath(); fse.mkdirsSync(tmpDir); @@ -29,10 +36,8 @@ describe('Service Lifecyle Integration Test', () => { execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); - expect(serverless.utils - .fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); + expect(fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); + expect(fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); }); it('should deploy service to aws', () => { @@ -60,7 +65,7 @@ describe('Service Lifecyle Integration Test', () => { ); `; - serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); + fs.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); }); @@ -95,9 +100,9 @@ describe('Service Lifecyle Integration Test', () => { return CF.describeStacksPromised({ StackName: stackName }) .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) - .catch(e => { - if (e.message.indexOf('does not exist') > -1) return BbPromise.resolve(); - throw new serverless.classes.Error(e); + .catch(error => { + if (error.message.indexOf('does not exist') > -1) return BbPromise.resolve(); + throw new Error(error); }); }); }); From 1ac9303de851b854f463f78ba59a43e3c5b5e2ed Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Sat, 17 Dec 2016 17:02:36 +0100 Subject: [PATCH 22/24] fix test to run in parallel --- .../integration-lambda-proxy/api-keys/tests.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js index 77e119870..a3048eda1 100644 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js @@ -39,6 +39,13 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { Utils.deployService(); }); + beforeAll(() => { + const info = execSync(`${Utils.serverlessExec} info`); + const stringifiedOutput = (new Buffer(info, 'base64').toString()); + // some regex magic to extract the first API key value from the info output + apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; + }); + it('should expose the endpoint(s) in the CloudFormation Outputs', () => CF.describeStacksPromised({ StackName: stackName }) .then((result) => _.find(result.Stacks[0].Outputs, @@ -50,13 +57,6 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { ); it('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); - - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - expect(apiKey.length).to.be.above(0); }); From cdcdf74f90060f71a585cd508165f8dc7abc337a Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Mon, 19 Dec 2016 09:15:17 +0100 Subject: [PATCH 23/24] run integration test suite only on master --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 448d313b3..28a51328e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: - if [[ -z "$INTEGRATION_TEST" && -z "$DISABLE_TESTS" ]]; then npm test; fi - if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" && -z "$INTEGRATION_TEST" ]]; then npm run lint; fi - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "simple" ]]; then npm run simple-integration-test; fi - - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" ]]; then npm run complex-integration-test; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" == "complex" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run complex-integration-test; fi after_success: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage From 59751ab4f8c38ef90378b929e4c3a33e0fdf7904 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Mon, 19 Dec 2016 11:17:16 +0100 Subject: [PATCH 24/24] use standard lib function and migrate to arrow functions --- scripts/integration-test-cleanup.js | 24 ++++++++++++------------ tests/simple-suite/tests.js | 13 ++----------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/scripts/integration-test-cleanup.js b/scripts/integration-test-cleanup.js index 23cea15f4..2d1d93578 100644 --- a/scripts/integration-test-cleanup.js +++ b/scripts/integration-test-cleanup.js @@ -11,8 +11,8 @@ const logger = console; const pattern = process.env.MATCH || '(test)-[0-9]+-[0-9]+-dev.+'; const regex = new RegExp(`^${pattern}/i`); -function emptyS3Bucket(bucket) { - return S3.listObjectsPromised({ Bucket: bucket }) +const emptyS3Bucket = (bucket) => ( + S3.listObjectsPromised({ Bucket: bucket }) .then(data => { logger.log('Bucket', bucket, 'has', data.Contents.length, 'items'); if (data.Contents.length) { @@ -25,18 +25,18 @@ function emptyS3Bucket(bucket) { }); } return Promise.resolve(); - }); -} + }) +); -function deleteS3Bucket(bucket) { - return emptyS3Bucket(bucket) +const deleteS3Bucket = (bucket) => ( + emptyS3Bucket(bucket) .then(() => { logger.log('Bucket', bucket, 'is now empty, deleting ...'); return S3.deleteBucketPromised({ Bucket: bucket }); - }); -} + }) +); -function cleanupS3Buckets(token) { +const cleanupS3Buckets = (token) => { logger.log('Looking through buckets ...'); const params = {}; @@ -60,9 +60,9 @@ function cleanupS3Buckets(token) { return Promise.resolve(); }) ); -} +}; -function cleanupCFStacks(token) { +const cleanupCFStacks = (token) => { const params = {}; if (token) { @@ -88,6 +88,6 @@ function cleanupCFStacks(token) { return Promise.resolve(); }) ); -} +}; cleanupS3Buckets().then(cleanupCFStacks); diff --git a/tests/simple-suite/tests.js b/tests/simple-suite/tests.js index 1d1d37008..b80b9a5a0 100644 --- a/tests/simple-suite/tests.js +++ b/tests/simple-suite/tests.js @@ -11,15 +11,6 @@ const testUtils = require('../utils/index'); const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); -const fileExistsSync = (filePath) => { - try { - const stats = fse.lstatSync(filePath); - return stats.isFile(); - } catch (e) { - return false; - } -}; - const tmpDir = testUtils.getTmpDirPath(); fse.mkdirsSync(tmpDir); process.chdir(tmpDir); @@ -36,8 +27,8 @@ describe('Service Lifecyle Integration Test', () => { execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); testUtils.replaceTextInFile('serverless.yml', 'name: aws', 'name: aws\n cfLogs: true'); - expect(fileExistsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); - expect(fileExistsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); + expect(fs.existsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); + expect(fs.existsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); }); it('should deploy service to aws', () => {