Skip to content

Commit

Permalink
Other: Added eventemitter tests and updated micromodule dependencies …
Browse files Browse the repository at this point in the history
…(so far)
  • Loading branch information
dcodeIO committed Jan 25, 2017
1 parent 2db4305 commit 3fcd88c
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 89 deletions.
2 changes: 1 addition & 1 deletion lib/aspromise/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export = asPromise;
* @param {...*} params Function arguments
* @returns {Promise<*>} Promisified function
*/
function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;
declare function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;
2 changes: 1 addition & 1 deletion lib/aspromise/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/aspromise",
"description": "Returns a promise from a node-style callback function.",
"version": "1.0.6",
"version": "1.1.1",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
4 changes: 1 addition & 3 deletions lib/aspromise/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ var tape = require("tape");

var asPromise = require("..");

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

if (typeof Promise === "undefined")
return test.pass("not supported, skipping...");

test.test(this.name + " - resolve", function(test) {

function fn(arg1, arg2, callback) {
Expand Down
64 changes: 27 additions & 37 deletions lib/base64/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
export = base64;

/**
* A minimal base64 implementation for number arrays.
* @memberof util
* @namespace
* Calculates the byte length of a base64 encoded string.
* @param {string} string Base64 encoded string
* @returns {number} Byte length
*/
declare namespace base64 {

/**
* Calculates the byte length of a base64 encoded string.
* @param {string} string Base64 encoded string
* @returns {number} Byte length
*/
function length(string: string): number;
export function length(string: string): number;

/**
* Encodes a buffer to a base64 encoded string.
* @param {Uint8Array} buffer Source buffer
* @param {number} start Source start
* @param {number} end Source end
* @returns {string} Base64 encoded string
*/
function encode(buffer: Uint8Array, start: number, end: number): string;
/**
* Encodes a buffer to a base64 encoded string.
* @param {Uint8Array} buffer Source buffer
* @param {number} start Source start
* @param {number} end Source end
* @returns {string} Base64 encoded string
*/
export function encode(buffer: Uint8Array, start: number, end: number): string;

/**
* Decodes a base64 encoded string to a buffer.
* @param {string} string Source string
* @param {Uint8Array} buffer Destination buffer
* @param {number} offset Destination offset
* @returns {number} Number of bytes written
* @throws {Error} If encoding is invalid
*/
function decode(string: string, buffer: Uint8Array, offset: number): number;
/**
* Decodes a base64 encoded string to a buffer.
* @param {string} string Source string
* @param {Uint8Array} buffer Destination buffer
* @param {number} offset Destination offset
* @returns {number} Number of bytes written
* @throws {Error} If encoding is invalid
*/
export function decode(string: string, buffer: Uint8Array, offset: number): number;

/**
* Tests if the specified string appears to be base64 encoded.
* @param {string} string String to test
* @returns {boolean} `true` if it appears to be base64 encoded, otherwise false
*/
function test(string: string): boolean;
}
/**
* Tests if the specified string appears to be base64 encoded.
* @param {string} string String to test
* @returns {boolean} `true` if it appears to be base64 encoded, otherwise false
*/
export function test(string: string): boolean;
2 changes: 1 addition & 1 deletion lib/base64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/base64",
"description": "A minimal base64 implementation for number arrays.",
"version": "1.0.6",
"version": "1.1.1",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
12 changes: 10 additions & 2 deletions lib/eventemitter/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"name": "@protobufjs/eventemitter",
"description": "A minimal event emitter.",
"version": "1.0.5",
"version": "1.1.0",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/dcodeIO/protobuf.js.git"
},
"license": "BSD-3-Clause",
"main": "index.js",
"types": "index.d.ts"
"types": "index.d.ts",
"devDependencies": {
"istanbul": "^0.4.5",
"tape": "^4.6.3"
},
"scripts": {
"test": "tape tests/*.js",
"coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js"
}
}
47 changes: 47 additions & 0 deletions lib/eventemitter/tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var tape = require("tape");

var EventEmitter = require("..");

tape.test("eventemitter", function(test) {

var ee = new EventEmitter();
var fn;
var ctx = {};

test.doesNotThrow(function() {
ee.emit("a", 1);
ee.off();
ee.off("a");
ee.off("a", function() {});
}, "should not throw if no listeners are registered");

test.equal(ee.on("a", function(arg1) {
test.equal(this, ctx, "should be called with this = ctx");
test.equal(arg1, 1, "should be called with arg1 = 1");
}, ctx), ee, "should return itself when registering events");
ee.emit("a", 1);

ee.off("a");
test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");

ee.off();
test.same(ee._listeners, {}, "should remove all listeners when just calling off()");

ee.on("a", fn = function(arg1) {
test.equal(this, ctx, "should be called with this = ctx");
test.equal(arg1, 1, "should be called with arg1 = 1");
}, ctx).emit("a", 1);

ee.off("a", fn);
test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");

ee.on("a", function() {
test.equal(this, ee, "should be called with this = ee");
}).emit("a");

test.doesNotThrow(function() {
ee.off("a", fn);
}, "should not throw if no such listener is found");

test.end();
});
4 changes: 2 additions & 2 deletions lib/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"url": "https://github.com/dcodeIO/protobuf.js.git"
},
"dependencies": {
"@protobufjs/aspromise": "^1.0.5",
"@protobufjs/inquire": "^1.0.2"
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/inquire": "^1.1.0"
},
"license": "BSD-3-Clause",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion lib/inquire/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/inquire",
"description": "Requires a module only if available and hides the require call from bundlers.",
"version": "1.0.3",
"version": "1.1.0",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
46 changes: 18 additions & 28 deletions lib/path/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
export = path;

