[Pkg-javascript-commits] [node-deps-sort] 13/79: using through2, a test

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:41:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-deps-sort.

commit ecc1edc2d8b1e443a07a1337493602dfece3bc78
Author: James Halliday <mail at substack.net>
Date:   Sun Jul 20 06:23:04 2014 -0700

    using through2, a test
---
 index.js        | 12 ++++-----
 package.json    | 79 +++++++++++++++++++++++++++++----------------------------
 test/indexed.js | 38 +++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 45 deletions(-)

diff --git a/index.js b/index.js
index d010717..28e4028 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,12 @@
-var through = require('through');
+var through = require('through2');
 
 module.exports = function (opts) {
     if (!opts) opts = {};
     
     var rows = [];
-    return through(write, end);
+    return through.obj(write, end);
     
-    function write (row) { rows.push(row) }
+    function write (row, enc, next) { rows.push(row); next() }
     
     function end () {
         var tr = this;
@@ -23,15 +23,15 @@ module.exports = function (opts) {
                 Object.keys(row.deps).forEach(function (key) {
                     row.indexDeps[key] = index[row.deps[key]];
                 });
-                tr.queue(row);
+                tr.push(row);
             });
         }
         else {
             rows.forEach(function (row) {
-                tr.queue(row);
+                tr.push(row);
             });
         }
-        tr.queue(null);
+        tr.push(null);
     }
     
     function cmp (a, b) {
diff --git a/package.json b/package.json
index bae9678..3c92b6a 100644
--- a/package.json
+++ b/package.json
@@ -1,41 +1,42 @@
 {
-    "name": "deps-sort",
-    "version": "0.1.2",
-    "description": "sort module-deps output for deterministic browserify bundles",
-    "main": "index.js",
-    "bin": {
-        "deps-sort": "bin/cmd.js"
-    },
-    "dependencies": {
-        "through": "~2.3.4",
-        "JSONStream": "~0.6.4",
-        "minimist": "~0.0.1"
-    },
-    "devDependencies": {
-        "tap": "~0.4.0"
-    },
-    "scripts": {
-        "test": "tap test/*.js"
-    },
-    "repository": {
-        "type": "git",
-        "url": "git://github.com/substack/deps-sort.git"
-    },
-    "homepage": "https://github.com/substack/deps-sort",
-    "keywords": [
-        "dependency",
-        "graph",
-        "browser",
-        "browserify",
-        "module-deps",
-        "browser-pack",
-        "sorted",
-        "determinism"
-    ],
-    "author": {
-        "name": "James Halliday",
-        "email": "mail at substack.net",
-        "url": "http://substack.net"
-    },
-    "license": "MIT"
+  "name": "deps-sort",
+  "version": "0.1.2",
+  "description": "sort module-deps output for deterministic browserify bundles",
+  "main": "index.js",
+  "bin": {
+    "deps-sort": "bin/cmd.js"
+  },
+  "dependencies": {
+    "JSONStream": "~0.6.4",
+    "minimist": "~0.0.1",
+    "through2": "~0.5.1"
+  },
+  "devDependencies": {
+    "tap": "~0.4.0",
+    "tape": "^2.13.4"
+  },
+  "scripts": {
+    "test": "tap test/*.js"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/substack/deps-sort.git"
+  },
+  "homepage": "https://github.com/substack/deps-sort",
+  "keywords": [
+    "dependency",
+    "graph",
+    "browser",
+    "browserify",
+    "module-deps",
+    "browser-pack",
+    "sorted",
+    "determinism"
+  ],
+  "author": {
+    "name": "James Halliday",
+    "email": "mail at substack.net",
+    "url": "http://substack.net"
+  },
+  "license": "MIT"
 }
diff --git a/test/indexed.js b/test/indexed.js
new file mode 100644
index 0000000..2066ea0
--- /dev/null
+++ b/test/indexed.js
@@ -0,0 +1,38 @@
+var sort = require('../');
+var test = require('tape');
+var through = require('through2');
+
+test('indexed', function (t) {
+    t.plan(1);
+    var s = sort({ index: true });
+    var rows = [];
+    function write (row, enc, next) { rows.push(row); next() }
+    function end () {
+        t.deepEqual(rows, [
+            {
+                id: '/bar.js',
+                deps: {},
+                index: 1,
+                indexDeps: {}
+            },
+            {
+                id: '/foo.js',
+                deps: { './bar': '/bar.js' },
+                index: 2,
+                indexDeps: { './bar': 1 }
+            },
+            {
+                id: '/main.js',
+                deps: { './foo': '/foo.js' },
+                index: 3,
+                indexDeps: { './foo': 2 }
+            },
+        ]);
+    }
+    s.pipe(through.obj(write, end));
+    
+    s.write({ id: '/main.js', deps: { './foo': '/foo.js' } });
+    s.write({ id: '/foo.js', deps: { './bar': '/bar.js' } });
+    s.write({ id: '/bar.js', deps: {} });
+    s.end();
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-deps-sort.git



More information about the Pkg-javascript-commits mailing list