style: fix lint issues in code 🕺 (#626)
* style: fix lint issues in code 🕺 Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: lint fix all files Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore: add `keywords` for better reach Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add `husky` & `commitlint` Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore: ignore `public` directory Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * revert: do not lint `public` directory Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: fix issues with lint Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add eslint config Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add lint-staged Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: lint fix all file(s) Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * fix: ignore rules for light version Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * fix: remove unnecessary space Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore(deps): update lockfile Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: autofix linting issue(s) Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
const testTileJSONArray = function(url) {
|
||||
describe(url + ' is array of TileJSONs', function() {
|
||||
it('is json', function(done) {
|
||||
const testTileJSONArray = function (url) {
|
||||
describe(url + ' is array of TileJSONs', function () {
|
||||
it('is json', function (done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
.get(url)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
});
|
||||
|
||||
it('is non-empty array', function(done) {
|
||||
it('is non-empty array', function (done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(function(res) {
|
||||
expect(res.body).to.be.a('array');
|
||||
expect(res.body.length).to.be.greaterThan(0);
|
||||
}).end(done);
|
||||
.get(url)
|
||||
.expect(function (res) {
|
||||
expect(res.body).to.be.a('array');
|
||||
expect(res.body.length).to.be.greaterThan(0);
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const testTileJSON = function(url) {
|
||||
describe(url + ' is TileJSON', function() {
|
||||
it('is json', function(done) {
|
||||
const testTileJSON = function (url) {
|
||||
describe(url + ' is TileJSON', function () {
|
||||
it('is json', function (done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
.get(url)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
});
|
||||
|
||||
it('has valid tiles', function(done) {
|
||||
it('has valid tiles', function (done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(function(res) {
|
||||
expect(res.body.tiles.length).to.be.greaterThan(0);
|
||||
}).end(done);
|
||||
.get(url)
|
||||
.expect(function (res) {
|
||||
expect(res.body.tiles.length).to.be.greaterThan(0);
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe('Metadata', function() {
|
||||
describe('/health', function() {
|
||||
it('returns 200', function(done) {
|
||||
supertest(app)
|
||||
.get('/health')
|
||||
.expect(200, done);
|
||||
describe('Metadata', function () {
|
||||
describe('/health', function () {
|
||||
it('returns 200', function (done) {
|
||||
supertest(app).get('/health').expect(200, done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,24 +50,25 @@ describe('Metadata', function() {
|
||||
testTileJSONArray('/rendered.json');
|
||||
testTileJSONArray('/data.json');
|
||||
|
||||
describe('/styles.json is valid array', function() {
|
||||
it('is json', function(done) {
|
||||
describe('/styles.json is valid array', function () {
|
||||
it('is json', function (done) {
|
||||
supertest(app)
|
||||
.get('/styles.json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
.get('/styles.json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
});
|
||||
|
||||
it('contains valid item', function(done) {
|
||||
it('contains valid item', function (done) {
|
||||
supertest(app)
|
||||
.get('/styles.json')
|
||||
.expect(function(res) {
|
||||
expect(res.body).to.be.a('array');
|
||||
expect(res.body.length).to.be.greaterThan(0);
|
||||
expect(res.body[0].version).to.be.equal(8);
|
||||
expect(res.body[0].id).to.be.a('string');
|
||||
expect(res.body[0].name).to.be.a('string');
|
||||
}).end(done);
|
||||
.get('/styles.json')
|
||||
.expect(function (res) {
|
||||
expect(res.body).to.be.a('array');
|
||||
expect(res.body.length).to.be.greaterThan(0);
|
||||
expect(res.body[0].version).to.be.equal(8);
|
||||
expect(res.body[0].id).to.be.a('string');
|
||||
expect(res.body[0].name).to.be.a('string');
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
import {expect} from 'chai';
|
||||
import { expect } from 'chai';
|
||||
import supertest from 'supertest';
|
||||
import {server} from '../src/server.js';
|
||||
import { server } from '../src/server.js';
|
||||
|
||||
global.expect = expect;
|
||||
global.supertest = supertest;
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
console.log('global setup');
|
||||
process.chdir('test_data');
|
||||
const running = server({
|
||||
configPath: 'config.json',
|
||||
port: 8888,
|
||||
publicUrl: '/test/'
|
||||
publicUrl: '/test/',
|
||||
});
|
||||
global.app = running.app;
|
||||
global.server = running.server;
|
||||
return running.startupPromise;
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
console.log('global teardown');
|
||||
global.server.close(function() {
|
||||
console.log('Done'); process.exit();
|
||||
global.server.close(function () {
|
||||
console.log('Done');
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
|
||||
156
test/static.js
156
test/static.js
@@ -1,10 +1,10 @@
|
||||
const testStatic = function(prefix, q, format, status, scale, type, query) {
|
||||
const testStatic = function (prefix, q, format, status, scale, type, query) {
|
||||
if (scale) q += '@' + scale + 'x';
|
||||
let path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
||||
if (query) {
|
||||
path += query;
|
||||
}
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
it(path + ' returns ' + status, function (done) {
|
||||
const test = supertest(app).get(path);
|
||||
if (status) test.expect(status);
|
||||
if (type) test.expect('Content-Type', type);
|
||||
@@ -14,17 +14,45 @@ const testStatic = function(prefix, q, format, status, scale, type, query) {
|
||||
|
||||
const prefix = 'test-style';
|
||||
|
||||
describe('Static endpoints', function() {
|
||||
describe('center-based', function() {
|
||||
describe('valid requests', function() {
|
||||
describe('various formats', function() {
|
||||
testStatic(prefix, '0,0,0/256x256', 'png', 200, undefined, /image\/png/);
|
||||
testStatic(prefix, '0,0,0/256x256', 'jpg', 200, undefined, /image\/jpeg/);
|
||||
testStatic(prefix, '0,0,0/256x256', 'jpeg', 200, undefined, /image\/jpeg/);
|
||||
testStatic(prefix, '0,0,0/256x256', 'webp', 200, undefined, /image\/webp/);
|
||||
describe('Static endpoints', function () {
|
||||
describe('center-based', function () {
|
||||
describe('valid requests', function () {
|
||||
describe('various formats', function () {
|
||||
testStatic(
|
||||
prefix,
|
||||
'0,0,0/256x256',
|
||||
'png',
|
||||
200,
|
||||
undefined,
|
||||
/image\/png/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'0,0,0/256x256',
|
||||
'jpg',
|
||||
200,
|
||||
undefined,
|
||||
/image\/jpeg/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'0,0,0/256x256',
|
||||
'jpeg',
|
||||
200,
|
||||
undefined,
|
||||
/image\/jpeg/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'0,0,0/256x256',
|
||||
'webp',
|
||||
200,
|
||||
undefined,
|
||||
/image\/webp/,
|
||||
);
|
||||
});
|
||||
|
||||
describe('different parameters', function() {
|
||||
describe('different parameters', function () {
|
||||
testStatic(prefix, '0,0,0/300x300', 'png', 200, 2);
|
||||
testStatic(prefix, '0,0,0/300x300', 'png', 200, 3);
|
||||
|
||||
@@ -42,7 +70,7 @@ describe('Static endpoints', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid requests return 4xx', function() {
|
||||
describe('invalid requests return 4xx', function () {
|
||||
testStatic(prefix, '190,0,0/256x256', 'png', 400);
|
||||
testStatic(prefix, '0,86,0/256x256', 'png', 400);
|
||||
testStatic(prefix, '80,40,20/0x0', 'png', 400);
|
||||
@@ -57,16 +85,44 @@ describe('Static endpoints', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('area-based', function() {
|
||||
describe('valid requests', function() {
|
||||
describe('various formats', function() {
|
||||
testStatic(prefix, '-180,-80,180,80/10x10', 'png', 200, undefined, /image\/png/);
|
||||
testStatic(prefix, '-180,-80,180,80/10x10', 'jpg', 200, undefined, /image\/jpeg/);
|
||||
testStatic(prefix, '-180,-80,180,80/10x10', 'jpeg', 200, undefined, /image\/jpeg/);
|
||||
testStatic(prefix, '-180,-80,180,80/10x10', 'webp', 200, undefined, /image\/webp/);
|
||||
describe('area-based', function () {
|
||||
describe('valid requests', function () {
|
||||
describe('various formats', function () {
|
||||
testStatic(
|
||||
prefix,
|
||||
'-180,-80,180,80/10x10',
|
||||
'png',
|
||||
200,
|
||||
undefined,
|
||||
/image\/png/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'-180,-80,180,80/10x10',
|
||||
'jpg',
|
||||
200,
|
||||
undefined,
|
||||
/image\/jpeg/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'-180,-80,180,80/10x10',
|
||||
'jpeg',
|
||||
200,
|
||||
undefined,
|
||||
/image\/jpeg/,
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'-180,-80,180,80/10x10',
|
||||
'webp',
|
||||
200,
|
||||
undefined,
|
||||
/image\/webp/,
|
||||
);
|
||||
});
|
||||
|
||||
describe('different parameters', function() {
|
||||
describe('different parameters', function () {
|
||||
testStatic(prefix, '-180,-90,180,90/20x20', 'png', 200, 2);
|
||||
testStatic(prefix, '0,0,1,1/200x200', 'png', 200, 3);
|
||||
|
||||
@@ -74,7 +130,7 @@ describe('Static endpoints', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid requests return 4xx', function() {
|
||||
describe('invalid requests return 4xx', function () {
|
||||
testStatic(prefix, '0,87,1,88/5x2', 'png', 400);
|
||||
|
||||
testStatic(prefix, '0,0,1,1/1x1', 'gif', 400);
|
||||
@@ -83,20 +139,60 @@ describe('Static endpoints', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('autofit path', function() {
|
||||
describe('valid requests', function() {
|
||||
testStatic(prefix, 'auto/256x256', 'png', 200, undefined, /image\/png/, '?path=10,10|20,20');
|
||||
describe('autofit path', function () {
|
||||
describe('valid requests', function () {
|
||||
testStatic(
|
||||
prefix,
|
||||
'auto/256x256',
|
||||
'png',
|
||||
200,
|
||||
undefined,
|
||||
/image\/png/,
|
||||
'?path=10,10|20,20',
|
||||
);
|
||||
|
||||
describe('different parameters', function() {
|
||||
testStatic(prefix, 'auto/20x20', 'png', 200, 2, /image\/png/, '?path=10,10|20,20');
|
||||
testStatic(prefix, 'auto/200x200', 'png', 200, 3, /image\/png/, '?path=-10,-10|-20,-20');
|
||||
describe('different parameters', function () {
|
||||
testStatic(
|
||||
prefix,
|
||||
'auto/20x20',
|
||||
'png',
|
||||
200,
|
||||
2,
|
||||
/image\/png/,
|
||||
'?path=10,10|20,20',
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'auto/200x200',
|
||||
'png',
|
||||
200,
|
||||
3,
|
||||
/image\/png/,
|
||||
'?path=-10,-10|-20,-20',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid requests return 4xx', function() {
|
||||
describe('invalid requests return 4xx', function () {
|
||||
testStatic(prefix, 'auto/256x256', 'png', 400);
|
||||
testStatic(prefix, 'auto/256x256', 'png', 400, undefined, undefined, '?path=invalid');
|
||||
testStatic(prefix, 'auto/2560x2560', 'png', 400, undefined, undefined, '?path=10,10|20,20');
|
||||
testStatic(
|
||||
prefix,
|
||||
'auto/256x256',
|
||||
'png',
|
||||
400,
|
||||
undefined,
|
||||
undefined,
|
||||
'?path=invalid',
|
||||
);
|
||||
testStatic(
|
||||
prefix,
|
||||
'auto/2560x2560',
|
||||
'png',
|
||||
400,
|
||||
undefined,
|
||||
undefined,
|
||||
'?path=10,10|20,20',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,38 +1,41 @@
|
||||
const testIs = function(url, type, status) {
|
||||
it(url + ' return ' + (status || 200) + ' and is ' + type.toString(),
|
||||
function(done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(status || 200)
|
||||
.expect('Content-Type', type, done);
|
||||
});
|
||||
const testIs = function (url, type, status) {
|
||||
it(
|
||||
url + ' return ' + (status || 200) + ' and is ' + type.toString(),
|
||||
function (done) {
|
||||
supertest(app)
|
||||
.get(url)
|
||||
.expect(status || 200)
|
||||
.expect('Content-Type', type, done);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const prefix = 'test-style';
|
||||
|
||||
describe('Styles', function() {
|
||||
describe('/styles/' + prefix + '/style.json is valid style', function() {
|
||||
describe('Styles', function () {
|
||||
describe('/styles/' + prefix + '/style.json is valid style', function () {
|
||||
testIs('/styles/' + prefix + '/style.json', /application\/json/);
|
||||
|
||||
it('contains expected properties', function(done) {
|
||||
it('contains expected properties', function (done) {
|
||||
supertest(app)
|
||||
.get('/styles/' + prefix + '/style.json')
|
||||
.expect(function(res) {
|
||||
expect(res.body.version).to.be.equal(8);
|
||||
expect(res.body.name).to.be.a('string');
|
||||
expect(res.body.sources).to.be.a('object');
|
||||
expect(res.body.glyphs).to.be.a('string');
|
||||
expect(res.body.sprite).to.be.a('string');
|
||||
expect(res.body.sprite).to.be.equal('/test/styles/test-style/sprite');
|
||||
expect(res.body.layers).to.be.a('array');
|
||||
}).end(done);
|
||||
.get('/styles/' + prefix + '/style.json')
|
||||
.expect(function (res) {
|
||||
expect(res.body.version).to.be.equal(8);
|
||||
expect(res.body.name).to.be.a('string');
|
||||
expect(res.body.sources).to.be.a('object');
|
||||
expect(res.body.glyphs).to.be.a('string');
|
||||
expect(res.body.sprite).to.be.a('string');
|
||||
expect(res.body.sprite).to.be.equal('/test/styles/test-style/sprite');
|
||||
expect(res.body.layers).to.be.a('array');
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
describe('/styles/streets/style.json is not served', function() {
|
||||
describe('/styles/streets/style.json is not served', function () {
|
||||
testIs('/styles/streets/style.json', /./, 404);
|
||||
});
|
||||
|
||||
describe('/styles/' + prefix + '/sprite[@2x].{format}', function() {
|
||||
describe('/styles/' + prefix + '/sprite[@2x].{format}', function () {
|
||||
testIs('/styles/' + prefix + '/sprite.json', /application\/json/);
|
||||
testIs('/styles/' + prefix + '/sprite@2x.json', /application\/json/);
|
||||
testIs('/styles/' + prefix + '/sprite.png', /image\/png/);
|
||||
@@ -40,11 +43,13 @@ describe('Styles', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Fonts', function() {
|
||||
describe('Fonts', function () {
|
||||
testIs('/fonts/Open Sans Bold/0-255.pbf', /application\/x-protobuf/);
|
||||
testIs('/fonts/Open Sans Regular/65280-65535.pbf', /application\/x-protobuf/);
|
||||
testIs('/fonts/Open Sans Bold,Open Sans Regular/0-255.pbf',
|
||||
/application\/x-protobuf/);
|
||||
testIs(
|
||||
'/fonts/Open Sans Bold,Open Sans Regular/0-255.pbf',
|
||||
/application\/x-protobuf/,
|
||||
);
|
||||
testIs('/fonts/Nonsense,Open Sans Bold/0-255.pbf', /./, 400);
|
||||
|
||||
testIs('/fonts/Nonsense/0-255.pbf', /./, 400);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const testTile = function(prefix, z, x, y, status) {
|
||||
const testTile = function (prefix, z, x, y, status) {
|
||||
const path = '/data/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
it(path + ' returns ' + status, function (done) {
|
||||
const test = supertest(app).get(path);
|
||||
if (status) test.expect(status);
|
||||
if (status == 200) test.expect('Content-Type', /application\/x-protobuf/);
|
||||
@@ -10,13 +10,13 @@ const testTile = function(prefix, z, x, y, status) {
|
||||
|
||||
const prefix = 'openmaptiles';
|
||||
|
||||
describe('Vector tiles', function() {
|
||||
describe('existing tiles', function() {
|
||||
describe('Vector tiles', function () {
|
||||
describe('existing tiles', function () {
|
||||
testTile(prefix, 0, 0, 0, 200);
|
||||
testTile(prefix, 14, 8581, 5738, 200);
|
||||
});
|
||||
|
||||
describe('non-existent requests return 4xx', function() {
|
||||
describe('non-existent requests return 4xx', function () {
|
||||
testTile('non_existent', 0, 0, 0, 404);
|
||||
testTile(prefix, -1, 0, 0, 404); // err zoom
|
||||
testTile(prefix, 20, 0, 0, 404); // zoom out of bounds
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const testTile = function(prefix, z, x, y, format, status, scale, type) {
|
||||
const testTile = function (prefix, z, x, y, format, status, scale, type) {
|
||||
if (scale) y += '@' + scale + 'x';
|
||||
const path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
it(path + ' returns ' + status, function (done) {
|
||||
const test = supertest(app).get(path);
|
||||
test.expect(status);
|
||||
if (type) test.expect('Content-Type', type);
|
||||
@@ -11,16 +11,16 @@ const testTile = function(prefix, z, x, y, format, status, scale, type) {
|
||||
|
||||
const prefix = 'test-style';
|
||||
|
||||
describe('Raster tiles', function() {
|
||||
describe('valid requests', function() {
|
||||
describe('various formats', function() {
|
||||
describe('Raster tiles', function () {
|
||||
describe('valid requests', function () {
|
||||
describe('various formats', function () {
|
||||
testTile(prefix, 0, 0, 0, 'png', 200, undefined, /image\/png/);
|
||||
testTile(prefix, 0, 0, 0, 'jpg', 200, undefined, /image\/jpeg/);
|
||||
testTile(prefix, 0, 0, 0, 'jpeg', 200, undefined, /image\/jpeg/);
|
||||
testTile(prefix, 0, 0, 0, 'webp', 200, undefined, /image\/webp/);
|
||||
});
|
||||
|
||||
describe('different coordinates and scales', function() {
|
||||
describe('different coordinates and scales', function () {
|
||||
testTile(prefix, 1, 1, 1, 'png', 200);
|
||||
|
||||
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
||||
@@ -29,7 +29,7 @@ describe('Raster tiles', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid requests return 4xx', function() {
|
||||
describe('invalid requests return 4xx', function () {
|
||||
testTile('non_existent', 0, 0, 0, 'png', 404);
|
||||
testTile(prefix, -1, 0, 0, 'png', 404);
|
||||
testTile(prefix, 25, 0, 0, 'png', 404);
|
||||
|
||||
Reference in New Issue
Block a user