File tree Expand file tree Collapse file tree 9 files changed +112
-5
lines changed Expand file tree Collapse file tree 9 files changed +112
-5
lines changed Original file line number Diff line number Diff line change 5
5
"es6": true
6
6
},
7
7
"parserOptions": {
8
- "sourceType": "module"
8
+ "sourceType": "module",
9
+ "ecmaVersion": 2019
9
10
},
10
11
"extends": "eslint:recommended",
11
12
"rules": {
22
23
"indent": [
23
24
"error",
24
25
2
26
+ ],
27
+ "semi": [
28
+ "error",
29
+ "always"
30
+ ],
31
+ "object-curly-spacing": [
32
+ "error",
33
+ "always"
34
+ ],
35
+ "array-bracket-spacing": [
36
+ "error",
37
+ "never"
25
38
]
26
39
}
27
40
}
Original file line number Diff line number Diff line change
1
+ .nyc_output /
1
2
.vscode /
3
+ coverage /
2
4
dist /
3
5
node_modules /
Original file line number Diff line number Diff line change
1
+ {
2
+ "spec" : " test/**/*.spec.js" ,
3
+ "slow" : 10 ,
4
+ "timeout" : 50 ,
5
+ "require" : " @babel/register"
6
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "all" : true ,
3
+ "check-coverage" : true ,
4
+ "lines" : 95 ,
5
+ "statements" : 95 ,
6
+ "functions" : 95 ,
7
+ "branches" : 90 ,
8
+ "include" : [
9
+ " src/**/*.js"
10
+ ],
11
+ "reporter" : [
12
+ " lcov" ,
13
+ " text"
14
+ ]
15
+ }
Original file line number Diff line number Diff line change 7
7
"build" : " babel --out-dir dist src" ,
8
8
"lint" : " eslint ." ,
9
9
"format" : " npm run lint -s -- --fix" ,
10
- "test" : " npm run lint -s"
10
+ "test" : " npm run lint -s && nyc mocha --colors "
11
11
},
12
12
"repository" : {
13
13
"type" : " git" ,
35
35
"@babel/cli" : " ^7.10.5" ,
36
36
"@babel/core" : " ^7.11.4" ,
37
37
"@babel/preset-env" : " ^7.11.0" ,
38
+ "@babel/register" : " ^7.10.5" ,
38
39
"babel-plugin-add-module-exports" : " ^1.0.2" ,
39
- "eslint" : " ^7.7.0"
40
+ "chai" : " ^4.2.0" ,
41
+ "eslint" : " ^7.7.0" ,
42
+ "eslint-plugin-chai-friendly" : " ^0.6.0" ,
43
+ "eslint-plugin-mocha" : " ^8.0.0" ,
44
+ "mocha" : " ^8.1.1" ,
45
+ "nyc" : " ^15.1.0" ,
46
+ "sinon" : " ^9.0.3"
40
47
}
41
48
}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export class FunctionValuePlugin {
5
5
this . variableResolvers = {
6
6
'fn.arn' : ( value ) => this . getFunctionARNStatement ( value ) ,
7
7
'fn.name' : ( value ) => this . getFunctionNameStatement ( value )
8
- }
8
+ } ;
9
9
}
10
10
11
11
getFunctionLogicalId ( value ) {
Original file line number Diff line number Diff line change 1
- import { FunctionValuePlugin } from './functionValuePlugin ' ;
1
+ import { FunctionValuePlugin } from './function-value-plugin ' ;
2
2
3
3
export default FunctionValuePlugin ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "env": {
3
+ "mocha": true
4
+ },
5
+ "plugins": [
6
+ "mocha",
7
+ "chai-friendly"
8
+ ],
9
+ "parserOptions": {
10
+ "sourceType": "module"
11
+ },
12
+ "rules": {
13
+ "mocha/no-identical-title": [
14
+ "error"
15
+ ],
16
+ "chai-friendly/no-unused-expressions": [
17
+ "error"
18
+ ]
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ import Plugin from '../src/index' ;
2
+ import sinon from 'sinon' ;
3
+ import { expect } from 'chai' ;
4
+
5
+ describe ( 'plugin' , ( ) => {
6
+ const functionName = 'health' ;
7
+ const logicalId = 'HealthLambdaFunction' ;
8
+ let variableResolvers ;
9
+
10
+ before ( ( ) => {
11
+ const service = { getAllFunctions : sinon . stub ( ) . returns ( [ functionName ] ) } ;
12
+ const provider = {
13
+ naming : { getLambdaLogicalId : sinon . stub ( ) . returns ( logicalId ) }
14
+ } ;
15
+ const serverless = {
16
+ service,
17
+ getProvider : sinon . stub ( ) . returns ( provider )
18
+ } ;
19
+
20
+ variableResolvers = new Plugin ( serverless ) . variableResolvers ;
21
+ } ) ;
22
+
23
+ [
24
+ { type : 'arn' , expected : `!GetAtt ${ logicalId } .ARN` } ,
25
+ { type : 'name' , expected : `!Ref ${ logicalId } ` }
26
+ ] . forEach ( test => {
27
+ it ( `will generate function ${ test . type } snippet` , async ( ) => {
28
+ const resolver = `fn.${ test . type } ` ;
29
+ const value = `${ resolver } :${ functionName } ` ;
30
+ const result = await variableResolvers [ resolver ] ( value ) ;
31
+
32
+ expect ( result ) . to . equal ( test . expected ) ;
33
+ } ) ;
34
+ } ) ;
35
+
36
+ it ( 'will fail if function not found' , async ( ) => {
37
+ try {
38
+ await variableResolvers [ 'fn.arn' ] ( 'fn.arn:test' ) ;
39
+ throw new Error ( 'should not get here' ) ;
40
+ } catch {
41
+ // success!
42
+ }
43
+ } ) ;
44
+ } ) ;
You can’t perform that action at this time.
0 commit comments