Skip to content

Commit

Permalink
Other: Added lib/path tests and updated a few dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 25, 2017
1 parent 2b12fb7 commit 2db4305
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 10 additions & 2 deletions lib/path/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"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 <dcode+protobufjs@dcode.io>",
"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"
}
}
60 changes: 60 additions & 0 deletions lib/path/tests/index.js
Original file line number Diff line number Diff line change
@@ -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();
});
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/lib_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("../lib/path/tests");

0 comments on commit 2db4305

Please sign in to comment.