make 'cancel' function in FileSource optional

update README
This commit is contained in:
Mike Morris
2015-08-04 14:50:04 -04:00
parent 84a1e6d1c3
commit d3104756af
7 changed files with 93 additions and 107 deletions

View File

@@ -31,31 +31,27 @@ function setup(options, callback) {
callback(new mbgl.Map(options));
}
function getFileSourceOptions(gzip, t) {
var options = {};
function getOptions(gzip, t) {
return {
request: function(req) {
var parts = req.url.split('.');
var filetype = parts[parts.length - 1];
options.request = function(req) {
var parts = req.url.split('.');
var filetype = parts[parts.length - 1];
request({
url: 'http://localhost:' + server.address().port + path.join('/', req.url),
encoding: null,
gzip: filetype === 'pbf' ? gzip : true,
headers: {
'Accept-Encoding': 'gzip'
}
}, function (err, res, body) {
t.error(err);
var response = {};
response.data = res.body;
req.respond(null, response);
});
request({
url: 'http://localhost:' + server.address().port + path.join('/', req.url),
encoding: null,
gzip: filetype === 'pbf' ? gzip : true,
headers: {
'Accept-Encoding': 'gzip'
}
}, function (err, res, body) {
t.error(err);
var response = {};
response.data = res.body;
req.respond(null, response);
});
}
};
options.cancel = function(req) {};
return options;
}
test('gzip', function(t) {
@@ -64,7 +60,7 @@ test('gzip', function(t) {
if (msg.severity == 'ERROR') t.error(msg);
});
setup(getFileSourceOptions(true, t), function(map) {
setup(getOptions(true, t), function(map) {
map.load(style);
map.render({}, function(err, data) {
mbgl.removeAllListeners('message');
@@ -110,7 +106,7 @@ test('gzip', function(t) {
}
});
setup(getFileSourceOptions(false, t), function(map) {
setup(getOptions(false, t), function(map) {
map.load(style);
map.render({}, function(err, data) {
map.release();

View File

@@ -34,39 +34,35 @@ test('Map', function(t) {
t.end();
});
t.test('should require a FileSource options object as first parameter', function(t) {
t.test('should require an options object as first parameter', function(t) {
t.throws(function() {
new mbgl.Map();
}, /Requires FileSource options as first argument/);
}, /Requires an options object as first argument/);
t.throws(function() {
new mbgl.Map('options');
}, /Requires FileSource options as first argument/);
}, /Requires an options object as first argument/);
t.end();
});
t.test('should require the FileSource options object to have request and cancel methods', function(t) {
t.test('should require then options object to have request and cancel methods', function(t) {
var options = {};
t.throws(function() {
new mbgl.Map(options);
}, /FileSource options must have a request member function/);
}, /Options object must have a 'request' method/);
options.request = 'test';
t.throws(function() {
new mbgl.Map(options);
}, /FileSource options must have a request member function/);
}, /Options object must have a 'request' method/);
options.request = function() {};
t.throws(function() {
new mbgl.Map(options);
}, /FileSource options must have a cancel member function/);
options.cancel = 'test';
t.throws(function() {
new mbgl.Map(options);
}, /FileSource options must have a cancel member function/);
}, /Options object 'cancel' property must be a function/);
options.cancel = function() {};
t.doesNotThrow(function() {