/**
* A minimal path module to resolve Unix, Windows and URL paths alike.
* @memberof util
* @namespace
* Tests if the specified path is absolute.
* @param {string} path Path to test
* @returns {boolean} `true` if path is absolute
*/
declare namespace path {

/**
* Tests if the specified path is absolute.
* @param {string} path Path to test
* @returns {boolean} `true` if path is absolute
*/
function isAbsolute(path: string): boolean;
export function isAbsolute(path: string): boolean;

/**
* Normalizes the specified path.
* @param {string} path Path to normalize
* @returns {string} Normalized path
*/
function normalize(path: string): string;
/**
* Normalizes the specified path.
* @param {string} path Path to normalize
* @returns {string} Normalized path
*/
export function normalize(path: string): string;

/**
* Resolves the specified include path against the specified origin path.
* @param {string} originPath Path to the origin file
* @param {string} includePath Include path relative to origin path
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
* @returns {string} Path to the include file
*/
function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
}
/**
* Resolves the specified include path against the specified origin path.
* @param {string} originPath Path to the origin file
* @param {string} includePath Include path relative to origin path
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
* @returns {string} Path to the include file
*/
export function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
2 changes: 1 addition & 1 deletion lib/path/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/path",
"description": "A minimal path module to resolve Unix, Windows and URL paths alike.",
"version": "1.0.3",
"version": "1.1.1",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion lib/pool/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/pool",
"description": "A general purpose buffer pool.",
"version": "1.0.6",
"version": "1.1.0",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
4 changes: 1 addition & 3 deletions lib/pool/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ var tape = require("tape");

var pool = require("..");

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

if (typeof Uint8Array === "undefined")
return test.pass("not supported, skipping...");

var alloc = pool(function(size) { return new Uint8Array(size); }, Uint8Array.prototype.subarray);

var buf1 = alloc(0);
Expand Down
2 changes: 1 addition & 1 deletion lib/utf8/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/utf8",
"description": "A minimal UTF8 implementation for number arrays.",
"version": "1.0.8",
"version": "1.1.0",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
"release": "npm run make && npm run changelog"
},
"dependencies": {
"@protobufjs/aspromise": "^1.0.5",
"@protobufjs/base64": "^1.0.5",
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/base64": "^1.1.1",
"@protobufjs/codegen": "^1.0.8",
"@protobufjs/eventemitter": "^1.0.5",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.0.4",
"@protobufjs/inquire": "^1.0.2",
"@protobufjs/path": "^1.0.2",
"@protobufjs/pool": "^1.0.5",
"@protobufjs/utf8": "^1.0.7"
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.1",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0"
},
"optionalDependencies": {
"long": "^3.2.0",
Expand Down
1 change: 1 addition & 0 deletions tests/lib_eventemitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("../lib/eventemitter/tests");

0 comments on commit 3fcd88c

Please sign in to comment.