diff --git a/Makefile b/Makefile index 9b2f33b65..2b35e6b2e 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,29 @@ TESTS = $(shell ls -S `find test -type f -name "*.test.js" -print`) REPORTER = tap TIMEOUT = 30000 MOCHA_OPTS = +REGISTRY = --registry=http://r.cnpmjs.org install: - @npm install --registry=http://r.cnpmjs.org \ + @npm install $(REGISTRY) \ --disturl=http://dist.cnpmjs.org jshint: install @-./node_modules/.bin/jshint ./ -test: install +pretest: + @mysql -uroot -e 'DROP DATABASE IF EXISTS cnpmjs_test;' + @mysql -uroot -e 'CREATE DATABASE cnpmjs_test;' + @mysql -uroot 'cnpmjs_test' < ./docs/db.sql + @mysql -uroot 'cnpmjs_test' -e 'show tables;' + +test: install pretest @NODE_ENV=test ./node_modules/.bin/mocha \ --harmony-generators \ --reporter $(REPORTER) \ --timeout $(TIMEOUT) \ --require should \ - --require co-mocha\ + --require co-mocha \ + --require ./test/init.js \ $(MOCHA_OPTS) \ $(TESTS) @@ -28,7 +36,8 @@ test-cov cov: install --reporter $(REPORTER) \ --timeout $(TIMEOUT) \ --require should \ - --require co-mocha\ + --require co-mocha \ + --require ./test/init.js \ $(MOCHA_OPTS) \ $(TESTS) @./node_modules/.bin/cov coverage diff --git a/README.md b/README.md index 48dfb6828..5e8424e48 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,18 @@ only need to change the registry in config. Even include manual synchronization ## Develop -**Notice**: need node version >=0.11.9 +### Dependencies + +* [node](http://nodejs.org) >=0.11.9 +* [mysql](http://dev.mysql.com/downloads/), include `mysqld` and `mysql cli` + +### Start MySQL + +```bash +$ nohup mysqld & +``` + +### Clone codes and run test ```bash # clone from git diff --git a/config/index.js b/config/index.js index ac2adea9d..a16befb77 100644 --- a/config/index.js +++ b/config/index.js @@ -38,13 +38,13 @@ var config = { // mysql config mysqlServers: [ { - host: 'keydiary.mysql.rds.aliyuncs.com', // 'db4free.net' + host: '127.0.0.1', port: 3306, - user: 'cnpmjs', - password: 'cnpmjs123' + user: 'root', + password: '' } ], - mysqlDatabase: 'cnpmjstest', + mysqlDatabase: 'cnpmjs_test', mysqlMaxConnections: 4, mysqlQueryTimeout: 5000, diff --git a/package.json b/package.json index 0e7047cf0..df45234cf 100644 --- a/package.json +++ b/package.json @@ -11,19 +11,19 @@ }, "dependencies": { "co": "3.0.5", - "copy-to": "0.0.2", "co-gather": "0.0.1", - "co-read": "0.0.1", + "co-read": "0.0.2", "co-redis": "1.1.0", - "co-urllib": "0.1.3", + "co-urllib": "0.2.0", "co-write": "0.3.0", - "debug": "0.7.4", - "eventproxy": "0.3.0", + "copy-to": "0.0.3", + "debug": "0.8.0", + "eventproxy": "0.3.1", "giturl": "0.0.2", "graceful": "0.0.6", "gravatar": "1.0.6", "humanize-number": "0.0.2", - "koa": "0.5.1", + "koa": "0.5.2", "koa-limit": "1.0.0", "koa-markdown": "0.0.3", "koa-middlewares": "0.1.3", @@ -34,7 +34,7 @@ "mkdirp": "0.3.5", "moment": "2.5.1", "ms": "0.6.2", - "multiline": "0.2.0", + "multiline": "0.3.2", "mysql": "2.1.1", "nodemailer": "0.6.1", "qn": "0.2.1", @@ -42,7 +42,7 @@ "redis": "0.10.1", "semver": "2.2.1", "thunkify-wrap": "0.1.1", - "utility": "0.1.11" + "utility": "0.1.12" }, "devDependencies": { "autod": ">=0.0.13", @@ -55,8 +55,8 @@ "mm": "0.2.1", "mocha": "*", "pedding": "0.0.3", - "should": "3.1.3", - "supertest": "0.9.2" + "should": "3.3.0", + "supertest": "0.10.0" }, "homepage": "https://github.com/cnpm/cnpmjs.org", "repository": { diff --git a/test/init.js b/test/init.js new file mode 100644 index 000000000..d4fddc334 --- /dev/null +++ b/test/init.js @@ -0,0 +1,32 @@ +/**! + * cnpmjs.org - test/init.js + * + * Copyright(c) fengmk2 and other contributors. + * MIT Licensed + * + * Authors: + * fengmk2 (http://fengmk2.github.com) + */ + +'use strict'; + +/** + * Module dependencies. + */ + +var crypto = require('crypto'); +var utility = require('utility'); +var User = require('../proxy/user'); + +var user = { + name: 'cnpmjstest10', + email: 'fengmk2@gmail.com', + // password: 'cnpmjstest10', + ip: '127.0.0.1' +}; +user.salt = crypto.randomBytes(30).toString('hex'); +user.password_sha = utility.sha1(user.name + user.salt); + +User.add(user, function (err, result) { + console.log(err); +}); diff --git a/test/proxy/module.test.js b/test/proxy/module.test.js index 8dd9e5fe3..c5c5fdf86 100644 --- a/test/proxy/module.test.js +++ b/test/proxy/module.test.js @@ -38,8 +38,17 @@ describe('proxy/module.test.js', function () { }); describe('search()', function () { - it('should search modules', function (done) { - Module.search('as', function (err, data) { + before(function (done) { + Module.addKeywords('aaaa', 'mock aaaaaa', ['aa', 'bb', 'cc'], function (err, results) { + should.not.exist(err); + results.should.be.an.Array; + results.should.length(3); + done(); + }); + }); + + it.skip('should search modules', function (done) { + Module.search('mock', function (err, data) { should.not.exist(err); data.should.have.keys('keywordMatchs', 'searchMatchs'); data.searchMatchs.length.should.above(0); @@ -74,13 +83,8 @@ describe('proxy/module.test.js', function () { }); }); + var mockName = 'aa' + Date.now(); describe('addKeywords()', function () { - var mockName = 'aa' + Date.now(); - - after(function (done) { - mysql.query('DELETE FROM module_keyword WHERE name=?', [mockName], done); - }); - it('should add diff keywords to module', function (done) { Module.addKeywords(mockName, mockName, ['aa', 'bb', 'cc'], function (err, results) { should.not.exist(err); @@ -91,10 +95,11 @@ describe('proxy/module.test.js', function () { }); it('should add same keywords to module', function (done) { - Module.addKeywords('aa', 'desc aa', ['aa', 'bb', 'cc'], function (err, results) { + Module.addKeywords(mockName, 'desc aa', ['aa', 'bb', 'cc'], function (err, results) { should.not.exist(err); results.should.be.an.Array; - results.should.length(0); + results.should.length(3); + // results.should.length(0); done(); }); }); @@ -102,7 +107,7 @@ describe('proxy/module.test.js', function () { describe('getKeywords()', function () { it('should get aa module keywords', function (done) { - Module.getKeywords('aa', function (err, keywords) { + Module.getKeywords(mockName, function (err, keywords) { should.not.exist(err); keywords.should.eql(['aa', 'bb', 'cc']); done();