Skip to content

Commit db8a4b3

Browse files
committed
unit tests fixed
1 parent 8ad9fd1 commit db8a4b3

File tree

8 files changed

+433
-77
lines changed

8 files changed

+433
-77
lines changed

build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module.exports = {
3535
return Promise.resolve()
3636
.then(() => this.process(this.states[this.stateDefinition.StartAt], this.stateDefinition.StartAt, this.eventFile))
3737
.catch(err => {
38-
console.log('OOPS', err.stack);
39-
this.cliLog(err);
38+
// console.log('OOPS', err.stack);
39+
// this.cliLog(err);
4040
throw err;
4141
});
4242
},

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class StepFunctionsOfflinePlugin {
7474
if (this.options.location) {
7575
this.location = path.join(process.cwd(), this.options.location);
7676
}
77-
if (this.variables.location) {
77+
if (this.variables && this.variables.location) {
7878
this.location = path.join(process.cwd(), this.variables.location);
7979
}
8080
}
@@ -116,6 +116,7 @@ class StepFunctionsOfflinePlugin {
116116
this.environment = this.serverless.service.provider.environment;
117117
process.env.STEP_IS_OFFLINE = true;
118118
process.env = _.extend(process.env, this.environment);
119+
return;
119120
}
120121

121122
findState() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "git@github.com:vkkis93/serverless-step-functions-offline.git"
1414
},
1515
"scripts": {
16-
"test": "nyc ./node_modules/mocha/bin/mocha ./tests/index.test.js './tests/!(index.test).js'",
16+
"test": "nyc ./node_modules/mocha/bin/mocha ./tests/index.test.js ./tests/enum.test.js ./tests/parse.test.js ./tests/build.test.js",
1717
"lint": "eslint ./** --ext .js"
1818
},
1919
"dependencies": {

parse.js

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
2-
const BbPromise = require('bluebird');
2+
const Promise = require('bluebird');
33
const path = require('path');
4-
const _ = require('lodash');
54

65
module.exports = {
76
yamlParse() {
@@ -37,67 +36,16 @@ module.exports = {
3736
}
3837

3938
this.serverless.variables.populateService(this.serverless.pluginManager.cliOptions);
40-
return BbPromise.resolve();
39+
return Promise.resolve();
4140
});
4241
},
4342

44-
getAllStateMachines() {
45-
if (Object.prototype.toString.call(this.serverless.service.stepFunctions.stateMachines)
46-
!== '[object Object]') {
47-
const errorMessage = [
48-
'stateMachines property is not an object',
49-
' Please check the README for more info.',
50-
].join('');
51-
throw new this.serverless.classes
52-
.Error(errorMessage);
53-
}
54-
return Object.keys(this.serverless.service.stepFunctions.stateMachines);
55-
},
56-
5743
getStateMachine(stateMachineName) {
5844
if (stateMachineName in this.serverless.service.stepFunctions.stateMachines) {
5945
return this.serverless.service.stepFunctions.stateMachines[stateMachineName];
6046
}
6147
throw new this.serverless.classes
6248
.Error(`stateMachine "${stateMachineName}" doesn't exist in this Service`);
63-
},
64-
65-
isStateMachines() {
66-
if (this.serverless.service.stepFunctions != null
67-
&& this.serverless.service.stepFunctions.stateMachines != null
68-
&& !_.isEmpty(this.serverless.service.stepFunctions.stateMachines)) {
69-
return true;
70-
}
71-
return false;
72-
},
73-
74-
getAllActivities() {
75-
if (!Array.isArray(this.serverless.service.stepFunctions.activities)) {
76-
const errorMessage = [
77-
'activities property is not an array',
78-
' Please check the README for more info.',
79-
].join('');
80-
throw new this.serverless.classes
81-
.Error(errorMessage);
82-
}
83-
return this.serverless.service.stepFunctions.activities;
84-
},
85-
86-
getActivity(activityName) {
87-
if (this.serverless.service.stepFunctions.activities.indexOf(activityName) !== -1) {
88-
return activityName;
89-
}
90-
91-
throw new this.serverless.classes
92-
.Error(`activity "${activityName}" doesn't exist in this Service`);
93-
},
94-
95-
isActivities() {
96-
if (this.serverless.service.stepFunctions != null
97-
&& this.serverless.service.stepFunctions.activities != null
98-
&& !_.isEmpty(this.serverless.service.stepFunctions.activities)) {
99-
return true;
100-
}
101-
return false;
10249
}
50+
10351
};

