Skip to content

Commit

Permalink
更新依赖库(express)
Browse files Browse the repository at this point in the history
  • Loading branch information
codelint committed Oct 22, 2014
1 parent 718a8a7 commit 9f57f48
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 24 deletions.
5 changes: 2 additions & 3 deletions .gitignore
@@ -1,4 +1,3 @@
node_modules
.git
.svn
.idea
*.iml
node_modules
6 changes: 4 additions & 2 deletions bin/testful
@@ -1,9 +1,11 @@
#! /usr/bin/env node

try{
var testful = require('testful');
var testful = require('../lib');
console.log('import lib from "../lib"');
}catch(e){
var testful = require('./lib');
console.log(e);
var testful = require('testful');
}
var client = testful.client;
client.testful.main(process.argv, process.argv.length);
Expand Down
5 changes: 5 additions & 0 deletions command.history
@@ -0,0 +1,5 @@
#! /bin/bash

./bin/testful -d ./sample -f ./sample/server.context.js

git push -u origin master
5 changes: 3 additions & 2 deletions do_sample_test
@@ -1,3 +1,4 @@
#! /bin/bash

./bin/testful ./lib/client/testful.js -d ./sample -f ./sample/server.context.js
#
# ./bin/testful ./lib/client/testful.js -d ./sample -f ./sample/server.context.js
./bin/testful -d ./sample -f ./sample/server.context.js
26 changes: 26 additions & 0 deletions github.readme
@@ -0,0 +1,26 @@
Global setup:
Set up git
git config --global user.name "Your Name"
git config --global user.email codelint@foxmail.com
Add your public key

Next steps:
mkdir testful
cd testful
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:codelint/testful.git
git push -u origin master

Existing Git Repo?
cd existing_git_repo
git remote add origin git@github.com:codelint/testful.git
git push -u origin master

Importing a Subversion Repo?
Click here

When you're done:
Continue
8 changes: 6 additions & 2 deletions lib/RestTester.js
Expand Up @@ -187,7 +187,11 @@ var Tester = function(cases, context, callback) {
var ct = this.context;
var server = ct.server;
if (server) {
server.listen(ct.port);
server = server.listen(ct.port, function(){
var host = server.address().address;
var port = server.address().port;
console.log('Start mock server at http://%s:%s', host, port)
});
}
next();
});
Expand All @@ -199,7 +203,7 @@ var Tester = function(cases, context, callback) {
});
this.on(E.PRECLOSE, function() {//after test close the server
if(self.context.server) {
self.context.server.close();
//self.context.server.close();
}
})
};
Expand Down
18 changes: 14 additions & 4 deletions lib/client/testful.js
Expand Up @@ -9,7 +9,9 @@
var Tester = require('../RestTester.js');
var validate = require('lang').validate;
var util = require('util');
require('colors');
var assert = require('assert');
//var colors = require('colors');


function main(argv, argn) {
var opts = require('optimist')(argv)
Expand All @@ -19,6 +21,11 @@ function main(argv, argn) {
describe: "the cases file's suffix, it will work when '--basedir' specified",
'default': 'case.js',
string: true
}).options('colors', {
alias: "m",
describe: "colors mode (broswer or conosle)",
'default': 'console',
string: true
}).options('basedir', {
alias: "d",
describe: "the cases files parent's directory",
Expand Down Expand Up @@ -51,6 +58,10 @@ function main(argv, argn) {
opts.showHelp();
process.exit(0);
}
if (argv.colors){
var enhance = require("../vendor/colors.js");
enhance(argv.colors);
}
var logger = {
info: function(msg) {
console.log(util.format("[%s] %s", "info".blue, msg))
Expand Down Expand Up @@ -137,15 +148,15 @@ function main(argv, argn) {
var callee = arguments.callee;
if (fi >= files.length) {
outputReport(report);
return;
process.exit(report.fail);
}
var file = files[fi++];
var cases = fileToJson(file);
if (!cases) return callee();
// start to test....
var tester = new Tester(cases, context);
tester.onAfter(function(next, title, _case) {
validate.omatch(_case.expect, _case.actual);
assert.ok(validate.omatch(_case.actual, _case.expect), "actual.body do not match the expect.body");
next();
});
tester.onTeardown(function(next, title, _case) {
Expand Down Expand Up @@ -182,7 +193,6 @@ function main(argv, argn) {
s(report.fail).red))
}


initFiles(run);
}

Expand Down
7 changes: 4 additions & 3 deletions lib/server.mock.js
Expand Up @@ -7,11 +7,12 @@
*/


var bodyParser = require('body-parser');
var express = require('express');

function mock(port) {
var testServer = express.createServer();
testServer.use(express.bodyParser());
var testServer = express();
testServer.use(bodyParser());

testServer.get("/api/for/test/get", function(req, res) {
res.send({
Expand All @@ -32,4 +33,4 @@ function mock(port) {
return testServer;
}

module.exports = mock;
module.exports = mock;
22 changes: 16 additions & 6 deletions package.json
Expand Up @@ -2,24 +2,34 @@
"author": "inotseeyou <inotseeyou@gmail.com> (http://inotseeyou.com)",
"name": "testful",
"description": "test framework for restful service, just http test",
"version": "0.1.6",
"version": "1.0.1",
"repository": {
"url": "https://github.com/codelint/testful.git"
},
"licence":"MIT",
"licence": "MIT",
"main": "./lib/index.js",
"engines": {
"node": ">=0.5.10"
},
"dependencies": {
"lang" : ">= 0.1.13",
"colors" : ">= 0.5.1"
"lang": ">= 0.1.13",
"colors": ">= 0.5.1",
"findit": "= 0.1.2",
"express": "~4.9.8",
"body-parser": "~1.9.0"
},
"devDependencies": {
"expresso": "0.9.2"
},
"keywords": ["restful", "test", "testful", "framework", "simple", "http"],
"scripts":{
"keywords": [
"restful",
"test",
"testful",
"framework",
"simple",
"http"
],
"scripts": {
"test": "expresso ./lib/RestTester.test.js"
}
}
3 changes: 1 addition & 2 deletions pom.xml
Expand Up @@ -7,6 +7,5 @@
<groupId>testful</groupId>
<artifactId>testful</artifactId>
<version>1.0</version>


</project>
</project>

0 comments on commit 9f57f48

Please sign in to comment.