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/package.json b/package.json index bf30a8fda..214315ac4 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,12 @@ "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": "mocha tests/integration/simple-integration-test", - "complex-integration-test": "mocha tests/integration/all" + "simple-integration-test": "jest --maxWorkers=5 simple-suite", + "complex-integration-test": "jest --maxWorkers=5 integration" + }, + "jest": { + "testRegex": "(\\.|/)(tests)\\.js$", + "setupTestFrameworkScriptFile": "/tests/setupTests.js" }, "devDependencies": { "chai": "^3.5.0", @@ -63,6 +67,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", diff --git a/scripts/integration-test-cleanup.js b/scripts/integration-test-cleanup.js new file mode 100644 index 000000000..2d1d93578 --- /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`); + +const emptyS3Bucket = (bucket) => ( + 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(); + }) +); + +const deleteS3Bucket = (bucket) => ( + emptyS3Bucket(bucket) + .then(() => { + logger.log('Bucket', bucket, 'is now empty, deleting ...'); + return S3.deleteBucketPromised({ Bucket: bucket }); + }) +); + +const 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(); + }) + ); +}; + +const 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 33b39dfb3..000000000 --- a/tests/integration/all.js +++ /dev/null @@ -1,38 +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'); -require('./aws/general/package/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..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 @@ -17,14 +17,12 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { let stackName; let endpoint; let apiKey; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -41,24 +39,24 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', functio 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, { OutputKey: 'ServiceEndpoint' }).OutputValue) .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; + const matched = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${matched}/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); }); @@ -79,7 +77,7 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', functio }) ); - after(() => { + 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 5781519f0..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,13 +12,11 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { let stackName; let endpointBase; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -56,7 +54,7 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): CORS test', function () }) ); - 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 ce9676147..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,13 +12,12 @@ 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); +describe('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', () => { let stackName; let endpoint; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -57,7 +56,7 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers 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 44cbb7f80..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 @@ -12,13 +12,11 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', () => { let stackName; let endpoint; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -135,7 +133,7 @@ describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', funct }); }); - 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 615058232..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,14 +17,12 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda): API keys test', () => { let stackName; let endpoint; let apiKey; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of the API key with something unique @@ -79,7 +77,7 @@ describe('AWS - API Gateway (Integration: Lambda): API keys test', function () { }) ); - after(() => { + 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 f2252cd8e..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,13 +12,11 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda): CORS test', () => { let stackName; let endpointBase; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -56,7 +54,7 @@ describe('AWS - API Gateway (Integration: Lambda): CORS test', function () { }) ); - 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 a58f8a4b1..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,13 +12,11 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda): Custom authorizers test', () => { let stackName; let endpoint; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -57,7 +55,7 @@ describe('AWS - API Gateway (Integration: Lambda): Custom authorizers test', fun }) ); - 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 a91c03ada..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 @@ -12,13 +12,11 @@ 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); - +describe('AWS - API Gateway (Integration: Lambda): Simple API test', () => { let stackName; let endpoint; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -135,7 +133,7 @@ describe('AWS - API Gateway (Integration: Lambda): Simple API test', function () }); }); - 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 3dee13db5..66222e495 100644 --- a/tests/integration/aws/general/custom-resources/tests.js +++ b/tests/integration/aws/general/custom-resources/tests.js @@ -15,13 +15,11 @@ 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); - +describe('AWS - General: Custom resources test', () => { let stackName; let s3BucketName; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // replace name of bucket which is created through custom resources with something unique @@ -54,7 +52,7 @@ describe('AWS - General: Custom resources test', function () { .then((found) => expect(found).to.equal(true)) ); - 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 21d94a73f..af1dcb368 100644 --- a/tests/integration/aws/general/environment-variables/tests.js +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -6,10 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -describe('AWS - General: Environment variables test', function () { - this.timeout(0); - - before(() => { +describe('AWS - General: Environment variables test', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -29,7 +27,7 @@ describe('AWS - General: Environment variables test', function () { .to.be.equal('overwritten_by_function'); }); - 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 3525462e5..ed4083d95 100644 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ b/tests/integration/aws/general/nested-handlers/tests.js @@ -6,10 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../../utils/index'); -describe('AWS - General: Nested handlers test', function () { - this.timeout(0); - - before(() => { +describe('AWS - General: Nested handlers test', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -21,7 +19,7 @@ describe('AWS - General: Nested handlers test', function () { expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); }); - 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 bb1cb7338..06e615005 100644 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ b/tests/integration/aws/general/overwrite-resources/tests.js @@ -10,12 +10,10 @@ 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); - +describe('AWS - General: Overwrite resources test', () => { let stackName; - before(() => { + beforeAll(() => { stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -38,7 +36,7 @@ describe('AWS - General: Overwrite resources test', function () { }); }); - after(() => { + afterAll(() => { Utils.removeService(); }); }); diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js index d2a858bcb..a3d0a8f9f 100644 --- a/tests/integration/aws/general/package/tests.js +++ b/tests/integration/aws/general/package/tests.js @@ -10,12 +10,11 @@ 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); +describe('AWS - General: Deployment with --noDeploy', () => { let serviceName; let deploy; - before(() => { + beforeAll(() => { serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); deploy = execSync(`${Utils.serverlessExec} deploy --noDeploy`); }); @@ -30,7 +29,8 @@ describe('AWS - General: Deployment with --noDeploy', function () { 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/); + // 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) => { 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..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,10 +4,8 @@ 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(() => { +describe('AWS - S3: Multiple events in multiple functions with multiple buckets', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -30,7 +28,7 @@ describe('AWS - S3: Multiple events in multiple functions with multiple buckets' }) ); - 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 e93dba618..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,10 +4,8 @@ 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(() => { +describe('AWS - S3: Multiple events in multiple functions with a single bucket', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -26,7 +24,7 @@ describe('AWS - S3: Multiple events in multiple functions with a single bucket', }) ); - 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 71f0727fe..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,10 +4,8 @@ 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(() => { +describe('AWS - S3: Multiple events in a single function with a single bucket', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -24,7 +22,7 @@ describe('AWS - S3: Multiple events in a single function with a single bucket', }) ); - 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 87ff53529..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,10 +4,8 @@ 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(() => { +describe('AWS - S3: Single event in a single function with a single bucket', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -22,7 +20,7 @@ describe('AWS - S3: Single event in a single function with a single bucket', fun }) ); - 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 5ea854aec..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,10 +5,8 @@ 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(() => { +describe('AWS - Schedule: Multiple schedules with multiple functions', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -26,7 +24,7 @@ describe('AWS - Schedule: Multiple schedules with multiple functions', function }) ); - 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 b15b0907b..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,10 +4,8 @@ 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(() => { +describe('AWS - SNS: Multiple topics with multiple functions', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -27,7 +25,7 @@ describe('AWS - SNS: Multiple topics with multiple functions', function () { }) ); - 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 3866f9aa7..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,10 +4,8 @@ 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(() => { +describe('AWS - SNS: Multiple topics single function', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -24,7 +22,7 @@ describe('AWS - SNS: Multiple topics single function', function () { }) ); - 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 19c8adf69..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,10 +4,8 @@ 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(() => { +describe('AWS - SNS: Single topic with multiple functions', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -26,7 +24,7 @@ describe('AWS - SNS: Single topic with multiple functions', function () { }) ); - 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 7af1ff575..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,10 +4,8 @@ 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(() => { +describe('AWS - SNS: Single topic with single function', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); Utils.deployService(); }); @@ -22,7 +20,7 @@ describe('AWS - SNS: Single topic with single function', function () { }) ); - after(() => { + afterAll(() => { Utils.removeService(); }); }); diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js index 3ef77e3d6..6da6213f6 100644 --- a/tests/integration/general/custom-plugins/tests.js +++ b/tests/integration/general/custom-plugins/tests.js @@ -6,10 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -describe('General: Custom plugins test', function () { - this.timeout(0); - - before(() => { +describe('General: Custom plugins test', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); // cd into the plugins directory @@ -31,7 +29,7 @@ describe('General: Custom plugins test', function () { expect(result).to.equal('Hello from the greeter plugin!'); }); - after(() => { + afterAll(() => { // unlink the npm package execSync('npm r serverless-plugin-greeter -g'); }); diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js index ec1bc3a41..54594cf22 100644 --- a/tests/integration/general/local-plugins/tests.js +++ b/tests/integration/general/local-plugins/tests.js @@ -6,10 +6,8 @@ const execSync = require('child_process').execSync; const Utils = require('../../../utils/index'); -describe('General: Local plugins test', function () { - this.timeout(0); - - before(() => { +describe('General: Local plugins test', () => { + beforeAll(() => { Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); }); diff --git a/tests/setupTests.js b/tests/setupTests.js new file mode 100644 index 000000000..4da8b0798 --- /dev/null +++ b/tests/setupTests.js @@ -0,0 +1,3 @@ +// timeout is set to 5 minutes +// eslint-disable-next-line no-undef +jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; diff --git a/tests/integration/simple-integration-test.js b/tests/simple-suite/tests.js similarity index 82% rename from tests/integration/simple-integration-test.js rename to tests/simple-suite/tests.js index 2fab3d6b3..b80b9a5a0 100644 --- a/tests/integration/simple-integration-test.js +++ b/tests/simple-suite/tests.js @@ -1,17 +1,15 @@ '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(serverless.config.serverlessPath, '..', 'bin', 'serverless'); +const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); const tmpDir = testUtils.getTmpDirPath(); fse.mkdirsSync(tmpDir); @@ -24,17 +22,13 @@ 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); - +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); + 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', () => { @@ -62,7 +56,7 @@ describe('Service Lifecyle Integration Test', function () { ); `; - serverless.utils.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); + fs.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); }); @@ -97,9 +91,9 @@ describe('Service Lifecyle Integration Test', function () { 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); }); }); }); diff --git a/tests/utils/index.js b/tests/utils/index.js index 43bf30fcd..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')); @@ -31,7 +28,8 @@ module.exports = { replaceTextInFile, 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',