Skip to content

Commit a9a7887

Browse files
author
cfernandes
committed
fix gulp lint and gulp test
- disable istanbul's code coverage reporting as it cannot handle async-await - write a sample test
1 parent 28512c4 commit a9a7887

16 files changed

+483
-475
lines changed

.eslintrc

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@
5252
}
5353
],
5454
"no-inline-comments": 2,
55-
"space-before-blocks": 2
55+
"space-before-blocks": 2,
56+
"no-unused-vars": ["error", { "varsIgnorePattern": "colors" }]
5657
},
5758
"env": {
5859
"es6": true,
59-
"node": true
60+
"node": true,
61+
"mocha": true
6062
},
6163
"parserOptions": {
62-
"ecmaVersion": 8
64+
"ecmaVersion": 2017
6365
},
64-
"extends": "eslint:recommended"
66+
"extends": ["eslint:recommended"]
6567
}

bin/operations/backup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const fs = require('fs');
33
const {dissoc, merge, compose} = require('ramda');
44
const colors = require('colors');
5-
const kongContext = require('../../kong/context');
6-
const kongApi = require('../../kong/index');
5+
const kongContext = require('../../lib/kong/context');
6+
const kongApi = require('../../lib/kong/index');
77

88
module.exports = async function backup(filename, url, username, password) {
99
let adjustedFileName = 'kong-backup.json';

bin/operations/synchronization.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const colors = require('colors');
44
const {promisify} = require('util');
55
const readFile = promisify(fs.readFile);
66
const {differenceWith, filter}= require('ramda');
7-
const kongContext = require('../../kong/context');
8-
const kongApi = require('../../kong/index');
7+
const kongContext = require('../../lib/kong/context');
8+
const kongApi = require('../../lib/kong/index');
99

1010
module.exports = async function synchronization(filename, url, username, password, synchBasicAuthCreds) {
1111
function apiHasValidUrl(apiObject) {
@@ -46,7 +46,7 @@ module.exports = async function synchronization(filename, url, username, passwor
4646
const serverSNIs = await kong.snis.allSNIs();
4747
const serverCertificates = await kong.certificates.allCertificates();
4848

49-
const delay = millis => new Promise(resolve => setTimeout(_ => resolve(), millis));
49+
const delay = millis => new Promise(resolve => setTimeout(() => resolve(), millis));
5050
const waitTimeInMs = 3000;
5151

5252
const entityIdComparator = (aEntity, bEntity) => aEntity.id === bEntity.id;

bin/operations/teardown.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const colors = require('colors');
4-
const kongContext = require('../../kong/context');
5-
const kongApi = require('../../kong/index');
4+
const kongContext = require('../../lib/kong/context');
5+
const kongApi = require('../../lib/kong/index');
66

77
module.exports = async function teardown(url, username, password) {
88
try {

bin/skull-island.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
'use strict';
44

5-
const fs = require('fs');
65
const cli = require('commander');
76
const colors = require('colors');
87
const {version} = require('../package.json');

gulpfile.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,30 @@ const istanbul = require('gulp-istanbul');
66
const gutil = require('gulp-util');
77
const eslint = require('gulp-eslint');
88

9-
const sourceFiles = ['index.js', 'lib/**/*.js', 'bin/index.js'];
9+
const sourceFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.js'];
1010
const testSourceFiles = ['test/**/**.spec.js'];
1111
const allSourceFiles = sourceFiles.concat(testSourceFiles);
1212

1313
gulp.task('test', done => {
1414
gulp.src(sourceFiles)
15-
.pipe(istanbul()) // Covering files
16-
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
15+
// .pipe(istanbul()) // Covering files
16+
// .pipe(istanbul.hookRequire()) // Force `require` to return covered files
1717
.on('finish', function () {
1818
return gulp.src(testSourceFiles)
1919
.pipe(mocha())
2020
.on('error', gutil.log)
21-
.pipe(istanbul.writeReports()) // Creating the reports after tests ran
22-
.pipe(istanbul.enforceThresholds({thresholds: {global: 100}})) // Enforce a coverage of at least 100%
21+
// .pipe(istanbul.writeReports()) // Creating the reports after tests ran
22+
// .pipe(istanbul.enforceThresholds({thresholds: {global: 100}})) // Enforce a coverage of at least 100%
2323
.on('end', done);
24-
2524
})
2625
.on('error', gutil.log);
2726
});
2827

2928
gulp.task('lint', _ => {
3029
return gulp.src(allSourceFiles)
31-
.pipe(eslint())
30+
.pipe(eslint({fix: true}))
3231
.pipe(eslint.format())
3332
.pipe(eslint.failAfterError());
3433
});
3534

36-
gulp.task('default', ['lint']);
35+
gulp.task('default', ['lint', 'test']);

kong/context.js renamed to lib/kong/context.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const request = require('request-promise-native');
24
const {merge, mergeDeepLeft, compose} = require('ramda');
35

kong/entities/apis.js renamed to lib/kong/entities/apis.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"use strict";
1+
'use strict';
2+
23
const {prop, merge} = require('ramda');
34

45
module.exports = function kongApis(connectionContext) {
@@ -17,7 +18,7 @@ module.exports = function kongApis(connectionContext) {
1718
// if a user manually edits the configuration JSON and does not provide an ID, then attempt
1819
// a synchronization by looking at the server and obtaining the APIs ID from there
1920
if (!apiData.id) {
20-
const apiDataFromServer = await api(apiData.name).catch(_ => undefined);
21+
const apiDataFromServer = await api(apiData.name).catch(() => undefined);
2122
// the API does not even exist on the server
2223
if (!apiDataFromServer) {
2324
return createOrUpdateAdminRequest('apis', apiData);
File renamed without changes.

kong/entities/consumers.js renamed to lib/kong/entities/consumers.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"use strict";
1+
'use strict';
2+
23
const {prop, merge, mergeAll, mergeDeepLeft, assoc, dissoc, pickBy, keys, reduce} = require('ramda');
34

45
module.exports = function kongConsumers(connectionContext) {
@@ -11,7 +12,7 @@ module.exports = function kongConsumers(connectionContext) {
1112
const futureAllTopicsForConsumer = Promise.all(
1213
authPlugins.map(eachTopic =>
1314
consumerDetails(eachConsumer.id, eachTopic)
14-
.catch(_ => [])
15+
.catch(() => [])
1516
.then(eachTopicData => assoc(eachTopic, eachTopicData, {}))
1617
)
1718
);
@@ -85,7 +86,7 @@ module.exports = function kongConsumers(connectionContext) {
8586
});
8687
}
8788

88-
const criteria = (value, key) => value.length > 0;
89+
const criteria = value => value.length > 0;
8990
const credentialPlugins = consumerDataWithCredentials.credentials;
9091
let filteredCredentialPlugins = pickBy(criteria, credentialPlugins);
9192

kong/entities/plugins.js renamed to lib/kong/entities/plugins.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const {prop, has} = require('ramda');
34

45
module.exports = function kongPlugins(connectionContext) {

kong/entities/snis.js renamed to lib/kong/entities/snis.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function kongSNIs(connectionContext) {
2020
console.log(`Error creating SNI: ${sniData.name} (most likely because it already exists)`, err.data.message);
2121
return undefined;
2222
});
23-
const search = await sni(sniDataWithTime.name).catch(_ => undefined);
23+
const search = await sni(sniDataWithTime.name).catch(() => undefined);
2424
// PUT on a non-existent SNI will say everything is fine but really you need
2525
// to check if the object is present and follow up with a POST if it is not
2626
if (!search) {

kong/index.js renamed to lib/kong/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const kongApis = require('./entities/apis');
34
const kongPlugins = require('./entities/plugins');
45
const kongConsumers = require('./entities/consumers');

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
"request-promise-native": "^1.0.4"
4444
},
4545
"devDependencies": {
46+
"chai": "^4.0.2",
47+
"docker-compose-mocha": "^1.0.11",
4648
"gulp": "^3.9.1",
47-
"gulp-eslint": "^2.1.0",
48-
"gulp-istanbul": "^0.10.4",
49-
"gulp-mocha": "^2.1.3",
50-
"gulp-util": "^3.0.6",
49+
"gulp-eslint": "^4.0.0",
50+
"gulp-istanbul": "^1.1.2",
51+
"gulp-mocha": "^4.3.1",
52+
"gulp-util": "^3.0.8",
5153
"jscs-stylish": "^0.3.1",
5254
"jshint-stylish": "^2.0.1",
5355
"mocha": "^3.4.2"
5456
}
55-
}
57+
}

test/api.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const chai = require('chai');
4+
const expect = chai.expect;
5+
6+
describe('Kong API Object Specification', () => {
7+
it('must be able to create an API', () => {
8+
expect(1).to.equal(1);
9+
});
10+
});

0 commit comments

Comments
 (0)