tests/build.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('build.js', () => {
2121
}).finally(done);
2222
});
2323

24-
it('should throw err - can not read property', (done) => {
24+
it('should throw err - goody', (done) => {
2525
stepFunctionsOfflinePlugin.variables = {FirstLambda: 'firstLambda'};
2626
stepFunctionsOfflinePlugin.hooks[hooks.buildStepWorkFlow]()
2727
.then((res) => {

tests/index.test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ const StepFunctionsOfflinePlugin = require('../index');
88

99
describe('index.js', () => {
1010
global.hooks = {
11-
beforeStart: 'before:step-functions-offline:start',
1211
start: 'step-functions-offline:start',
1312
isInstalledPluginSLSStepFunctions: 'step-functions-offline:isInstalledPluginSLSStepFunctions',
1413
findState: 'step-functions-offline:findState',
1514
findFunctionsPathAndHandler: 'step-functions-offline:findFunctionsPathAndHandler',
1615
loadEventFile: 'step-functions-offline:loadEventFile',
16+
loadEnvVariables: 'step-functions-offline:loadEnvVariables',
1717
buildStepWorkFlow: 'step-functions-offline:buildStepWorkFlow'
1818
};
1919

2020
const options = {
2121
stateMachine: 'foo',
2222
s: 'foo',
23-
event: null
23+
event: null,
24+
location: './tests'
2425
};
2526
const serverless = new Serverless();
2627
serverless.cli = new CLI();
@@ -49,14 +50,14 @@ describe('index.js', () => {
4950

5051
describe('#checkVariableInYML', () => {
5152
it('should throw error - custom.stepFunctionsOffline does not exist', () => {
52-
expect(stepFunctionsOfflinePlugin.hooks[hooks.beforeStart]).to.throw(/ENV_VARIABLES/);
53+
expect(stepFunctionsOfflinePlugin.hooks[hooks.start]).to.throw(/ENV_VARIABLES/);
5354
});
5455

5556
it('should exists custom.stepFunctionsOffline', () => {
5657
stepFunctionsOfflinePlugin.serverless.service.custom = {
5758
stepFunctionsOffline: {FirstLambda: 'firstLamda/index.handler'}
5859
};
59-
expect(stepFunctionsOfflinePlugin.hooks[hooks.beforeStart]).to.not.throw();
60+
expect(stepFunctionsOfflinePlugin.hooks[hooks.start]).to.not.throw();
6061
});
6162

6263
});
@@ -113,6 +114,15 @@ describe('index.js', () => {
113114
});
114115
})
115116

117+
118+
describe('#loadEnvVariables', () => {
119+
it('should return empty object', () => {
120+
const result = stepFunctionsOfflinePlugin.hooks[hooks.loadEnvVariables]();
121+
expect(result).to.be.undefined;
122+
});
123+
124+
});
125+
116126
describe('#findState', () => {
117127
it('should throw err - serverless.yml not exists', () => {
118128
// stepFunctionsOfflinePlugin.serverless.config = process.cwd() + '/serverless.test.yml';

tests/serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ stepFunctions:
3333
States:
3434
FirstLambda:
3535
Type: Task
36-
Next: wait_using_seconds
36+
Next: FinalState
3737
wait_using_seconds:
3838
Type: Wait
3939
Seconds: 10

0 commit comments

Comments
 (0)