Skip to content

Commit 6169aaa

Browse files
committed
Fix tests for browser and bump version to 0.2.1
1 parent 6a49fe7 commit 6169aaa

File tree

3 files changed

+46
-57
lines changed

3 files changed

+46
-57
lines changed

README.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# msgpack for node
22

3-
[![Build Status](https://secure.travis-ci.org/creationix/msgpack-js.png)](http://travis-ci.org/creationix/msgpack-js)
3+
[![node support](https://travis-ci.org/creationix/msgpack-js.png)](https://travis-ci.org/creationix/msgpack-js)
4+
5+
[![browser support](https://ci.testling.com/creationix/msgpack-js.png)](https://ci.testling.com/creationix/msgpack-js)
6+
47

58
A handwritten msgpack encoder and decoder for Node.JS and modern browsers.
69

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22
"author": "Tim Caswell <[email protected]>",
33
"name": "msgpack-js",
44
"description": "msgpack encoder and decoder in pure javascript",
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/creationix/msgpack-js.git"
99
},
10+
"scripts": {
11+
"test": "node test.js"
12+
},
13+
"testling": {
14+
"files": "test.js",
15+
"browsers": [
16+
"ie/9..latest",
17+
"firefox/19..latest",
18+
"chrome/25..latest",
19+
"safari/latest",
20+
"iphone/6",
21+
"ipad/6"
22+
]
23+
},
1024
"main": "msgpack.js",
1125
"dependencies": {
12-
"bops": "~0.0.5"
26+
"bops": "~0.0.6"
27+
},
28+
"devDependencies": {
29+
"tape": "~1.0.2"
1330
}
1431
}

test.js

100755100644
Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/usr/bin/env node
1+
"use strict";
2+
var bops = require('bops');
3+
var test = require('tape');
24
var msgpack = require('./msgpack');
35
var util = require('util');
4-
var assert = require('assert');
56

67
var tests = [
78
true, false, null, undefined,
@@ -12,61 +13,29 @@ var tests = [
1213
0x20000, -0x20000, 0x40000,-0x40000,
1314
10, 100, 1000, 10000, 100000, 1000000,
1415
-10, -100, -1000, -10000, -100000, -1000000,
15-
'hello', 'world', Buffer("Hello"), Buffer("World"),
16+
'hello', 'world', bops.from("Hello"), bops.from("World"),
1617
[1,2,3], [], {name: "Tim", age: 29}, {},
1718
{a: 1, b: 2, c: [1, 2, 3]},
1819
];
19-
for (var i = 0, l = tests.length; i < l; i++) {
20-
var test = tests[i];
21-
if (typeof test === 'number') {
22-
tests.push(test + 1);
23-
tests.push(test - 1);
24-
tests.push(test + 0.5);
25-
}
26-
}
27-
[0x100, 0x1000, 0x10000, 0x100000].forEach(function (length) {
28-
var list = new Array(length), obj = {};
29-
for (var i = 0; i < length; i++) {
30-
list[i] = i;
31-
obj[i] = i;
32-
}
33-
tests.push(list);
34-
tests.push(obj);
35-
});
3620

37-
var width = 80;
38-
if (process.stdout.isTTY) {
39-
width = process.stdout.getWindowSize()[0];
40-
}
41-
var mistakes = 0;
42-
function dump(value) {
43-
if (typeof value === 'undefined' || Buffer.isBuffer(value)) {
44-
return util.inspect(value).replace(/\n */g, '');
45-
}
46-
return JSON.stringify(value);
47-
}
48-
tests.forEach(function (test) {
49-
console.log(dump(test).substr(0, width));
50-
var encoded = msgpack.encode(test);
51-
console.log(encoded.inspect().substr(0, width));
52-
var decoded = msgpack.decode(encoded);
53-
try {
54-
assert.deepEqual(test, decoded);
55-
if (typeof test === "object" && test !== null) {
56-
assert.equal(test.constructor, decoded.constructor);
21+
test('codec works as expected', function(assert) {
22+
23+
tests.forEach(function (input) {
24+
var packed = msgpack.encode(input);
25+
console.log(packed);
26+
var output = msgpack.decode(packed);
27+
if (bops.is(input)) {
28+
assert.true(bops.is(output));
29+
for (var i = 0, l = input.length; i < l; i++) {
30+
assert.equal(input[i], output[i]);
31+
}
32+
assert.equal(input.length, output.length);
33+
}
34+
else {
35+
assert.deepEqual(input, output);
5736
}
58-
} catch (err) {
59-
console.error();
60-
console.error(dump(test).substr(0, width));
61-
console.error(encoded.inspect().substr(0, width));
62-
console.error(dump(decoded).substr(0, width));
63-
console.error(err.stack);
64-
mistakes++;
65-
}
37+
});
38+
39+
assert.end();
40+
6641
});
67-
if (mistakes) {
68-
console.error(mistakes + " tests failed!");
69-
} else {
70-
console.log("\nAll tests passed successfully!");
71-
}
72-
process.exit(mistakes.length);

0 commit comments

Comments
 (0)