Update eslint & config to latest major versions

This commit is contained in:
Miroslav Bajtoš 2019-02-05 08:57:18 +01:00
parent 94b12fb52c
commit 87dec34709
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
7 changed files with 96 additions and 88 deletions

View File

@ -0,0 +1,2 @@
public
coverage

View File

@ -3,24 +3,26 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var g = require('strong-globalize')(); 'use strict';
var loopback = require('loopback'); const g = require('strong-globalize')();
var app = loopback();
var explorer = require('../');
var port = 3000;
var User = loopback.Model.extend('user', { const loopback = require('loopback');
const app = loopback();
const explorer = require('../');
const port = 3000;
const User = loopback.Model.extend('user', {
username: 'string', username: 'string',
email: 'string', email: 'string',
sensitiveInternalProperty: 'string', sensitiveInternalProperty: 'string',
}, { hidden: ['sensitiveInternalProperty'] }); }, {hidden: ['sensitiveInternalProperty']});
User.attachTo(loopback.memory()); User.attachTo(loopback.memory());
app.model(User); app.model(User);
var apiPath = '/api'; const apiPath = '/api';
explorer(app, { basePath: apiPath }); explorer(app, {basePath: apiPath});
app.use(apiPath, loopback.rest()); app.use(apiPath, loopback.rest());
g.log('{{Explorer}} mounted at {{localhost:%s/explorer}}', port); g.log('{{Explorer}} mounted at {{localhost:%s/explorer}}', port);

View File

@ -3,23 +3,25 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var g = require('strong-globalize')(); 'use strict';
var loopback = require('loopback'); const g = require('strong-globalize')();
var app = loopback();
var explorer = require('../');
var port = 3000;
var Product = loopback.PersistedModel.extend('product', { const loopback = require('loopback');
foo: { type: 'string', required: true }, const app = loopback();
const explorer = require('../');
const port = 3000;
const Product = loopback.PersistedModel.extend('product', {
foo: {type: 'string', required: true},
bar: 'string', bar: 'string',
aNum: { type: 'number', min: 1, max: 10, required: true, default: 5 }, aNum: {type: 'number', min: 1, max: 10, required: true, default: 5},
}); });
Product.attachTo(loopback.memory()); Product.attachTo(loopback.memory());
app.model(Product); app.model(Product);
var apiPath = '/api'; const apiPath = '/api';
explorer(app, { basePath: apiPath }); explorer(app, {basePath: apiPath});
app.use(apiPath, loopback.rest()); app.use(apiPath, loopback.rest());
g.log('{{Explorer}} mounted at {{http://localhost:%s/explorer}}', port); g.log('{{Explorer}} mounted at {{http://localhost:%s/explorer}}', port);

View File

