Mobrovac has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/395498 )
Change subject: Update to service-template-node v0.5.4
......................................................................
Update to service-template-node v0.5.4
Bug: T181564
Change-Id: Ic7f59ffb0c325a9b2a8035edc6ab1faeced266c4
---
M .eslintrc.yml
M app.js
M lib/swagger-ui.js
M package.json
M test/features/app/app.js
M test/features/app/spec.js
M test/features/info/info.js
M test/utils/assert.js
M test/utils/logStream.js
M test/utils/server.js
10 files changed, 106 insertions(+), 98 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mathoid
refs/changes/98/395498/1
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 2cd5d61..312fdfd 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -1,6 +1 @@
extends: 'eslint-config-node-services'
-rules:
- indent:
- - error
- - 4
- - SwitchCase: 1
diff --git a/app.js b/app.js
index 7027a6d..9b1c0ec 100644
--- a/app.js
+++ b/app.js
@@ -17,7 +17,6 @@
const packageInfo = require('./package.json');
const yaml = require('js-yaml');
const addShutdown = require('http-shutdown');
-
const mjAPI = require("mathoid-mathjax-node/lib/mj-single.js");
@@ -155,7 +154,7 @@
/**
* Loads all routes declared in routes/ into the app
* @param {Application} app the application object to load routes into
- * @returns {bluebird} a promise resolving to the app object
+ * @return {bluebird} a promise resolving to the app object
*/
function loadRoutes(app) {
@@ -207,7 +206,7 @@
/**
* Creates and start the service's web server
* @param {Application} app the app object to use in the service
- * @returns {bluebird} a promise creating the web server
+ * @return {bluebird} a promise creating the web server
*/
function createServer(app) {
diff --git a/lib/swagger-ui.js b/lib/swagger-ui.js
index 9e39ff5..a85985c 100644
--- a/lib/swagger-ui.js
+++ b/lib/swagger-ui.js
@@ -33,7 +33,7 @@
.replace(/((?:src|href)=['"])/g, '$1?doc&path=')
// Some self-promotion
.replace(/<a id="logo".*?<\/a>/,
- `<a id="logo"
href="${app.info.homepage}">${app.info.name}</a>`)
+ `<a id="logo"
href="${app.info.homepage}">${app.info.name}</a>`)
.replace(/<title>[^<]*<\/title>/,
`<title>${app.info.name}</title>`)
// Replace the default url with ours, switch off validation &
// limit the size of documents to apply syntax highlighting to
diff --git a/package.json b/package.json
index e1feee7..7a3b0bb 100644
--- a/package.json
+++ b/package.json
@@ -6,11 +6,11 @@
"scripts": {
"start": "service-runner",
"test": "PREQ_CONNECT_TIMEOUT=15 mocha && nsp check",
+ "lint": "eslint --cache --max-warnings 0 --ext .js --ext .json .",
"docker-start": "service-runner docker-start",
"docker-test": "service-runner docker-test",
"test-build": "service-runner docker-test && service-runner build
--deploy-repo --force",
- "coverage": "istanbul cover _mocha -- -R spec",
- "coveralls": "cat ./coverage/lcov.info | coveralls"
+ "coverage": "istanbul cover _mocha -- -R spec"
},
"repository": {
"type": "git",
@@ -42,32 +42,32 @@
"bunyan": "^1.8.12",
"cassandra-uuid": "^0.0.2",
"compression": "^1.7.1",
- "core-js": "^2.4.1",
"express": "^4.16.2",
"http-shutdown": "^1.2.0",
"js-yaml": "^3.10.0",
"mathoid-mathjax-node": "^0.6.6",
"mathoid-mathjax": "2.5.4",
"mathoid-texvcjs": "0.3.2",
- "preq": "^0.5.3",
- "service-runner": "^2.4.2",
+ "preq": "^0.5.4",
+ "service-runner": "^2.4.7",
"svgo": "^0.7.1",
"swagger-router": "^0.7.1",
"swagger-ui": "git+https://github.com/wikimedia/swagger-ui#master",
"texvcinfo": "^0.4.2"
},
"devDependencies": {
+ "ajv": "^5.5.0",
"commander": "^2.9.0",
"dom-compare": "^0.2.1",
- "extend": "^3.0.0",
+ "extend": "^3.0.1",
"istanbul": "^0.4.5",
"mocha": "^4.0.1",
"mocha-jshint": "^2.3.1",
"mocha-lcov-reporter": "^1.3.0",
- "mocha-eslint": "^3.0.1",
- "eslint": "^3.12.0",
- "eslint-config-node-services": "^2.0.2",
- "eslint-config-wikimedia": "^0.4.0",
+ "mocha-eslint": "^4.1.0",
+ "eslint": "^4.12.0",
+ "eslint-config-node-services": "^2.2.5",
+ "eslint-config-wikimedia": "^0.5.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-jsdoc": "^3.0.0",
"nsp": "^2.8.1",
diff --git a/test/features/app/app.js b/test/features/app/app.js
index 3cdec05..c23bdca 100644
--- a/test/features/app/app.js
+++ b/test/features/app/app.js
@@ -1,3 +1,5 @@
+/* global describe, it, before, after */
+
'use strict';
diff --git a/test/features/app/spec.js b/test/features/app/spec.js
index 8e9846a..4629d68 100644
--- a/test/features/app/spec.js
+++ b/test/features/app/spec.js
@@ -1,3 +1,5 @@
+/* global describe, it, before, after */
+
'use strict';
@@ -212,8 +214,10 @@
}
}
// check that the body type is the same
- if(expRes.body.constructor !== res.body.constructor) {
- throw new Error('Expected a body of type ' + expRes.body.constructor +
' but gotten ' + res.body.constructor);
+ if (expRes.body.constructor !== res.body.constructor) {
+ throw new Error(
+ `Expected body type ${expRes.body.constructor} but got
${res.body.constructor}`
+ );
}
// compare the bodies
@@ -263,7 +267,7 @@
const path = spec.paths[pathStr];
assert.deepEqual(!!Object.keys(path), true, `No methods defined
for path: ${pathStr}`);
Object.keys(path).forEach((method) => {
- const mSpec = path[method];
+ const mSpec = path[method];
if ({}.hasOwnProperty.call(mSpec, 'x-monitor') &&
!mSpec['x-monitor']) {
return;
}
diff --git a/test/features/info/info.js b/test/features/info/info.js
index 38aeb8e..02767dd 100644
--- a/test/features/info/info.js
+++ b/test/features/info/info.js
@@ -1,3 +1,5 @@
+/* global describe, it, before, after */
+
'use strict';
@@ -12,12 +14,12 @@
describe('service information', function() {
- this.timeout(20000);
+ this.timeout(20000); // eslint-disable-line no-invalid-this
before(() => { return server.start(); });
// common URI prefix for info tests
- const infoUri = server.config.uri + '_info/';
+ const infoUri = `${server.config.uri}_info/`;
// common function used for generating requests
// and checking their return values
diff --git a/test/utils/assert.js b/test/utils/assert.js
index d26b336..390348c 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -1,7 +1,26 @@
+/* eslint-disable no-console */
+
'use strict';
-var assert = require('assert');
+const assert = require('assert');
+
+
+function deepEqual(result, expected, message) {
+
+ try {
+ if (typeof expected === 'string') {
+ assert.ok(result === expected || (new
RegExp(expected).test(result)));
+ } else {
+ assert.deepEqual(result, expected, message);
+ }
+ } catch (e) {
+ console.log(`Expected:\n${JSON.stringify(expected, null, 2)}`);
+ console.log(`Result:\n${JSON.stringify(result, null, 2)}`);
+ throw e;
+ }
+
+}
/**
@@ -10,7 +29,7 @@
function status(res, expected) {
deepEqual(res.status, expected,
- 'Expected status to be ' + expected + ', but was ' + res.status);
+ `Expected status to be ${expected}, but was ${res.status}`);
}
@@ -20,9 +39,9 @@
*/
function contentType(res, expected) {
- var actual = res.headers['content-type'];
+ const actual = res.headers['content-type'];
deepEqual(actual, expected,
- 'Expected content-type to be ' + expected + ', but was ' + actual);
+ `Expected content-type to be ${expected}, but was ${actual}`);
}
@@ -43,30 +62,13 @@
}
-function deepEqual(result, expected, message) {
-
- try {
- if (typeof expected === 'string') {
- assert.ok(result === expected || (new
RegExp(expected).test(result)));
- } else {
- assert.deepEqual(result, expected, message);
- }
- } catch (e) {
- console.log('Expected:\n' + JSON.stringify(expected, null, 2));
- console.log('Result:\n' + JSON.stringify(result, null, 2));
- throw e;
- }
-
-}
-
-
function notDeepEqual(result, expected, message) {
try {
assert.notDeepEqual(result, expected, message);
} catch (e) {
- console.log('Not expected:\n' + JSON.stringify(expected, null, 2));
- console.log('Result:\n' + JSON.stringify(result, null, 2));
+ console.log(`Not expected:\n${JSON.stringify(expected, null, 2)}`);
+ console.log(`Result:\n${JSON.stringify(result, null, 2)}`);
throw e;
}
@@ -75,7 +77,7 @@
function fails(promise, onRejected) {
- var failed = false;
+ let failed = false;
function trackFailure(e) {
failed = true;
diff --git a/test/utils/logStream.js b/test/utils/logStream.js
index f8e292d..3872fb7 100644
--- a/test/utils/logStream.js
+++ b/test/utils/logStream.js
@@ -1,68 +1,72 @@
+/* eslint-disable no-console */
+
'use strict';
-var bunyan = require('bunyan');
+const bunyan = require('bunyan');
function logStream(logStdout) {
- var log = [];
- var parrot = bunyan.createLogger({
- name: 'test-logger',
- level: 'warn'
- });
+ const log = [];
+ const parrot = bunyan.createLogger({
+ name: 'test-logger',
+ level: 'warn'
+ });
- function write(chunk, encoding, callback) {
- try {
- var entry = JSON.parse(chunk);
- var levelMatch = /^(\w+)/.exec(entry.levelPath);
- if (logStdout && levelMatch) {
- var level = levelMatch[1];
- if (parrot[level]) {
- parrot[level](entry);
+ function write(chunk, encoding, callback) {
+ try {
+ const entry = JSON.parse(chunk);
+ const levelMatch = /^(\w+)/.exec(entry.levelPath);
+ if (logStdout && levelMatch) {
+ const level = levelMatch[1];
+ if (parrot[level]) {
+ parrot[level](entry);
+ }
}
+ } catch (e) {
+ console.error('something went wrong trying to parrot a log entry',
e, chunk);
}
- } catch (e) {
- console.error('something went wrong trying to parrot a log entry', e,
chunk);
+
+ log.push(chunk);
}
- log.push(chunk);
- }
-
- // to implement the stream writer interface
- function end(chunk, encoding, callback) {
- }
-
- function get() {
- return log;
- }
-
- function slice() {
-
- var begin = log.length;
- var end = null;
-
- function halt() {
- if (end === null) {
- end = log.length;
- }
+ // to implement the stream writer interface
+ function end(chunk, encoding, callback) {
}
function get() {
- return log.slice(begin, end);
+ return log;
+ }
+
+ function slice() {
+
+ const begin = log.length;
+ let end = null;
+
+ function halt() {
+ if (end === null) {
+ end = log.length;
+ }
+ }
+
+ function get() {
+ return log.slice(begin, end);
+ }
+
+ /* Disable eslint object-shorthand until Node 4 support is dropped */
+ /* eslint-disable object-shorthand */
+ return {
+ halt: halt,
+ get: get
+ };
+
}
return {
- halt: halt,
- get: get
+ write: write,
+ end: end,
+ slice: slice,
+ get: get
};
-
- }
-
- return {
- write: write,
- end: end,
- slice: slice,
- get: get
- };
}
module.exports = logStream;
diff --git a/test/utils/server.js b/test/utils/server.js
index b3a2b75..8a67d3f 100644
--- a/test/utils/server.js
+++ b/test/utils/server.js
@@ -58,8 +58,8 @@
serviceReturns.forEach(servers =>
servers.forEach(server =>
server.shutdown()));
- return runner.stop().then(function () {
- module.exports.stop = function () {
+ return runner.stop().then(() => {
+ module.exports.stop = () => {
return BBPromise.resolve();
};
});
--
To view, visit https://gerrit.wikimedia.org/r/395498
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7f59ffb0c325a9b2a8035edc6ab1faeced266c4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mathoid
Gerrit-Branch: master
Gerrit-Owner: Mobrovac <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits