Skip to content

Commit d1aa28f

Browse files
committed
support component
1 parent e208ee8 commit d1aa28f

8 files changed

+106
-12
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
lib-cov
2+
build
3+
components
24
coverage.html
35
*.seed
46
*.log

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Makefile
55
logo.png
66
jsdoc/
77
.jshintrc
8+
build/
9+
components/

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ REPORTER = spec
33
TIMEOUT = 10000
44
MOCHA_OPTS =
55

6+
build: index.js components
7+
@component build --dev
8+
9+
components: component.json
10+
@component install --dev
11+
12+
clean:
13+
@rm -rf components build
14+
615
install-test:
716
@NODE_ENV=test npm install
817

@@ -14,10 +23,14 @@ test: install-test
1423
$(TESTS)
1524

1625
test-cov:
17-
@$(MAKE) test REPORTER=dot
26+
@rm -rf coverage.html
1827
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html
1928
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov
29+
@ls -lh coverage.html
2030

2131
test-all: test test-cov
2232

23-
.PHONY: install-test test test-cov test-all
33+
test-component: build
34+
@open test/test_component.html
35+
36+
.PHONY: build components clean install-test test test-cov test-all

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ $ npm install eventproxy
7070
```js
7171
var EventProxy = require('eventproxy');
7272
```
73+
74+
### Component
75+
76+
```bash
77+
$ component install JacksonTian/eventproxy
78+
```
79+
7380
### 前端用户
7481
以下示例均指向Github的源文件地址,您也可以[下载源文件](https://raw.github.com/JacksonTian/eventproxy/master/lib/eventproxy.js)到你自己的项目中。整个文件注释全面,带注释和空行,一共约500行。为保证EventProxy的易嵌入,项目暂不提供压缩版。用户可以自行采用Uglify、YUI Compressor或Google Closure Complier进行压缩。
7582

component.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "eventproxy",
3+
"repo": "JacksonTian/eventproxy",
4+
"description": "An implementation of task/event based asynchronous pattern.",
5+
"version": "0.2.5",
6+
"keywords": [
7+
"event",
8+
"task-base",
9+
"event machine",
10+
"nested callback terminator"
11+
],
12+
"dependencies": {
13+
},
14+
"development": {
15+
"chaijs/chai": "*",
16+
"fengmk2/pedding": "*"
17+
},
18+
"main": "lib/eventproxy.js",
19+
"scripts": ["lib/eventproxy.js"],
20+
"license": "MIT"
21+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
},
3232
"travis-cov": {
33-
"threshold": 70
33+
"threshold": 97
3434
}
3535
},
3636
"repository": {

test/test.js

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
var assert = require('chai').assert;
22
var should = require('chai').should();
3-
var EventProxy = require('../');
43
var pedding = require('pedding');
5-
var fs = require('fs');
4+
5+
try {
6+
var EventProxy = require('../');
7+
var http = require('http');
8+
var fs = require('fs');
9+
} catch (e) {
10+
var EventProxy = require('eventproxy');
11+
var http = {
12+
get: function (options, callback) {
13+
setTimeout(function () {
14+
callback({
15+
statusCode: 200
16+
});
17+
}, 0);
18+
}
19+
};
20+
var __filename = 'mock_file.txt';
21+
var fs = {
22+
readFile: function (filename, encode, callback) {
23+
if (typeof encode === 'function') {
24+
callback = encode;
25+
encode = null;
26+
}
27+
setTimeout(function () {
28+
if (filename === 'not exist file') {
29+
return callback(new Error('ENOENT, open \'not exist file\''));
30+
}
31+
callback(null, 'Foo bar baz');
32+
}, 10);
33+
}
34+
};
35+
}
636

737
describe("EventProxy", function () {
838
describe('constructor', function () {
@@ -391,7 +421,7 @@ describe("EventProxy", function () {
391421
done();
392422
});
393423
fs.readFile(__filename, ep.done('data'));
394-
require('http').get({ host: 'cnodejs.org' }, function (res) {
424+
http.get({ host: 'cnodejs.org' }, function (res) {
395425
should.exist(res);
396426
res.statusCode.should.equal(200);
397427
ep.emit('cnodejs', res);
@@ -404,22 +434,22 @@ describe("EventProxy", function () {
404434

405435
it('should success callback after all event emit', function (done) {
406436
done = pedding(3, done);
407-
var ep = EventProxy.create('data', 'dirs', 'cnodejs', function (data, dirs, cnodejs) {
437+
var ep = EventProxy.create('data', 'data2', 'cnodejs', function (data, data2, cnodejs) {
408438
should.exist(data);
409-
should.exist(dirs);
439+
should.exist(data2);
410440
should.exist(cnodejs);
411441
done();
412442
}, function (err) {
413443
throw new Error('should not call this');
414444
});
415445
fs.readFile(__filename, ep.done('data'));
416-
require('http').get({ host: 'cnodejs.org' }, function (res) {
446+
http.get({ host: 'cnodejs.org' }, function (res) {
417447
assert.deepEqual(res.statusCode, 200);
418448
ep.emit('cnodejs', res);
419449
done();
420450
});
421451
process.nextTick(function () {
422-
fs.readdir(__dirname, ep.done('dirs'));
452+
fs.readFile(__filename, ep.done('data2'));
423453
done();
424454
});
425455
});
@@ -442,7 +472,7 @@ describe("EventProxy", function () {
442472
});
443473

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

462492
process.nextTick(function () {
463-
fs.readdir(__dirname, ep.done('dirs'));
493+
fs.readFile(__filename, ep.done('dirs'));
464494
done();
465495
});
466496
});

test/test_component.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>eventproxy tests</title>
4+
<meta charset="UTF-8">
5+
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
6+
</head>
7+
<body>
8+
<div id="mocha"></div>
9+
<script src="../node_modules/mocha/mocha.js"></script>
10+
<script src="../build/build.js"></script>
11+
<script>
12+
mocha.setup('bdd');
13+
</script>
14+
<script src="test.js"></script>
15+
<script>
16+
mocha.run();
17+
</script>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)