diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..211df6524 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +manual_test_nodejs +manual_test_python +manual_test_ruby +manual_test_websocket diff --git a/.eslintrc.js b/.eslintrc.js index 4e7610cb7..c3fef98ce 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,21 +1,21 @@ const { env, platform } = process; const rules = { - semi: ["error", "always"], - "prefer-destructuring": "off", - "key-spacing": "off", - "guard-for-in": "off", - "no-restricted-syntax": "off", - "import/no-dynamic-require": "off", + 'guard-for-in': 'off', + 'import/no-dynamic-require': 'off', + 'key-spacing': 'off', + 'no-restricted-syntax': 'off', + 'prefer-destructuring': 'off', + semi: ['error', 'always'], }; // workaround for git + eslint line ending issue on Travis for Windows OS: // https://travis-ci.community/t/files-in-checkout-have-eol-changed-from-lf-to-crlf/349/2 -if (env.TRAVIS && platform === "win32") { - rules["linebreak-style"] = "off"; +if (env.TRAVIS && platform === 'win32') { + rules['linebreak-style'] = 'off'; } module.exports = { - extends: "dherault", + extends: 'dherault', rules, }; diff --git a/package.json b/package.json index fe4a21571..ed50c0ba9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "src/index.js", "scripts": { "test": "mocha test", - "lint": "eslint src/**/*.js test/**/*.js" + "lint": "eslint ." }, "repository": { "type": "git", diff --git a/test/.eslintrc.js b/test/.eslintrc.js index 55ff461e8..ae6782e62 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -5,5 +5,8 @@ const rules = { }; module.exports = { + 'env': { + 'mocha': true + }, rules, }; diff --git a/test/unit/authCanExecuteResourceTest.js b/test/unit/authCanExecuteResourceTest.js index 7e431e3ba..2180ac5e0 100644 --- a/test/unit/authCanExecuteResourceTest.js +++ b/test/unit/authCanExecuteResourceTest.js @@ -1,4 +1,3 @@ -/* global describe context it */ const { expect } = require('chai'); const authCanExecuteResource = require('../../src/authCanExecuteResource'); @@ -137,6 +136,7 @@ describe('authCanExecuteResource', () => { const canExecute = authCanExecuteResource(policy, resourceTwo); expect(canExecute).to.eq(false); }); + context('and the Resource is an array', () => { it('returns false', () => { const policy = setup( @@ -154,6 +154,7 @@ describe('authCanExecuteResource', () => { expect(canExecute).to.eq(false); }); }); + context('and there is also an Allow statement', () => { it('returns false', () => { const policy = setup( diff --git a/test/unit/authFunctionNameExtractorTest.js b/test/unit/authFunctionNameExtractorTest.js index 3abafc467..8fcff5c90 100644 --- a/test/unit/authFunctionNameExtractorTest.js +++ b/test/unit/authFunctionNameExtractorTest.js @@ -1,4 +1,3 @@ -/* global describe context it */ const { expect } = require('chai'); const authFunctionNameExtractor = require('../../src/authFunctionNameExtractor'); @@ -79,6 +78,7 @@ describe('authFunctionNameExtractor', () => { context('authorizer is a string', () => { it('is a string anAuthorizerName', supportedAuthTest('anAuthorizerName', 'anAuthorizerName')); }); + context('authorizer is an object', () => { it('named anAuthorizerName', supportedAuthTest({ name : 'anAuthorizerName' }, 'anAuthorizerName')); }); diff --git a/test/unit/authMatchPolicyResourceTest.js b/test/unit/authMatchPolicyResourceTest.js index 3b0a2abd1..b4d25295f 100644 --- a/test/unit/authMatchPolicyResourceTest.js +++ b/test/unit/authMatchPolicyResourceTest.js @@ -1,4 +1,3 @@ -/* global describe context it */ const { expect } = require('chai'); const authMatchPolicyResource = require('../../src/authMatchPolicyResource'); diff --git a/test/unit/createLambdaProxyContextTest.js b/test/unit/createLambdaProxyContextTest.js index 53b1655b9..2d24f773a 100644 --- a/test/unit/createLambdaProxyContextTest.js +++ b/test/unit/createLambdaProxyContextTest.js @@ -1,5 +1,3 @@ -/* global describe before context it */ -/* eslint-disable no-unused-expressions */ const { expect } = require('chai'); const RequestBuilder = require('../support/RequestBuilder'); const createLambdaProxyContext = require('../../src/createLambdaProxyContext'); diff --git a/test/unit/functionHelperTest.js b/test/unit/functionHelperTest.js index d1faec670..774c6c2f8 100644 --- a/test/unit/functionHelperTest.js +++ b/test/unit/functionHelperTest.js @@ -1,4 +1,3 @@ -/* global describe before context it */ const { expect } = require('chai'); const path = require('path'); const functionHelper = require('../../src/functionHelper'); diff --git a/test/unit/requestBodyValidatorTest.js b/test/unit/requestBodyValidatorTest.js index 06b4198db..d96146348 100644 --- a/test/unit/requestBodyValidatorTest.js +++ b/test/unit/requestBodyValidatorTest.js @@ -1,4 +1,3 @@ -/* global describe before context it */ const { expect } = require('chai'); const requestBodyValidator = require('../../src/requestBodyValidator'); @@ -64,6 +63,7 @@ describe('requestBodyValidator', () => { }, }, }; + before(() => { result = requestBodyValidator.getModel(custom, eventHttp, log => logStorage.push(log)); }); @@ -71,6 +71,7 @@ describe('requestBodyValidator', () => { it('should return null', () => { expect(result).to.eq(null); }); + it('should add a warning log', () => { expect(logStorage.length).to.eq(1); expect(logStorage[0]).to.eq(`Warning: can't find '${anotherModel}' within ${JSON.stringify(eventHttp.documentation.requestModels)}`); @@ -101,6 +102,7 @@ describe('requestBodyValidator', () => { const body = JSON.stringify({ message: 'foo', }); + it('should throw error', () => { expect(() => requestBodyValidator.validate(model, body)).to.throw(/Request body validation failed.*/); }); diff --git a/test/unit/utilsTest.js b/test/unit/utilsTest.js index 7855edf02..2c462e407 100644 --- a/test/unit/utilsTest.js +++ b/test/unit/utilsTest.js @@ -1,4 +1,3 @@ -/* global describe context it */ const { expect } = require('chai'); const { detectEncoding, diff --git a/test/unit/velocityContextTest.js b/test/unit/velocityContextTest.js index 43476036d..45147ed65 100644 --- a/test/unit/velocityContextTest.js +++ b/test/unit/velocityContextTest.js @@ -1,4 +1,3 @@ -/* global describe it */ const { expect } = require('chai'); const createVelocityContext = require('../../src/createVelocityContext');