Skip to content

Commit

Permalink
chore: more test
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 28, 2015
1 parent 79aa97a commit 9709b69
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"build": "rm -rf lib && babel src --out-dir lib --ignore __tests__",
"test": "babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha --no-timeouts",
"debug": "./node_modules/.bin/mocha --require babel-core/register --no-timeouts",
"debug": "./node_modules/.bin/mocha --require babel-core/register --require babel-polyfill --no-timeouts",
"lint": "eslint --ext .js src",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
Expand All @@ -41,6 +41,7 @@
"babel-core": "~6.3.15",
"babel-istanbul": "^0.5.9",
"babel-plugin-add-module-exports": "~0.1.2",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "~6.3.13",
"babel-preset-stage-0": "~6.3.13",
"coveralls": "~2.11.4",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function createServer(_args, callback) {
join(__dirname, './plugins/serve-index'),
]);

const plugins = resolvePlugins(pluginNames, resolveDir, args);
const plugins = resolvePlugins(pluginNames, resolveDir, cwd);
function _applyPlugins(name, pluginArgs, _callback) {
return applyPlugins(plugins, name, context, pluginArgs, _callback);
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function resolvePlugins(pluginNames, resolveDir, cwd) {
return pluginNames.map(pluginName => resolvePlugin(pluginName, resolveDir, cwd));
}

export function expression(plugins, name, context = {}, pluginArgs, _callback = function noop() {}) {
export function applyPlugins(plugins, name, context = {}, pluginArgs, _callback = function noop() {}) {
if (!plugins || !plugins.length) return _callback();
let ret;

Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/plugin-run/plugin-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

var a = '';

module.exports = {
name: 'a',
'middleware.before': function() {
a = 'foo';
},
'middleware': function() {
return function *(next) {
if (this.url.indexOf('/foo') > -1) {
this.body = a;
return;
}
yield next;
};
},
};
27 changes: 23 additions & 4 deletions test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ import expect from 'expect';

const port = 12346;

describe.only('index', () => {
describe('index', () => {

before(done => {
dora({
plugins: [],
plugins: [
'./plugin-a',
],
port,
cwd: join(__dirname, 'fixtures/plugin-run'),
}, done);
});

it('plugin-a middleware', (done) => {
request(`http://localhost:${port}/foo`, (err, res, body) => {
expect(body).toEqual('foo');
done();
});
});

it('static', (done) => {
request(`http://localhost:${port}/index.js`, (err, res, body) => {
expect(body.trim()).toEqual('console.log(\'index\');');
done();
});
});

it('normal', () => {
expect(1).toEqual(1);
it('serve index', (done) => {
request(`http://localhost:${port}/`, (err, res, body) => {
expect(body.indexOf('<title>listing directory /</title>') > -1).toExist();
done();
});
});

});

0 comments on commit 9709b69

Please sign in to comment.