Skip to content

Commit

Permalink
Merge pull request #29 from fengmk2/component
Browse files Browse the repository at this point in the history
support component
  • Loading branch information
JacksonTian committed Jul 9, 2013
2 parents e208ee8 + d1aa28f commit 4bf057d
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,4 +1,6 @@
lib-cov
build
components
coverage.html
*.seed
*.log
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Expand Up @@ -5,3 +5,5 @@ Makefile
logo.png
jsdoc/
.jshintrc
build/
components/
17 changes: 15 additions & 2 deletions Makefile
Expand Up @@ -3,6 +3,15 @@ REPORTER = spec
TIMEOUT = 10000
MOCHA_OPTS =

build: index.js components
@component build --dev

components: component.json
@component install --dev

clean:
@rm -rf components build

install-test:
@NODE_ENV=test npm install

Expand All @@ -14,10 +23,14 @@ test: install-test
$(TESTS)

test-cov:
@$(MAKE) test REPORTER=dot
@rm -rf coverage.html
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov
@ls -lh coverage.html

test-all: test test-cov

.PHONY: install-test test test-cov test-all
test-component: build
@open test/test_component.html

.PHONY: build components clean install-test test test-cov test-all
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -70,6 +70,13 @@ $ npm install eventproxy
```js
var EventProxy = require('eventproxy');
```

### Component

```bash
$ component install JacksonTian/eventproxy
```

### 前端用户
以下示例均指向Github的源文件地址,您也可以[下载源文件](https://raw.github.com/JacksonTian/eventproxy/master/lib/eventproxy.js)到你自己的项目中。整个文件注释全面,带注释和空行,一共约500行。为保证EventProxy的易嵌入,项目暂不提供压缩版。用户可以自行采用Uglify、YUI Compressor或Google Closure Complier进行压缩。

Expand Down
21 changes: 21 additions & 0 deletions component.json
@@ -0,0 +1,21 @@
{
"name": "eventproxy",
"repo": "JacksonTian/eventproxy",
"description": "An implementation of task/event based asynchronous pattern.",
"version": "0.2.5",
"keywords": [
"event",
"task-base",
"event machine",
"nested callback terminator"
],
"dependencies": {
},
"development": {
"chaijs/chai": "*",
"fengmk2/pedding": "*"
},
"main": "lib/eventproxy.js",
"scripts": ["lib/eventproxy.js"],
"license": "MIT"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
}
},
"travis-cov": {
"threshold": 70
"threshold": 97
}
},
"repository": {
Expand Down
48 changes: 39 additions & 9 deletions test/test.js
@@ -1,8 +1,38 @@
var assert = require('chai').assert;
var should = require('chai').should();
var EventProxy = require('../');
var pedding = require('pedding');
var fs = require('fs');

try {
var EventProxy = require('../');
var http = require('http');
var fs = require('fs');
} catch (e) {
var EventProxy = require('eventproxy');
var http = {
get: function (options, callback) {
setTimeout(function () {
callback({
statusCode: 200
});
}, 0);
}
};
var __filename = 'mock_file.txt';
var fs = {
readFile: function (filename, encode, callback) {
if (typeof encode === 'function') {
callback = encode;
encode = null;
}
setTimeout(function () {
if (filename === 'not exist file') {
return callback(new Error('ENOENT, open \'not exist file\''));
}
callback(null, 'Foo bar baz');
}, 10);
}
};
}

describe("EventProxy", function () {
describe('constructor', function () {
Expand Down Expand Up @@ -391,7 +421,7 @@ describe("EventProxy", function () {
done();
});
fs.readFile(__filename, ep.done('data'));
require('http').get({ host: 'cnodejs.org' }, function (res) {
http.get({ host: 'cnodejs.org' }, function (res) {
should.exist(res);
res.statusCode.should.equal(200);
ep.emit('cnodejs', res);
Expand All @@ -404,22 +434,22 @@ describe("EventProxy", function () {

it('should success callback after all event emit', function (done) {
done = pedding(3, done);
var ep = EventProxy.create('data', 'dirs', 'cnodejs', function (data, dirs, cnodejs) {
var ep = EventProxy.create('data', 'data2', 'cnodejs', function (data, data2, cnodejs) {
should.exist(data);
should.exist(dirs);
should.exist(data2);
should.exist(cnodejs);
done();
}, function (err) {
throw new Error('should not call this');
});
fs.readFile(__filename, ep.done('data'));
require('http').get({ host: 'cnodejs.org' }, function (res) {
http.get({ host: 'cnodejs.org' }, function (res) {
assert.deepEqual(res.statusCode, 200);
ep.emit('cnodejs', res);
done();
});
process.nextTick(function () {
fs.readdir(__dirname, ep.done('dirs'));
fs.readFile(__filename, ep.done('data2'));
done();
});
});
Expand All @@ -442,7 +472,7 @@ describe("EventProxy", function () {
});

fs.readFile(__filename, ep.done('data'));
require('http').get({ host: 'nodejs.org' }, function (res) {
http.get({ host: 'nodejs.org' }, function (res) {
assert.deepEqual(res.statusCode, 200);
ep.emit('cnodejs', res);
done();
Expand All @@ -460,7 +490,7 @@ describe("EventProxy", function () {
mockGet('fooquery2', ep.done('mockGet2'));

process.nextTick(function () {
fs.readdir(__dirname, ep.done('dirs'));
fs.readFile(__filename, ep.done('dirs'));
done();
});
});
Expand Down
19 changes: 19 additions & 0 deletions test/test_component.html
@@ -0,0 +1,19 @@
<html>
<head>
<title>eventproxy tests</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../build/build.js"></script>
<script>
mocha.setup('bdd');
</script>
<script src="test.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

0 comments on commit 4bf057d

Please sign in to comment.