mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #2975 from serverless/switch-to-jest-2
Switch to jest 2
This commit is contained in:
commit
524d596a9d
@ -11,6 +11,7 @@ module.exports = {
|
||||
"import/no-extraneous-dependencies" : "off"
|
||||
},
|
||||
"env": {
|
||||
"mocha": true
|
||||
"mocha": true,
|
||||
"jest": true
|
||||
}
|
||||
};
|
||||
|
||||
@ -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": "<rootDir>/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",
|
||||
|
||||
93
scripts/integration-test-cleanup.js
Normal file
93
scripts/integration-test-cleanup.js
Normal file
@ -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);
|
||||
@ -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');
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
@ -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'));
|
||||
});
|
||||
|
||||
|
||||
3
tests/setupTests.js
Normal file
3
tests/setupTests.js
Normal file
@ -0,0 +1,3 @@
|
||||
// timeout is set to 5 minutes
|
||||
// eslint-disable-next-line no-undef
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000;
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user