fix example

blah

real test

Still not writing tests correctly
This commit is contained in:
samanpwbb
2015-03-04 15:15:33 -05:00
parent 2734e2c3f9
commit fffb0f7df5
7 changed files with 141 additions and 2 deletions

View File

@@ -141,7 +141,8 @@ var fileSource = new mbgl.FileSource();
fileSource.request = function(req) {
request({
url: req.url,
encoding: null
encoding: null,
gzip: true
}, function (err, res, body) {
if (req.canceled) {
return;

View File

@@ -28,8 +28,10 @@
"aws-sdk": "^2.1.9",
"mapbox-gl-test-suite": "git://github.com/mapbox/mapbox-gl-test-suite#master",
"mkdirp": "^0.5.0",
"request": "^2.53.0",
"tap-spec": "^2.2.1",
"tape": "^3.5.0"
"tape": "^3.5.0",
"st": "^0.5.3"
},
"scripts": {
"install": "node-pre-gyp install || make",

26
test/fixtures/style-gz.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
"version": 7,
"name": "Empty",
"sources": {
"mapbox": {
"type": "vector",
"url": "./fixtures/tiles-gz.tilejson",
"maxzoom": 15
}
},
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "aqua"
}
}, {
"id": "water",
"type": "fill",
"source": "mapbox",
"source-layer": "water",
"paint": {
"fill-color": "red"
}
}]
}

13
test/fixtures/tiles-gz.tilejson vendored Normal file
View File

@@ -0,0 +1,13 @@
{
"bounds": [ -180, -85.0511, 180, 85.0511 ],
"center": [ 0, 0, 0 ],
"format": "pbf",
"id": "mapbox.mapbox-streets-v6-dev",
"maskLevel": 8,
"maxzoom": 15,
"minzoom": 0,
"name": "Mapbox Streets V6",
"scheme": "xyz",
"tilejson": "2.0.0",
"tiles": [ "./fixtures/tiles/{z}-{x}-{y}.vector.pbf.gz" ]
}

BIN
test/fixtures/tiles/0-0-0.vector.pbf.gz vendored Normal file

Binary file not shown.

View File

@@ -7,6 +7,7 @@ var mbgl = require('../..');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var suitePath = path.dirname(require.resolve('mapbox-gl-test-suite/package.json'));
mkdirp.sync('test/results');

96
test/map-gz.test.js Normal file
View File

@@ -0,0 +1,96 @@
'use strict';
/* jshint node: true */
var test = require('tape');
var mbgl = require('../');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var http = require('http');
var request = require('request');
var st = require('st');
/*
FIX: In all cases style-gz fails, and in all cases, style.json passes,
regardless of how gzip is set in either st or request.
*/
var style = require('../test/fixtures/style.json');
// var style = require('../test/fixtures/style-gz.json');
mkdirp.sync('results');
var server = http.createServer(st({path: __dirname}));
server.listen(2900);
function setup(fileSource, callback) {
callback(new mbgl.Map(fileSource));
}
function getFileSource(gzip, t) {
var fileSource = new mbgl.FileSource();
fileSource.request = function(req) {
request({
url: 'http://localhost:2900' + path.join('/', req.url),
encoding: null,
gzip: gzip
}, function (err, res, body) {
t.error(err);
var response = {};
response.data = res.body;
req.respond(null, response);
});
};
fileSource.cancel = function(req) {};
return fileSource;
}
test('before tests', function(t) {
server.listen(2900, t.end);
});
test('gzip passes', function(t) {
/*
FIX: I think need to turn OFF this event listener before this test
is done so next test doesn't accidentally use it.
*/
mbgl.on('message', function(msg) {
t.error(msg);
});
setup(getFileSource(true, t), function(map) {
map.load(style);
map.render({}, function(err, image) {
mbgl.compressPNG(image, function(err, data) {
fs.writeFileSync('results/image-pgf-gz-false.png', data);
t.end();
});
});
});
});
test('gzip fails', function(t) {
/*
FIX: No message will be emmitted if gzip doesn't fail,
so this test is pointless
*/
mbgl.on('message', function(msg) {
t.equal(msg === null, 'gzipped pbf fails when gzip:false');
});
setup(getFileSource(false, t), function(map) {
map.load(style);
map.render({}, function(err, image) {
mbgl.compressPNG(image, function(err, data) {
fs.writeFileSync('results/image-pgf-gz-true.png', data);
server.close(t.end);
});
});
});
});