-
Notifications
You must be signed in to change notification settings - Fork 711
test: expand coverage for fonts, vector tiles, raster tiles, and style URLs #2253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
navidnabavi
wants to merge
3
commits into
maptiler:master
Choose a base branch
from
navidnabavi:test/expand-font-data-rendered-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| describe('Fonts', function () { | ||
| describe('/fonts.json', function () { | ||
| it('returns 200 with application/json', function (done) { | ||
| supertest(app) | ||
| .get('/fonts.json') | ||
| .expect(200) | ||
| .expect('Content-Type', /application\/json/, done); | ||
| }); | ||
|
|
||
| it('returns non-empty array of font names', function (done) { | ||
| supertest(app) | ||
| .get('/fonts.json') | ||
| .expect(function (res) { | ||
| expect(res.body).to.be.a('array'); | ||
| expect(res.body.length).to.be.greaterThan(0); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('returns sorted font names', function (done) { | ||
| supertest(app) | ||
| .get('/fonts.json') | ||
| .expect(function (res) { | ||
| const sorted = [...res.body].sort(); | ||
| expect(res.body).to.deep.equal(sorted); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('/fonts/:fontstack/:range.pbf', function () { | ||
| describe('valid single font', function () { | ||
| it('returns 200 with application/x-protobuf', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .expect(200) | ||
| .expect('Content-Type', /application\/x-protobuf/, done); | ||
| }); | ||
|
|
||
| it('returns non-empty body', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .expect(function (res) { | ||
| const length = parseInt(res.headers['content-length'], 10); | ||
| expect(length).to.be.greaterThan(0); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('sets Last-Modified header', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Regular/0-255.pbf') | ||
| .expect(200) | ||
| .expect(function (res) { | ||
| expect(res.headers['last-modified']).to.be.a('string'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('valid combined font stack', function () { | ||
| it('returns 200 for comma-separated font stack', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold%2COpen%20Sans%20Regular/0-255.pbf') | ||
| .expect(200) | ||
| .expect('Content-Type', /application\/x-protobuf/, done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('304 Not Modified caching', function () { | ||
| it('returns 304 when If-Modified-Since matches Last-Modified', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .end(function (err, res) { | ||
| if (err) return done(err); | ||
| const lastModified = res.headers['last-modified']; | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .set('If-Modified-Since', lastModified) | ||
| .expect(304, done); | ||
| }); | ||
| }); | ||
|
|
||
| it('returns 200 when Cache-Control: no-cache overrides If-Modified-Since', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .end(function (err, res) { | ||
| if (err) return done(err); | ||
| const lastModified = res.headers['last-modified']; | ||
| supertest(app) | ||
| .get('/fonts/Open%20Sans%20Bold/0-255.pbf') | ||
| .set('If-Modified-Since', lastModified) | ||
| .set('Cache-Control', 'no-cache') | ||
| .expect(200, done); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('invalid requests return 400', function () { | ||
| it('returns 400 for fully nonexistent font', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Nonsense/0-255.pbf') | ||
| .expect(400, done); | ||
| }); | ||
|
|
||
| it('returns 400 when all fonts in stack are nonexistent', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Nonsense1%2CNonsense2/0-255.pbf') | ||
| .expect(400, done); | ||
| }); | ||
|
|
||
| it('returns 400 when first font in stack is nonexistent', function (done) { | ||
| supertest(app) | ||
| .get('/fonts/Nonsense%2COpen%20Sans%20Bold/0-255.pbf') | ||
| .expect(400, done); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| const prefix = 'test-style'; | ||
| const styleUrl = '/styles/' + prefix + '/style.json'; | ||
|
|
||
| describe('Style URL rewriting', function () { | ||
| describe('sprite URL', function () { | ||
| it('is rewritten to absolute URL', function (done) { | ||
| supertest(app) | ||
| .get(styleUrl) | ||
| .expect(function (res) { | ||
| expect(res.body.sprite).to.match(/^http/); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('contains correct style id path', function (done) { | ||
| supertest(app) | ||
| .get(styleUrl) | ||
| .expect(function (res) { | ||
| expect(res.body.sprite).to.include('/styles/' + prefix + '/sprite'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('glyphs URL', function () { | ||
| it('is rewritten to absolute URL', function (done) { | ||
| supertest(app) | ||
| .get(styleUrl) | ||
| .expect(function (res) { | ||
| expect(res.body.glyphs).to.match(/^http/); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('preserves {fontstack} and {range} template placeholders', function (done) { | ||
| supertest(app) | ||
| .get(styleUrl) | ||
| .expect(function (res) { | ||
| expect(res.body.glyphs).to.include('{fontstack}'); | ||
| expect(res.body.glyphs).to.include('{range}'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('source URLs', function () { | ||
| it('all source tile URLs are absolute', function (done) { | ||
| supertest(app) | ||
| .get(styleUrl) | ||
| .expect(function (res) { | ||
| for (const name of Object.keys(res.body.sources)) { | ||
| const source = res.body.sources[name]; | ||
| if (source.url) { | ||
| expect(source.url).to.match(/^http/); | ||
| } | ||
| } | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('styles.json listing', function () { | ||
| it('each item has an absolute url field', function (done) { | ||
| supertest(app) | ||
| .get('/styles.json') | ||
| .expect(function (res) { | ||
| for (const item of res.body) { | ||
| expect(item.url).to.match(/^http/); | ||
| expect(item.url).to.include('/styles/'); | ||
| expect(item.url).to.include('/style.json'); | ||
| } | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('contains both configured styles', function (done) { | ||
| supertest(app) | ||
| .get('/styles.json') | ||
| .expect(function (res) { | ||
| const ids = res.body.map((s) => s.id); | ||
| expect(ids).to.include('test-style'); | ||
| expect(ids).to.include('maptiler-basic'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Rendered TileJSON', function () { | ||
| it('/styles/' + prefix + '.json has tileSize 256 by default', function (done) { | ||
| supertest(app) | ||
| .get('/styles/' + prefix + '.json') | ||
| .expect(200) | ||
| .expect(function (res) { | ||
| expect(res.body.tileSize).to.equal(256); | ||
| expect(res.body.tiles).to.be.a('array'); | ||
| expect(res.body.tiles[0]).to.match(/^http/); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('/styles/512/' + prefix + '.json has tileSize 512', function (done) { | ||
| supertest(app) | ||
| .get('/styles/512/' + prefix + '.json') | ||
| .expect(200) | ||
| .expect(function (res) { | ||
| expect(res.body.tileSize).to.equal(512); | ||
| expect(res.body.tiles[0]).to.include('/512/'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('/styles/non_existent.json returns 404', function (done) { | ||
| supertest(app).get('/styles/non_existent.json').expect(404, done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Listing endpoints content', function () { | ||
| describe('/rendered.json', function () { | ||
| it('items have absolute tile URLs', function (done) { | ||
| supertest(app) | ||
| .get('/rendered.json') | ||
| .expect(function (res) { | ||
| for (const item of res.body) { | ||
| expect(item.tiles[0]).to.match(/^http/); | ||
| } | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('/data.json', function () { | ||
| it('contains configured data sources', function (done) { | ||
| supertest(app) | ||
| .get('/data.json') | ||
| .expect(function (res) { | ||
| const names = res.body.map((d) => d.name || d.id); | ||
| expect(res.body.length).to.be.greaterThan(0); | ||
| }) | ||
| .end(done); | ||
| }); | ||
|
|
||
| it('items have absolute tile URLs', function (done) { | ||
| supertest(app) | ||
| .get('/data.json') | ||
| .expect(function (res) { | ||
| for (const item of res.body) { | ||
| expect(item.tiles[0]).to.match(/^http/); | ||
| } | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Health endpoint', function () { | ||
| it('returns OK body when server is up', function (done) { | ||
| supertest(app).get('/health').expect(200).expect('OK', done); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.