Permalink
Browse files

passing tests

  • Loading branch information...
1 parent f47ce96 commit 965fc93e5ffa064930d5bc49e233d3e9ea7826bd @substack committed Jun 14, 2012
Showing with 48 additions and 2 deletions.
  1. +1 −2 index.js
  2. +43 −0 test/exports.js
  3. +1 −0 test/files/a.txt
  4. +1 −0 test/files/a.txt.js
  5. +1 −0 test/files/b.txt
  6. +1 −0 test/files/b.txt.js
View
3 index.js
@@ -14,7 +14,6 @@ module.exports = function (files, opts) {
var ext = path.extname(file);
if (opts.ext && ext !== ext) return;
if (ext === '.js') return; // already a js file, NICE TRY
- emitter.emit('started', file);
var rs = fs.createReadStream(file);
rs.on('error', emitter.emit.bind(emitter, 'error'));
@@ -28,7 +27,7 @@ module.exports = function (files, opts) {
});
rs.on('end', function () {
ws.end('"');
- emitter.emit('finished', file);
+ emitter.emit('export', file);
if (--pending === 0) emitter.emit('end');
});
});
View
43 test/exports.js
@@ -0,0 +1,43 @@
+var test = require('tap').test;
+var exportify = require('../');
+var fs = require('fs');
+var path = require('path');
+var existsSync = fs.existsSync || path.existsSync;
+
+(function () {
+ // clean out the directory
+ var files = fs.readdirSync(__dirname + '/files');
+ files.forEach(function (file) {
+ if (/\.js$/.test(file)) {
+ fs.unlinkSync(__dirname + '/files/' + file);
+ }
+ });
+})();
+
+var txt = {
+ a : fs.readFileSync(__dirname + '/files/a.txt', 'utf8'),
+ b : fs.readFileSync(__dirname + '/files/b.txt', 'utf8'),
+};
+
+test('package up some files', function (t) {
+ t.plan(5);
+
+ var files = [ 'a.txt', 'b.txt' ]
+ .map(function (file) { return __dirname + '/files/' + file })
+ ;
+ var ex = exportify(files);
+
+ var exported = [];
+ ex.on('export', function (file) {
+ exported.push(file);
+ });
+ ex.on('end', function () {
+ process.nextTick(function () {
+ t.same(exported.sort(), files.sort());
+ t.ok(existsSync(__dirname + '/files/a.txt.js'));
+ t.ok(existsSync(__dirname + '/files/b.txt.js'));
+ t.equal(txt.a, require('./files/a.txt.js'));
+ t.equal(txt.b, require('./files/b.txt.js'));
+ });
+ });
+});
View
1 test/files/a.txt
@@ -0,0 +1 @@
+beep
View
1 test/files/a.txt.js
@@ -0,0 +1 @@
+module.exports="beep\n"
View
1 test/files/b.txt
@@ -0,0 +1 @@
+boop
View
1 test/files/b.txt.js
@@ -0,0 +1 @@
+module.exports="boop\n"

0 comments on commit 965fc93

Please sign in to comment.