summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-08-31 17:53:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-08-31 17:53:37 -0700
commit0918ad5a29ea535ac59c39097cd7a670f0a76320 (patch)
tree9c899ef62b76a9d4b530107baebd82aefb0d3bb8 /platform
parente33abc975bff22f0bebd32e72e87ff6a70c1f509 (diff)
downloadqtlocation-mapboxgl-0918ad5a29ea535ac59c39097cd7a670f0a76320.tar.gz
Clean up tests
Diffstat (limited to 'platform')
-rw-r--r--platform/node/test/js/map.test.js341
1 files changed, 156 insertions, 185 deletions
diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js
index 4586ceeed4..ecd89c1487 100644
--- a/platform/node/test/js/map.test.js
+++ b/platform/node/test/js/map.test.js
@@ -20,200 +20,178 @@ function filePath(name) {
}, {});
}
-function setup(options, callback) {
- callback(new mbgl.Map(options));
-}
-
test('Map', function(t) {
- t.test('constructor', function(t) {
- t.test('must be called with new', function(t) {
- t.throws(function() {
- mbgl.Map();
- }, /Use the new operator to create new Map objects/);
+ t.test('must be constructed with new', function(t) {
+ t.throws(function() {
+ mbgl.Map();
+ }, /Use the new operator to create new Map objects/);
- t.end();
- });
-
- t.test('should require an options object as first parameter', function(t) {
- t.throws(function() {
- new mbgl.Map();
- }, /Requires an options object as first argument/);
+ t.end();
+ });
- t.throws(function() {
- new mbgl.Map('options');
- }, /Requires an options object as first argument/);
+ t.test('must be constructed with options object', function(t) {
+ t.throws(function() {
+ new mbgl.Map();
+ }, /Requires an options object as first argument/);
- t.end();
- });
+ t.throws(function() {
+ new mbgl.Map('options');
+ }, /Requires an options object as first argument/);
- t.test('should require then options object to have request and cancel methods', function(t) {
- var options = {};
+ t.end();
+ });
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a 'request' method/);
+ t.test('requires request and ratio options', function(t) {
+ var options = {};
- options.request = 'test';
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a 'request' method/);
+ t.throws(function() {
+ new mbgl.Map(options);
+ }, /Options object must have a 'request' method/);
- options.request = function() {};
- options.cancel = 'test';
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object 'cancel' property must be a function/);
+ options.request = 'test';
+ t.throws(function() {
+ new mbgl.Map(options);
+ }, /Options object must have a 'request' method/);
- options.cancel = function() {};
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a numerical 'ratio' property/);
+ options.request = function() {};
+ options.cancel = 'test';
+ t.throws(function() {
+ new mbgl.Map(options);
+ }, /Options object 'cancel' property must be a function/);
- options.ratio = 'test';
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a numerical 'ratio' property/);
+ options.cancel = function() {};
+ t.throws(function() {
+ new mbgl.Map(options);
+ }, /Options object must have a numerical 'ratio' property/);
- options.ratio = 1.0;
- t.doesNotThrow(function() {
- new mbgl.Map(options);
- });
+ options.ratio = 'test';
+ t.throws(function() {
+ new mbgl.Map(options);
+ }, /Options object must have a numerical 'ratio' property/);
- t.end();
+ options.ratio = 1.0;
+ t.doesNotThrow(function() {
+ new mbgl.Map(options);
});
t.end();
});
- t.test('load styles', function(t) {
- var options = {};
- options.request = function() {};
- options.cancel = function() {};
- options.ratio = 1.0;
-
- t.test('requires a string or object as the first parameter', function(t) {
- t.test('requires a map style as first argument', function(t) {
- setup(options, function(map) {
- t.throws(function() {
- map.load();
- }, /Requires a map style as first argument/);
+ t.test('.load', function(t) {
+ var options = {
+ request: function() {},
+ ratio: 1
+ };
- map.release();
+ t.test('requires a map style as first argument', function(t) {
+ var map = new mbgl.Map(options);
- t.end();
- });
- });
+ t.throws(function() {
+ map.load();
+ }, /Requires a map style as first argument/);
- t.test('expect either an object or array at root', { timeout: 1000 }, function(t) {
- setup(options, function(map) {
- mbgl.once('message', function(msg) {
- t.equal(msg.severity, 'ERROR');
- t.equal(msg.class, 'ParseStyle');
- t.ok(msg.text.match(/Expect either an object or array at root/));
+ map.release();
+ t.end();
+ });
- map.release();
+ t.test('expect either an object or array at root', { timeout: 1000 }, function(t) {
+ var map = new mbgl.Map(options);
- t.end();
- });
+ mbgl.once('message', function(msg) {
+ t.equal(msg.severity, 'ERROR');
+ t.equal(msg.class, 'ParseStyle');
+ t.ok(msg.text.match(/Expect either an object or array at root/));
- map.load('invalid');
- });
+ map.release();
+ t.end();
});
- t.end();
+ map.load('invalid');
});
t.test('accepts an empty stylesheet string', function(t) {
- setup(options, function(map) {
- t.doesNotThrow(function() {
- map.load('{}');
- });
-
- map.release();
+ var map = new mbgl.Map(options);
- t.end();
+ t.doesNotThrow(function() {
+ map.load('{}');
});
+
+ map.release();
+ t.end();
});
t.test('accepts a JSON stylesheet', { timeout: 1000 }, function(t) {
- setup(options, function(map) {
- t.doesNotThrow(function() {
- map.load(style);
- });
-
- map.release();
+ var map = new mbgl.Map(options);
- t.end();
+ t.doesNotThrow(function() {
+ map.load(style);
});
+
+ map.release();
+ t.end();
});
t.test('accepts a stringified stylesheet', { timeout: 1000 }, function(t) {
- setup(options, function(map) {
- t.doesNotThrow(function() {
- map.load(JSON.stringify(style));
- });
+ var map = new mbgl.Map(options);
- map.release();
-
- t.end();
+ t.doesNotThrow(function() {
+ map.load(JSON.stringify(style));
});
- });
- t.end();
+ map.release();
+ t.end();
+ });
});
- t.test('render argument requirements', function(t) {
- var options = {};
- options.request = function(req) {
- fs.readFile(path.join('test', req.url), function(err, data) {
- req.respond(err, { data: data });
- });
+ t.test('.render', function(t) {
+ var options = {
+ request: function(req) {
+ fs.readFile(path.join('test', req.url), function(err, data) {
+ req.respond(err, { data: data });
+ });
+ },
+ ratio: 1
};
- options.cancel = function() {};
- options.ratio = 1.0;
t.test('requires an object as the first parameter', function(t) {
- setup(options, function(map) {
- t.throws(function() {
- map.render();
- }, /First argument must be an options object/);
+ var map = new mbgl.Map(options);
- t.throws(function() {
- map.render('invalid');
- }, /First argument must be an options object/);
+ t.throws(function() {
+ map.render();
+ }, /First argument must be an options object/);
- map.release();
+ t.throws(function() {
+ map.render('invalid');
+ }, /First argument must be an options object/);
- t.end();
- });
+ map.release();
+ t.end();
});
t.test('requires a callback as the second parameter', function(t) {
- setup(options, function(map) {
- t.throws(function() {
- map.render({});
- }, /Second argument must be a callback function/);
+ var map = new mbgl.Map(options);
- t.throws(function() {
- map.render({}, 'invalid');
- }, /Second argument must be a callback function/);
+ t.throws(function() {
+ map.render({});
+ }, /Second argument must be a callback function/);
- map.release();
+ t.throws(function() {
+ map.render({}, 'invalid');
+ }, /Second argument must be a callback function/);
- t.end();
- });
+ map.release();
+ t.end();
});
t.test('requires a style to be set', function(t) {
- setup(options, function(map) {
- t.throws(function() {
- map.render({}, function() {});
- }, /Style is not loaded/);
+ var map = new mbgl.Map(options);
- map.release();
+ t.throws(function() {
+ map.render({}, function() {});
+ }, /Style is not loaded/);
- t.end();
- });
+ map.release();
+ t.end();
});
t.test('returns an error', function(t) {
@@ -224,70 +202,63 @@ test('Map', function(t) {
t.ok(msg.text.match(/Failed to load/), 'error text matches');
});
- setup(options, function(map) {
- map.load(style);
- map.render({ zoom: 1 }, function(err, data) {
- mbgl.removeAllListeners('message');
- map.release();
+ var map = new mbgl.Map(options);
+ map.load(style);
+ map.render({ zoom: 1 }, function(err, data) {
+ mbgl.removeAllListeners('message');
+ map.release();
- t.ok(err, 'returns error');
- t.ok(err.message.match(/Failed to load/), 'error text matches');
+ t.ok(err, 'returns error');
+ t.ok(err.message.match(/Failed to load/), 'error text matches');
- t.end();
- });
+ t.end();
});
});
t.test('double release', function(t) {
- setup(options, function(map) {
- map.release();
+ var map = new mbgl.Map(options);
+ map.release();
- t.throws(function() {
- map.release();
- }, /Map resources have already been released/);
+ t.throws(function() {
+ map.release();
+ }, /Map resources have already been released/);
- t.end();
- });
+ t.end();
});
t.test('returns an image', function(t) {
- setup(options, function(map) {
- map.load(style);
- map.render({}, function(err, data) {
- t.error(err);
-
- map.release();
-
- var filename = filePath('image.png');
-
- var png = new PNG({
- width: data.width,
- height: data.height
- });
-
- png.data = data.pixels;
-
- if (process.env.UPDATE) {
- png.pack()
- .pipe(fs.createWriteStream(filename.expected))
- .on('finish', t.end);
- } else {
- png.pack()
- .pipe(fs.createWriteStream(filename.actual))
- .on('finish', function() {
- compare(filename.actual, filename.expected, filename.diff, t, function(err, diff) {
- t.error(err);
- t.ok(diff <= 0.01, 'actual matches expected');
- t.end();
- });
- });
- }
+ var map = new mbgl.Map(options);
+ map.load(style);
+ map.render({}, function(err, data) {
+ t.error(err);
+
+ map.release();
+
+ var filename = filePath('image.png');
+
+ var png = new PNG({
+ width: data.width,
+ height: data.height
});
+
+ png.data = data.pixels;
+
+ if (process.env.UPDATE) {
+ png.pack()
+ .pipe(fs.createWriteStream(filename.expected))
+ .on('finish', t.end);
+ } else {
+ png.pack()
+ .pipe(fs.createWriteStream(filename.actual))
+ .on('finish', function() {
+ compare(filename.actual, filename.expected, filename.diff, t, function(err, diff) {
+ t.error(err);
+ t.ok(diff <= 0.01, 'actual matches expected');
+ t.end();
+ });
+ });
+ }
});
});
-
- t.end();
});
-
- t.end();
});