@ -5,20 +5,20 @@
'use strict'; 'use strict';
var SG = require('strong-globalize'); const SG = require('strong-globalize');
SG.SetRootDir(__dirname); SG.SetRootDir(__dirname);
var g = SG(); const g = SG();
/*! /*!
* Adds dynamically-updated docs as /explorer * Adds dynamically-updated docs as /explorer
*/ */
var url = require('url'); const url = require('url');
var path = require('path'); const path = require('path');
var urlJoin = require('./lib/url-join'); const urlJoin = require('./lib/url-join');
var _defaults = require('lodash').defaults; const _defaults = require('lodash').defaults;
var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec; const createSwaggerObject = require('loopback-swagger').generateSwaggerSpec;
var SWAGGER_UI_ROOT = require('swagger-ui/index').dist; const SWAGGER_UI_ROOT = require('swagger-ui/index').dist;
var STATIC_ROOT = path.join(__dirname, 'public'); const STATIC_ROOT = path.join(__dirname, 'public');
module.exports = explorer; module.exports = explorer;
explorer.routes = routes; explorer.routes = routes;
@ -31,7 +31,7 @@ explorer.routes = routes;
*/ */
function explorer(loopbackApplication, options) { function explorer(loopbackApplication, options) {
options = _defaults({}, options, { mountPath: '/explorer' }); options = _defaults({}, options, {mountPath: '/explorer'});
loopbackApplication.use( loopbackApplication.use(
options.mountPath, options.mountPath,
routes(loopbackApplication, options) routes(loopbackApplication, options)
@ -40,8 +40,8 @@ function explorer(loopbackApplication, options) {
} }
function routes(loopbackApplication, options) { function routes(loopbackApplication, options) {
var loopback = loopbackApplication.loopback; const loopback = loopbackApplication.loopback;
var loopbackMajor = const loopbackMajor =
(loopback && loopback.version && loopback.version.split('.')[0]) || 1; (loopback && loopback.version && loopback.version.split('.')[0]) || 1;
if (loopbackMajor < 2) { if (loopbackMajor < 2) {
@ -59,7 +59,7 @@ function routes(loopbackApplication, options) {
swaggerUI: true, swaggerUI: true,
}); });
var router = new loopback.Router(); const router = new loopback.Router();
mountSwagger(loopbackApplication, router, options); mountSwagger(loopbackApplication, router, options);
@ -68,7 +68,7 @@ function routes(loopbackApplication, options) {
router.get('/config.json', function(req, res) { router.get('/config.json', function(req, res) {
// Get the path we're mounted at. It's best to get this from the referer // Get the path we're mounted at. It's best to get this from the referer
// in case we're proxied at a deep path. // in case we're proxied at a deep path.
var source = url.parse(req.headers.referer || '').pathname; let source = url.parse(req.headers.referer || '').pathname;
// strip index.html if present in referer // strip index.html if present in referer
if (source && /\/index\.html$/.test(source)) { if (source && /\/index\.html$/.test(source)) {
source = source.replace(/\/index\.html$/, ''); source = source.replace(/\/index\.html$/, '');
@ -118,7 +118,7 @@ function routes(loopbackApplication, options) {
* @param {Object} opts Options. * @param {Object} opts Options.
*/ */
function mountSwagger(loopbackApplication, swaggerApp, opts) { function mountSwagger(loopbackApplication, swaggerApp, opts) {
var swaggerObject = createSwaggerObject(loopbackApplication, opts); let swaggerObject = createSwaggerObject(loopbackApplication, opts);
// listening to modelRemoted event for updating the swaggerObject // listening to modelRemoted event for updating the swaggerObject
// with the newly created model to appear in the Swagger UI. // with the newly created model to appear in the Swagger UI.
@ -135,7 +135,7 @@ function mountSwagger(loopbackApplication, swaggerApp, opts) {
// when a remote method is disabled to hide that method in the Swagger UI. // when a remote method is disabled to hide that method in the Swagger UI.
loopbackApplication.on('remoteMethodDisabled', rebuildSwaggerObject); loopbackApplication.on('remoteMethodDisabled', rebuildSwaggerObject);
var resourcePath = (opts && opts.resourcePath) || 'swagger.json'; let resourcePath = (opts && opts.resourcePath) || 'swagger.json';
if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath; if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath;
swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) { swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) {

View File

@ -8,6 +8,6 @@
// Simple url joiner. Ensure we don't have to care about whether or not // Simple url joiner. Ensure we don't have to care about whether or not
// we are fed paths with leading/trailing slashes. // we are fed paths with leading/trailing slashes.
module.exports = function urlJoin() { module.exports = function urlJoin() {
var args = Array.prototype.slice.call(arguments); const args = Array.prototype.slice.call(arguments);
return args.join('/').replace(/\/+/g, '/'); return args.join('/').replace(/\/+/g, '/');
}; };

View File

@ -27,8 +27,8 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^3.2.0", "chai": "^3.2.0",
"eslint": "^2.13.1", "eslint": "^5.13.0",
"eslint-config-loopback": "^2.0.0", "eslint-config-loopback": "^13.0.0",
"loopback": "^3.19.0", "loopback": "^3.19.0",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"supertest": "^3.1.0" "supertest": "^3.1.0"

View File

@ -3,14 +3,16 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var loopback = require('loopback'); 'use strict';
var explorer = require('../');
var request = require('supertest'); const loopback = require('loopback');
var assert = require('assert'); const explorer = require('../');
var path = require('path'); const request = require('supertest');
var expect = require('chai').expect; const assert = require('assert');
var urlJoin = require('../lib/url-join'); const path = require('path');
var os = require('os'); const expect = require('chai').expect;
const urlJoin = require('../lib/url-join');
const os = require('os');
describe('explorer', function() { describe('explorer', function() {
describe('with default config', function() { describe('with default config', function() {
@ -18,7 +20,7 @@ describe('explorer', function() {
it('should register "loopback-component-explorer" to the app', function() { it('should register "loopback-component-explorer" to the app', function() {
expect(this.app.get('loopback-component-explorer')) expect(this.app.get('loopback-component-explorer'))
.to.have.property('mountPath', '/explorer'); .to.have.property('mountPath', '/explorer');
}); });
it('should redirect to /explorer/', function(done) { it('should redirect to /explorer/', function(done) {
@ -99,7 +101,7 @@ describe('explorer', function() {
it('should register "loopback-component-explorer" to the app', function() { it('should register "loopback-component-explorer" to the app', function() {
expect(this.app.get('loopback-component-explorer')) expect(this.app.get('loopback-component-explorer'))
.to.have.property('mountPath', '/swagger'); .to.have.property('mountPath', '/swagger');
}); });
it('should serve correct swagger-ui config', function(done) { it('should serve correct swagger-ui config', function(done) {
@ -120,9 +122,9 @@ describe('explorer', function() {
describe('with custom app.restApiRoot', function() { describe('with custom app.restApiRoot', function() {
it('should serve correct swagger-ui config', function(done) { it('should serve correct swagger-ui config', function(done) {
var app = loopback(); const app = loopback();
app.set('restApiRoot', '/rest-api-root'); app.set('restApiRoot', '/rest-api-root');
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app); configureRestApiAndExplorer(app);
request(app) request(app)
@ -142,9 +144,9 @@ describe('explorer', function() {
// SwaggerUI builds resource URL by concatenating basePath + resourcePath // SwaggerUI builds resource URL by concatenating basePath + resourcePath
// Since the resource paths are always startign with a slash, // Since the resource paths are always startign with a slash,
// if the basePath ends with a slash too, an incorrect URL is produced // if the basePath ends with a slash too, an incorrect URL is produced
var app = loopback(); const app = loopback();
app.set('restApiRoot', '/apis/'); app.set('restApiRoot', '/apis/');
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app); configureRestApiAndExplorer(app);
request(app) request(app)
@ -153,8 +155,8 @@ describe('explorer', function() {
.end(function(err, res) { .end(function(err, res) {
if (err) return done(err); if (err) return done(err);
var baseUrl = res.body.basePath; const baseUrl = res.body.basePath;
var apiPath = Object.keys(res.body.paths)[0]; const apiPath = Object.keys(res.body.paths)[0];
expect(baseUrl + apiPath).to.equal('/apis/products'); expect(baseUrl + apiPath).to.equal('/apis/products');
done(); done();
@ -163,10 +165,10 @@ describe('explorer', function() {
}); });
describe('with custom front-end files', function() { describe('with custom front-end files', function() {
var app; let app;
beforeEach(function setupExplorerWithUiDirs() { beforeEach(function setupExplorerWithUiDirs() {
app = loopback(); app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
explorer(app, { explorer(app, {
uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')], uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')],
}); });
@ -189,7 +191,7 @@ describe('explorer', function() {
request(app).get('/explorer/') request(app).get('/explorer/')
.expect(200) .expect(200)
.end(function(err, res) { .end(function(err, res) {
if (err) return done(er); if (err) return done(err);
// expect the content of `dummy-swagger-ui/index.html` // expect the content of `dummy-swagger-ui/index.html`
expect(res.text).to.contain('custom index.html'); expect(res.text).to.contain('custom index.html');
done(); done();
@ -198,10 +200,10 @@ describe('explorer', function() {
}); });
describe('with swaggerUI option', function() { describe('with swaggerUI option', function() {
var app; let app;
beforeEach(function setupExplorerWithoutUI() { beforeEach(function setupExplorerWithoutUI() {
app = loopback(); app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
explorer(app, { explorer(app, {
swaggerUI: false, swaggerUI: false,
}); });
@ -234,11 +236,11 @@ describe('explorer', function() {
}); });
describe('explorer.routes API', function() { describe('explorer.routes API', function() {
var app; let app;
beforeEach(function() { beforeEach(function() {
app = loopback(); app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
var Product = loopback.PersistedModel.extend('product'); const Product = loopback.PersistedModel.extend('product');
Product.attachTo(loopback.memory()); Product.attachTo(loopback.memory());
app.model(Product); app.model(Product);
}); });
@ -256,10 +258,10 @@ describe('explorer', function() {
}); });
describe('when specifying custom static file root directories', function() { describe('when specifying custom static file root directories', function() {
var app; let app;
beforeEach(function() { beforeEach(function() {
app = loopback(); app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
}); });
it('should allow `uiDirs` to be defined as an Array', function(done) { it('should allow `uiDirs` to be defined as an Array', function(done) {
@ -294,8 +296,8 @@ describe('explorer', function() {
}); });
it('updates swagger object when a new model is added', function(done) { it('updates swagger object when a new model is added', function(done) {
var app = loopback(); const app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app, '/explorer'); configureRestApiAndExplorer(app, '/explorer');
// Ensure the swagger object was built // Ensure the swagger object was built
@ -306,7 +308,7 @@ describe('explorer', function() {
if (err) return done(err); if (err) return done(err);
// Create a new model // Create a new model
var Model = loopback.PersistedModel.extend('Customer'); const Model = loopback.PersistedModel.extend('Customer');
Model.attachTo(loopback.memory()); Model.attachTo(loopback.memory());
app.model(Model); app.model(Model);
@ -317,9 +319,9 @@ describe('explorer', function() {
.end(function(err, res) { .end(function(err, res) {
if (err) return done(err); if (err) return done(err);
var modelNames = Object.keys(res.body.definitions); const modelNames = Object.keys(res.body.definitions);
expect(modelNames).to.contain('Customer'); expect(modelNames).to.contain('Customer');
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.have.contain('/Customers'); expect(paths).to.have.contain('/Customers');
done(); done();
@ -328,11 +330,11 @@ describe('explorer', function() {
}); });
it('updates swagger object when a model is removed', function(done) { it('updates swagger object when a model is removed', function(done) {
var app = loopback(); const app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app, '/explorer'); configureRestApiAndExplorer(app, '/explorer');
var Model = loopback.PersistedModel.extend('Customer'); const Model = loopback.PersistedModel.extend('Customer');
Model.attachTo(loopback.memory()); Model.attachTo(loopback.memory());
app.model(Model); app.model(Model);
@ -352,9 +354,9 @@ describe('explorer', function() {
.end(function(err, res) { .end(function(err, res) {
if (err) return done(err); if (err) return done(err);
var modelNames = Object.keys(res.body.definitions); const modelNames = Object.keys(res.body.definitions);
expect(modelNames).to.not.contain('Customer'); expect(modelNames).to.not.contain('Customer');
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.not.contain('/Customers'); expect(paths).to.not.contain('/Customers');
done(); done();
@ -363,8 +365,8 @@ describe('explorer', function() {
}); });
it('updates swagger object when a remote method is disabled', function(done) { it('updates swagger object when a remote method is disabled', function(done) {
var app = loopback(); const app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app, '/explorer'); configureRestApiAndExplorer(app, '/explorer');
// Ensure the swagger object was built // Ensure the swagger object was built
@ -375,10 +377,10 @@ describe('explorer', function() {
if (err) return done(err); if (err) return done(err);
// Check the method that will be disabled // Check the method that will be disabled
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.contain('/products/findOne'); expect(paths).to.contain('/products/findOne');
var Product = app.models.Product; const Product = app.models.Product;
Product.disableRemoteMethodByName('findOne'); Product.disableRemoteMethodByName('findOne');
// Request swagger.json again // Request swagger.json again
@ -388,7 +390,7 @@ describe('explorer', function() {
.end(function(err, res) { .end(function(err, res) {
if (err) return done(err); if (err) return done(err);
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.not.contain('/products/findOne'); expect(paths).to.not.contain('/products/findOne');
done(); done();
@ -397,8 +399,8 @@ describe('explorer', function() {
}); });
it('updates swagger object when a remote method is added', function(done) { it('updates swagger object when a remote method is added', function(done) {
var app = loopback(); const app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app, '/explorer'); configureRestApiAndExplorer(app, '/explorer');
// Ensure the swagger object was built // Ensure the swagger object was built
@ -409,10 +411,10 @@ describe('explorer', function() {
if (err) return done(err); if (err) return done(err);
// Check the method that will be disabled // Check the method that will be disabled
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.contain('/products/findOne'); expect(paths).to.contain('/products/findOne');
var Product = app.models.Product; const Product = app.models.Product;
Product.findOne2 = function(cb) { cb(null, 1); }; Product.findOne2 = function(cb) { cb(null, 1); };
Product.remoteMethod('findOne2', {}); Product.remoteMethod('findOne2', {});
@ -423,7 +425,7 @@ describe('explorer', function() {
.end(function(err, res) { .end(function(err, res) {
if (err) return done(err); if (err) return done(err);
var paths = Object.keys(res.body.paths); const paths = Object.keys(res.body.paths);
expect(paths).to.contain('/products/findOne2'); expect(paths).to.contain('/products/findOne2');
done(); done();
@ -433,8 +435,8 @@ describe('explorer', function() {
function givenLoopBackAppWithExplorer(explorerBase) { function givenLoopBackAppWithExplorer(explorerBase) {
return function(done) { return function(done) {
var app = this.app = loopback(); const app = this.app = loopback();
app.set('remoting', { cors: false }); app.set('remoting', {cors: false});
configureRestApiAndExplorer(app, explorerBase); configureRestApiAndExplorer(app, explorerBase);
done(); done();
@ -442,11 +444,11 @@ describe('explorer', function() {
} }
function configureRestApiAndExplorer(app, explorerBase) { function configureRestApiAndExplorer(app, explorerBase) {
var Product = loopback.PersistedModel.extend('product'); const Product = loopback.PersistedModel.extend('product');
Product.attachTo(loopback.memory()); Product.attachTo(loopback.memory());
app.model(Product); app.model(Product);
explorer(app, { mountPath: explorerBase }); explorer(app, {mountPath: explorerBase});
app.set('legacyExplorer', false); app.set('legacyExplorer', false);
app.use(app.get('restApiRoot') || '/', loopback.rest()); app.use(app.get('restApiRoot') || '/', loopback.rest());
} }