Skip to content

Commit 3fcd88c

Browse files
committed
Other: Added eventemitter tests and updated micromodule dependencies (so far)
1 parent 2db4305 commit 3fcd88c

File tree

16 files changed

+121
-89
lines changed

16 files changed

+121
-89
lines changed

lib/aspromise/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export = asPromise;
88
* @param {...*} params Function arguments
99
* @returns {Promise<*>} Promisified function
1010
*/
11-
function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;
11+
declare function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;

lib/aspromise/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/aspromise",
33
"description": "Returns a promise from a node-style callback function.",
4-
"version": "1.0.6",
4+
"version": "1.1.1",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

lib/aspromise/tests/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ var tape = require("tape");
22

33
var asPromise = require("..");
44

5+
if (typeof Promise !== "undefined")
56
tape.test("aspromise", function(test) {
67

7-
if (typeof Promise === "undefined")
8-
return test.pass("not supported, skipping...");
9-
108
test.test(this.name + " - resolve", function(test) {
119

1210
function fn(arg1, arg2, callback) {

lib/base64/index.d.ts

+27-37
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
export = base64;
2-
31
/**
4-
* A minimal base64 implementation for number arrays.
5-
* @memberof util
6-
* @namespace
2+
* Calculates the byte length of a base64 encoded string.
3+
* @param {string} string Base64 encoded string
4+
* @returns {number} Byte length
75
*/
8-
declare namespace base64 {
9-
10-
/**
11-
* Calculates the byte length of a base64 encoded string.
12-
* @param {string} string Base64 encoded string
13-
* @returns {number} Byte length
14-
*/
15-
function length(string: string): number;
6+
export function length(string: string): number;
167

17-
/**
18-
* Encodes a buffer to a base64 encoded string.
19-
* @param {Uint8Array} buffer Source buffer
20-
* @param {number} start Source start
21-
* @param {number} end Source end
22-
* @returns {string} Base64 encoded string
23-
*/
24-
function encode(buffer: Uint8Array, start: number, end: number): string;
8+
/**
9+
* Encodes a buffer to a base64 encoded string.
10+
* @param {Uint8Array} buffer Source buffer
11+
* @param {number} start Source start
12+
* @param {number} end Source end
13+
* @returns {string} Base64 encoded string
14+
*/
15+
export function encode(buffer: Uint8Array, start: number, end: number): string;
2516

26-
/**
27-
* Decodes a base64 encoded string to a buffer.
28-
* @param {string} string Source string
29-
* @param {Uint8Array} buffer Destination buffer
30-
* @param {number} offset Destination offset
31-
* @returns {number} Number of bytes written
32-
* @throws {Error} If encoding is invalid
33-
*/
34-
function decode(string: string, buffer: Uint8Array, offset: number): number;
17+
/**
18+
* Decodes a base64 encoded string to a buffer.
19+
* @param {string} string Source string
20+
* @param {Uint8Array} buffer Destination buffer
21+
* @param {number} offset Destination offset
22+
* @returns {number} Number of bytes written
23+
* @throws {Error} If encoding is invalid
24+
*/
25+
export function decode(string: string, buffer: Uint8Array, offset: number): number;
3526

36-
/**
37-
* Tests if the specified string appears to be base64 encoded.
38-
* @param {string} string String to test
39-
* @returns {boolean} `true` if it appears to be base64 encoded, otherwise false
40-
*/
41-
function test(string: string): boolean;
42-
}
27+
/**
28+
* Tests if the specified string appears to be base64 encoded.
29+
* @param {string} string String to test
30+
* @returns {boolean} `true` if it appears to be base64 encoded, otherwise false
31+
*/
32+
export function test(string: string): boolean;

lib/base64/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/base64",
33
"description": "A minimal base64 implementation for number arrays.",
4-
"version": "1.0.6",
4+
"version": "1.1.1",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

lib/eventemitter/package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
{
22
"name": "@protobufjs/eventemitter",
33
"description": "A minimal event emitter.",
4-
"version": "1.0.5",
4+
"version": "1.1.0",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/dcodeIO/protobuf.js.git"
99
},
1010
"license": "BSD-3-Clause",
1111
"main": "index.js",
12-
"types": "index.d.ts"
12+
"types": "index.d.ts",
13+
"devDependencies": {
14+
"istanbul": "^0.4.5",
15+
"tape": "^4.6.3"
16+
},
17+
"scripts": {
18+
"test": "tape tests/*.js",
19+
"coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js"
20+
}
1321
}

lib/eventemitter/tests/index.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var tape = require("tape");
2+
3+
var EventEmitter = require("..");
4+
5+
tape.test("eventemitter", function(test) {
6+
7+
var ee = new EventEmitter();
8+
var fn;
9+
var ctx = {};
10+
11+
test.doesNotThrow(function() {
12+
ee.emit("a", 1);
13+
ee.off();
14+
ee.off("a");
15+
ee.off("a", function() {});
16+
}, "should not throw if no listeners are registered");
17+
18+
test.equal(ee.on("a", function(arg1) {
19+
test.equal(this, ctx, "should be called with this = ctx");
20+
test.equal(arg1, 1, "should be called with arg1 = 1");
21+
}, ctx), ee, "should return itself when registering events");
22+
ee.emit("a", 1);
23+
24+
ee.off("a");
25+
test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");
26+
27+
ee.off();
28+
test.same(ee._listeners, {}, "should remove all listeners when just calling off()");
29+
30+
ee.on("a", fn = function(arg1) {
31+
test.equal(this, ctx, "should be called with this = ctx");
32+
test.equal(arg1, 1, "should be called with arg1 = 1");
33+
}, ctx).emit("a", 1);
34+
35+
ee.off("a", fn);
36+
test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");
37+
38+
ee.on("a", function() {
39+
test.equal(this, ee, "should be called with this = ee");
40+
}).emit("a");
41+
42+
test.doesNotThrow(function() {
43+
ee.off("a", fn);
44+
}, "should not throw if no such listener is found");
45+
46+
test.end();
47+
});

lib/fetch/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"url": "https://github.com/dcodeIO/protobuf.js.git"
99
},
1010
"dependencies": {
11-
"@protobufjs/aspromise": "^1.0.5",
12-
"@protobufjs/inquire": "^1.0.2"
11+
"@protobufjs/aspromise": "^1.1.1",
12+
"@protobufjs/inquire": "^1.1.0"
1313
},
1414
"license": "BSD-3-Clause",
1515
"main": "index.js",

lib/inquire/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/inquire",
33
"description": "Requires a module only if available and hides the require call from bundlers.",
4-
"version": "1.0.3",
4+
"version": "1.1.0",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

lib/path/index.d.ts

+18-28
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
1-
export = path;
2-
31
/**
4-
* A minimal path module to resolve Unix, Windows and URL paths alike.
5-
* @memberof util
6-
* @namespace
2+
* Tests if the specified path is absolute.
3+
* @param {string} path Path to test
4+
* @returns {boolean} `true` if path is absolute
75
*/
8-
declare namespace path {
9-
10-
/**
11-
* Tests if the specified path is absolute.
12-
* @param {string} path Path to test
13-
* @returns {boolean} `true` if path is absolute
14-
*/
15-
function isAbsolute(path: string): boolean;
6+
export function isAbsolute(path: string): boolean;
167

17-
/**
18-
* Normalizes the specified path.
19-
* @param {string} path Path to normalize
20-
* @returns {string} Normalized path
21-
*/
22-
function normalize(path: string): string;
8+
/**
9+
* Normalizes the specified path.
10+
* @param {string} path Path to normalize
11+
* @returns {string} Normalized path
12+
*/
13+
export function normalize(path: string): string;
2314

24-
/**
25-
* Resolves the specified include path against the specified origin path.
26-
* @param {string} originPath Path to the origin file
27-
* @param {string} includePath Include path relative to origin path
28-
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
29-
* @returns {string} Path to the include file
30-
*/
31-
function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
32-
}
15+
/**
16+
* Resolves the specified include path against the specified origin path.
17+
* @param {string} originPath Path to the origin file
18+
* @param {string} includePath Include path relative to origin path
19+
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
20+
* @returns {string} Path to the include file
21+
*/
22+
export function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;

lib/path/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/path",
33
"description": "A minimal path module to resolve Unix, Windows and URL paths alike.",
4-
"version": "1.0.3",
4+
"version": "1.1.1",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

lib/pool/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/pool",
33
"description": "A general purpose buffer pool.",
4-
"version": "1.0.6",
4+
"version": "1.1.0",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

lib/pool/tests/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ var tape = require("tape");
22

33
var pool = require("..");
44

5+
if (typeof Uint8Array !== "undefined")
56
tape.test("pool", function(test) {
67

7-
if (typeof Uint8Array === "undefined")
8-
return test.pass("not supported, skipping...");
9-
108
var alloc = pool(function(size) { return new Uint8Array(size); }, Uint8Array.prototype.subarray);
119

1210
var buf1 = alloc(0);

lib/utf8/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@protobufjs/utf8",
33
"description": "A minimal UTF8 implementation for number arrays.",
4-
"version": "1.0.8",
4+
"version": "1.1.0",
55
"author": "Daniel Wirtz <[email protected]>",
66
"repository": {
77
"type": "git",

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
"release": "npm run make && npm run changelog"
4646
},
4747
"dependencies": {
48-
"@protobufjs/aspromise": "^1.0.5",
49-
"@protobufjs/base64": "^1.0.5",
48+
"@protobufjs/aspromise": "^1.1.1",
49+
"@protobufjs/base64": "^1.1.1",
5050
"@protobufjs/codegen": "^1.0.8",
51-
"@protobufjs/eventemitter": "^1.0.5",
51+
"@protobufjs/eventemitter": "^1.1.0",
5252
"@protobufjs/fetch": "^1.0.4",
53-
"@protobufjs/inquire": "^1.0.2",
54-
"@protobufjs/path": "^1.0.2",
55-
"@protobufjs/pool": "^1.0.5",
56-
"@protobufjs/utf8": "^1.0.7"
53+
"@protobufjs/inquire": "^1.1.0",
54+
"@protobufjs/path": "^1.1.1",
55+
"@protobufjs/pool": "^1.1.0",
56+
"@protobufjs/utf8": "^1.1.0"
5757
},
5858
"optionalDependencies": {
5959
"long": "^3.2.0",

tests/lib_eventemitter.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("../lib/eventemitter/tests");

0 commit comments

Comments
 (0)