Node platform improvements (#891)
This commit is contained in:
@@ -118,6 +118,7 @@ test('Map', function(t) {
|
||||
'setLayoutProperty',
|
||||
'setPaintProperty',
|
||||
'setFilter',
|
||||
'setSize',
|
||||
'setCenter',
|
||||
'setZoom',
|
||||
'setBearing',
|
||||
@@ -415,16 +416,16 @@ test('Map', function(t) {
|
||||
ratio: 1
|
||||
};
|
||||
|
||||
t.test('requires an object as the first parameter', function(t) {
|
||||
t.test('requires an object or a callback function as the first parameter', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
|
||||
t.throws(function() {
|
||||
map.render();
|
||||
}, /First argument must be an options object/);
|
||||
}, /First argument must be an options object or a callback function/);
|
||||
|
||||
t.throws(function() {
|
||||
map.render('invalid');
|
||||
}, /First argument must be an options object/);
|
||||
}, /First argument must be an options object or a callback function/);
|
||||
|
||||
map.release();
|
||||
t.end();
|
||||
@@ -456,6 +457,17 @@ test('Map', function(t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('requires a style to be set (without render options object)', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
|
||||
t.throws(function() {
|
||||
map.render(function() {});
|
||||
}, /Style is not loaded/);
|
||||
|
||||
map.release();
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('returns an error delayed', function(t) {
|
||||
var delay = 0;
|
||||
var map = new mbgl.Map({
|
||||
@@ -476,6 +488,27 @@ test('Map', function(t) {
|
||||
});
|
||||
});
|
||||
|
||||
t.test('returns an error delayed (without render options object)', function(t) {
|
||||
var delay = 0;
|
||||
var map = new mbgl.Map({
|
||||
request: function(req, callback) {
|
||||
delay += 100;
|
||||
setTimeout(function() {
|
||||
callback(new Error('not found'));
|
||||
}, delay);
|
||||
},
|
||||
ratio: 1
|
||||
});
|
||||
map.load(style);
|
||||
map.setZoom(1);
|
||||
map.render(function(err, data) {
|
||||
map.release();
|
||||
|
||||
t.ok(err, 'returns error');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.test('returns an error', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
@@ -487,6 +520,18 @@ test('Map', function(t) {
|
||||
});
|
||||
});
|
||||
|
||||
t.test('returns an error (without render options object)', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
map.setZoom(1);
|
||||
map.render(function(err, data) {
|
||||
map.release();
|
||||
|
||||
t.ok(err, 'returns error');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.test('double release', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.release();
|
||||
@@ -511,6 +556,19 @@ test('Map', function(t) {
|
||||
});
|
||||
});
|
||||
|
||||
t.test('returns an image (without render options object)', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
map.render(function(err, pixels) {
|
||||
t.error(err);
|
||||
map.release();
|
||||
t.ok(pixels);
|
||||
t.ok(pixels instanceof Buffer);
|
||||
t.equal(pixels.length, 512 * 512 * 4)
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.test('can be called several times in serial', function(t) {
|
||||
var completed = 0;
|
||||
var remaining = 10;
|
||||
@@ -536,6 +594,31 @@ test('Map', function(t) {
|
||||
render();
|
||||
});
|
||||
|
||||
t.test('can be called several times in serial (without render options object)', function(t) {
|
||||
var completed = 0;
|
||||
var remaining = 10;
|
||||
var start = +new Date;
|
||||
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
|
||||
function render() {
|
||||
map.render(function(err, data) {
|
||||
t.error(err);
|
||||
|
||||
t.ok(true, 'render @ ' + ((+new Date) - start) + 'ms');
|
||||
if (++completed === remaining) {
|
||||
map.release();
|
||||
t.end();
|
||||
} else {
|
||||
render();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render();
|
||||
});
|
||||
|
||||
t.test('throws if called in parallel', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
@@ -549,6 +632,19 @@ test('Map', function(t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('throws if called in parallel (without render options object)', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load(style);
|
||||
|
||||
t.throws(function() {
|
||||
map.render(function() {});
|
||||
map.render(function() {});
|
||||
}, /Map is currently processing a RenderRequest/);
|
||||
|
||||
map.release();
|
||||
t.end();
|
||||
});
|
||||
|
||||
// This can't be tested with a test-suite render test because zoom and center
|
||||
// are set via a different code path when included as style properties.
|
||||
t.test('sets zoom before center', function(t) {
|
||||
@@ -589,7 +685,50 @@ test('Map', function(t) {
|
||||
t.equal(numPixels, 0);
|
||||
t.end();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
t.test('sets zoom before center (without render options object)', function(t) {
|
||||
var map = new mbgl.Map(options);
|
||||
map.load({
|
||||
"version": 8,
|
||||
"sources": {
|
||||
"geojson": {
|
||||
"type": "geojson",
|
||||
"data": {
|
||||
"type": "Point",
|
||||
"coordinates": [
|
||||
18.05489,
|
||||
59.32744
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "circle",
|
||||
"type": "circle",
|
||||
"source": "geojson",
|
||||
"paint": {
|
||||
"circle-color": "red"
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
map.setSize([400, 400]);
|
||||
map.setZoom(5);
|
||||
map.setCenter([18.05489, 59.32744]);
|
||||
map.render(function(err, actual) {
|
||||
t.error(err);
|
||||
|
||||
var PNG = require('pngjs').PNG;
|
||||
var pixelmatch = require('pixelmatch');
|
||||
var expected = PNG.sync.read(
|
||||
fs.readFileSync(path.join(__dirname, '../fixtures/zoom-center/expected.png'))).data;
|
||||
var numPixels = pixelmatch(actual, expected, undefined, 400, 400, { threshold: 0.13 });
|
||||
t.equal(numPixels, 0);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
t.test('request callback', function (t) {
|
||||
|
||||
Reference in New Issue
Block a user