From 2db4305ca67d003d57aa14eb23f25eb6c3672034 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Wed, 25 Jan 2017 16:30:58 +0100 Subject: [PATCH] Other: Added lib/path tests and updated a few dependencies --- README.md | 6 ++--- lib/path/package.json | 12 +++++++-- lib/path/tests/index.js | 60 +++++++++++++++++++++++++++++++++++++++++ package.json | 7 ++--- tests/lib_path.js | 1 + 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 lib/path/tests/index.js create mode 100644 tests/lib_path.js diff --git a/README.md b/README.md index 283603cd3..e6dc7b7bc 100644 --- a/README.md +++ b/README.md @@ -346,16 +346,16 @@ Additionally, TypeScript definitions of static modules are compatible with refle 1. Instead of using `new SomeMessage(...)`, always use `SomeMessage.create(...)` because reflection objects do not provide a constructor. 2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well (i.e. to be able to use `MyMessage.MyEnum` instead of `root.lookup("MyMessage.MyEnum")`). -For example, the following generates a `bundle.json` and a `bundle.d.ts`, but no static code: +For example, the following generates a JSON module `bundle.js` and a `bundle.d.ts`, but no static code: ``` -$> pbjs -t json-module -w commonjs -o bundle.json file1.proto file2.proto +$> pbjs -t json-module -w commonjs -o bundle.js file1.proto file2.proto $> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts - ``` ### On reflection vs. static code -While using .proto files requires the [full library][dist-full] (about 18.5kb gzipped) or JSON at least the [light library][dist-light] (about 15.5kb gzipped), pretty much all code but the relatively short descriptors is shared and all features including reflection and the parser are available. +While using .proto files directly requires the [full library][dist-full] (about 18.5kb gzipped) respectively pure reflection/JSON the [light library][dist-light] (about 15.5kb gzipped), pretty much all code but the relatively short descriptors is shared. Static code, on the other hand, requires just the [minimal library][dist-minimal] (about 6kb gzipped), but generates additional, albeit editable, source code without any reflection features. diff --git a/lib/path/package.json b/lib/path/package.json index 372630343..92d4d4942 100644 --- a/lib/path/package.json +++ b/lib/path/package.json @@ -1,7 +1,7 @@ { "name": "@protobufjs/path", "description": "A minimal path module to resolve Unix, Windows and URL paths alike.", - "version": "1.0.2", + "version": "1.0.3", "author": "Daniel Wirtz ", "repository": { "type": "git", @@ -9,5 +9,13 @@ }, "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" + } } \ No newline at end of file diff --git a/lib/path/tests/index.js b/lib/path/tests/index.js new file mode 100644 index 000000000..9c23bc969 --- /dev/null +++ b/lib/path/tests/index.js @@ -0,0 +1,60 @@ +var tape = require("tape"); + +var path = require(".."); + +tape.test("path", function(test) { + + test.ok(path.isAbsolute("X:\\some\\path\\file.js"), "should identify absolute windows paths"); + test.ok(path.isAbsolute("/some/path/file.js"), "should identify absolute unix paths"); + + test.notOk(path.isAbsolute("some\\path\\file.js"), "should identify relative windows paths"); + test.notOk(path.isAbsolute("some/path/file.js"), "should identify relative unix paths"); + + var paths = [ + { + actual: "X:\\some\\..\\.\\path\\\\file.js", + normal: "X:/path/file.js", + resolve: { + origin: "X:/path/origin.js", + expected: "X:/path/file.js" + } + }, { + actual: "some\\..\\.\\path\\\\file.js", + normal: "path/file.js", + resolve: { + origin: "X:/path/origin.js", + expected: "X:/path/path/file.js" + } + }, { + actual: "/some/.././path//file.js", + normal: "/path/file.js", + resolve: { + origin: "/path/origin.js", + expected: "/path/file.js" + } + }, { + actual: "some/.././path//file.js", + normal: "path/file.js", + resolve: { + origin: "", + expected: "path/file.js" + } + }, { + actual: ".././path//file.js", + normal: "../path/file.js" + }, { + actual: "/.././path//file.js", + normal: "/path/file.js" + } + ]; + + paths.forEach(function(p) { + test.equal(path.normalize(p.actual), p.normal, "should normalize " + p.actual); + if (p.resolve) { + test.equal(path.resolve(p.resolve.origin, p.actual), p.resolve.expected, "should resolve " + p.actual); + test.equal(path.resolve(p.resolve.origin, p.normal, true), p.resolve.expected, "should resolve " + p.normal + " (already normalized)"); + } + }); + + test.end(); +}); diff --git a/package.json b/package.json index 5e2401e33..3ecb76519 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,9 @@ "@types/long": "^3.0.31" }, "devDependencies": { - "@types/node": "7.0.3", + "@types/node": "7.0.4", "benchmark": "^2.1.3", - "browserify": "^13.3.0", + "browserify": "^14.0.0", "browserify-wrap": "^1.0.2", "bundle-collapser": "^1.2.1", "chalk": "^1.1.3", @@ -79,7 +79,8 @@ "gulp-header": "^1.8.8", "gulp-if": "^2.0.1", "gulp-sourcemaps": "^2.4.0", - "gulp-uglify": "^2.0.0", + "gulp-uglify": "^2.0.1", + "istanbul": "^0.4.5", "jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc", "jsdoc": "^3.4.2", "minimist": "^1.2.0", diff --git a/tests/lib_path.js b/tests/lib_path.js new file mode 100644 index 000000000..ff7c112ac --- /dev/null +++ b/tests/lib_path.js @@ -0,0 +1 @@ +require("../lib/path/tests");