Skip to content

Commit

Permalink
Add lint to project. (#34)
Browse files Browse the repository at this point in the history
* Add lint to project.

* pr comment that prevents me from breaking the world
  • Loading branch information
Arthur Cinader authored Dec 6, 2016
1 parent fa27701 commit 4fe8908
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 26 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/*
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"no-trailing-spaces": 2,
"eol-last": 2,
"space-in-parens": ["error", "never"],
"no-multiple-empty-lines": 1
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ node_modules

# Webstorm
.idea/

.eslintcache
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ S3Adapter.prototype.createBucket = function() {
if (this._hasBucket) {
promise = Promise.resolve();
} else {
promise = new Promise((resolve, reject) => {
promise = new Promise((resolve) => {
this._s3Client.createBucket(() => {
this._hasBucket = true;
resolve();
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "AWS S3 adapter for parse-server",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test NODE_CONFIG_DIR=./spec/config istanbul cover -x **/spec/** jasmine --captureExceptions"
"pretest": "npm run lint",
"test": "NODE_ENV=test NODE_CONFIG_DIR=./spec/config istanbul cover -x **/spec/** jasmine --captureExceptions",
"lint": "eslint --cache ./"
},
"repository": {
"type": "git",
Expand All @@ -27,6 +29,7 @@
"devDependencies": {
"codecov": "^1.0.1",
"config": "^1.24.0",
"eslint": "^3.11.1",
"istanbul": "^0.4.2",
"jasmine": "^2.4.1",
"parse-server-conformance-tests": "^1.0.0"
Expand Down
31 changes: 31 additions & 0 deletions spec/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"env": {
"jasmine": true
},
"globals": {
"Parse": true,
"reconfigureServer": true,
"createTestUser": true,
"jfail": true,
"ok": true,
"strictEqual": true,
"TestObject": true,
"Item": true,
"Container": true,
"equal": true,
"notEqual": true,
"it_exclude_dbs": true,
"describe_only_db": true,
"on_db": true,
"defaultConfiguration": true,
"expectSuccess": true,
"range": true,
"expectError": true,
"jequal": true,
"create": true,
"arrayContains": true
},
"rules": {
"no-console": [0]
}
}
8 changes: 4 additions & 4 deletions spec/config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module.exports = {
},
bucket: 'bucket',
objectWithBucket: {
bucket: 'bucket',
bucket: 'bucket',
},
emptyObject: {},
paramsObjectWBucket: {
params: {
Bucket: 'bucket',
},
params: {
Bucket: 'bucket',
},
},
};
40 changes: 20 additions & 20 deletions spec/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ describe('S3Adapter tests', () => {
delete process.env.S3_REGION;
});

it('should throw when not initialized properly', () => {
expect(() => {
var s3 = new S3Adapter();
it('should throw when not initialized properly', () => {
expect(() => {
new S3Adapter();
}).toThrow("S3Adapter requires option 'bucket' or env. variable S3_BUCKET");

expect(() =>  {
var s3 = new S3Adapter('accessKey', 'secretKey', {});
expect(() => {
new S3Adapter('accessKey', 'secretKey', {});
}).toThrow(new Error('Failed to configure S3Adapter. Arguments don\'t make sense'));

expect(() => {
var s3 = new S3Adapter({ accessKey: 'accessKey' , secretKey: 'secretKey'});
expect(() => {
new S3Adapter({ accessKey: 'accessKey' , secretKey: 'secretKey'});
}).toThrow("S3Adapter requires option 'bucket' or env. variable S3_BUCKET")
})

it('should not throw when initialized properly', () => {
expect(() => {
var s3 = new S3Adapter('bucket');
it('should not throw when initialized properly', () => {
expect(() => {
new S3Adapter('bucket');
}).not.toThrow()

expect(() => {
var s3 = new S3Adapter({ bucket: 'bucket'});
expect(() => {
new S3Adapter({ bucket: 'bucket'});
}).not.toThrow()

expect(() => {
var s3 = new S3Adapter({}, { params:{ Bucket: 'bucket'}});
new S3Adapter({}, { params:{ Bucket: 'bucket'}});
}).not.toThrow()
});

Expand All @@ -50,34 +50,34 @@ describe('S3Adapter tests', () => {
describe('not initialized properly', () => {
it('should fail with two string arguments', () => {
expect(() => {
var s3 = new S3Adapter(config.get('accessKey'), config.get('secretKey'), {});
new S3Adapter(config.get('accessKey'), config.get('secretKey'), {});
}).toThrow(new Error('Failed to configure S3Adapter. Arguments don\'t make sense'));
});

it('should fail when passed an object without a bucket', () => {
expect(() => {
var s3 = new S3Adapter(config.get('insufficientOptions'));
new S3Adapter(config.get('insufficientOptions'));
}).toThrow("S3Adapter requires option 'bucket' or env. variable S3_BUCKET")
});
});


describe('should not throw when initialized properly', () => {
it('should accept a string bucket', () => {
expect(() => {
var s3 = new S3Adapter(config.get('bucket'));
expect(() => {
new S3Adapter(config.get('bucket'));
}).not.toThrow()
});

it('should accept an object with a bucket', () => {
expect(() =>  {
var s3 = new S3Adapter(config.get('objectWithBucket'));
expect(() => {
new S3Adapter(config.get('objectWithBucket'));
}).not.toThrow()
});

it('should accept a second argument of object with a params object with a bucket', () => {
expect(() => {
var s3 = new S3Adapter(config.get('emptyObject'), config.get('paramsObjectWBucket'));
new S3Adapter(config.get('emptyObject'), config.get('paramsObjectWBucket'));
}).not.toThrow()
});

Expand Down

0 comments on commit 4fe8908

Please sign in to comment.