Skip to content

Commit 98f57e7

Browse files
committed
Add test
1 parent d91e423 commit 98f57e7

File tree

5 files changed

+120
-9
lines changed

5 files changed

+120
-9
lines changed

.gitignore

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1+
# Logs
2+
*.log
3+
npm-debug.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
dist
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
128
node_modules
2-
npm-debug.log
29+
30+
# IDE stuff
31+
**/.idea
32+
33+
# OS stuff
34+
.DS_Store
35+
.tmp
36+
37+
# Serverless stuff
38+
admin.env
39+
.env
40+
tmp
41+
.coveralls.yml
42+
tmpdirs-serverless

.travis.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
language: node_js
22

3-
node_js:
4-
- '6.2'
3+
matrix:
4+
include:
5+
- node_js: '4.4'
6+
- node_js: '5.11'
7+
- node_js: '6.2'
8+
- node_js: '6.2'
9+
- node_js: '6.2'
10+
env:
11+
- DISABLE_TESTS=true
12+
- LINTING=true
513

614
sudo: false
715

816
install:
917
- travis_retry npm install
1018

1119
script:
12-
- npm run lint
20+
- if [[ -z "$DISABLE_TESTS" ]]; then npm run test; fi
21+
- if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" ]]; then npm run lint; fi
22+
23+
after_success:
24+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ const _ = require('lodash');
66
class ServerlessStepFunctions {
77
constructor(serverless, options) {
88
this.serverless = serverless;
9-
this.options = options;
9+
this.options = options || {};
1010
this.provider = this.serverless.getProvider('aws');
1111
this.awsStateLanguage = {};
1212
this.functionArns = {};
1313
const region = this.options.region || 'us-east-1';
14-
1514
this.iamRoleName = `serverless-step-functions-executerole-${region}`;
1615
this.iamPolicyName = `serverless-step-functions-executepolicy-${region}`;
17-
1816
this.iamPolicyStatement = `{
1917
"Version": "2012-10-17",
2018
"Statement": [

index.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
const expect = require('chai').expect;
4+
const Serverless = require('serverless/lib/Serverless');
5+
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider');
6+
const ServerlessStepFunctions = require('./index');
7+
8+
describe('ServerlessStepFunctions', () => {
9+
let serverless;
10+
let serverlessStepFunctions;
11+
12+
beforeEach(() => {
13+
serverless = new Serverless();
14+
serverless.servicePath = true;
15+
16+
serverless.service.functions = {
17+
first: {
18+
handler: true,
19+
},
20+
};
21+
const options = {
22+
stage: 'dev',
23+
region: 'us-east-1',
24+
function: 'first',
25+
functionObj: {
26+
name: 'first',
27+
},
28+
};
29+
serverless.init();
30+
serverless.setProvider('aws', new AwsProvider(serverless));
31+
serverlessStepFunctions = new ServerlessStepFunctions(serverless, options);
32+
});
33+
34+
describe('#constructor()', () => {
35+
it('should have hooks', () => expect(serverlessStepFunctions.hooks).to.be.not.empty);
36+
37+
it('should set the provider variable to an instance of AwsProvider', () =>
38+
expect(serverlessStepFunctions.provider).to.be.instanceof(AwsProvider));
39+
40+
it('should set the iamRoleName variable', () =>
41+
expect(serverlessStepFunctions.iamRoleName).to.be
42+
.equal('serverless-step-functions-executerole-us-east-1'));
43+
44+
it('should set the iamPolicyName variable', () =>
45+
expect(serverlessStepFunctions.iamPolicyName).to.be
46+
.equal('serverless-step-functions-executepolicy-us-east-1'));
47+
48+
it('should set an empty options object if no options are given', () => {
49+
const serverlessStepFunctionsWithEmptyOptions = new ServerlessStepFunctions(serverless);
50+
51+
expect(serverlessStepFunctionsWithEmptyOptions.options).to.deep.equal({});
52+
});
53+
});
54+
});

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "The module is AWS Step Functions plugin for Serverless Framework",
55
"main": "index.js",
66
"scripts": {
7-
"test": "npm run test",
7+
"test": "istanbul cover -x '*.test.js' node_modules/mocha/bin/_mocha '*.test.js' -- -R spec --recursive",
88
"lint": "eslint ."
99
},
1010
"repository": {
@@ -26,7 +26,14 @@
2626
"eslint-config-airbnb-base": "^5.0.2",
2727
"eslint-plugin-import": "^1.13.0",
2828
"eslint-plugin-jsx-a11y": "^2.1.0",
29-
"eslint-plugin-react": "^6.1.1"
29+
"eslint-plugin-react": "^6.1.1",
30+
"serverless": "^1.4.0",
31+
"istanbul": "^0.4.4",
32+
"mocha": "^3.0.2",
33+
"mocha-lcov-reporter": "^1.2.0",
34+
"chai": "^3.5.0",
35+
"coveralls": "^2.11.12",
36+
"sinon": "^1.17.5"
3037
},
3138
"dependencies": {
3239
"lodash": "^4.13.1",

0 commit comments

Comments
 (0)