Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
use local mysql for dev env. fix #308
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Apr 9, 2014
1 parent 9d660be commit 1b266d5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 30 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -34,15 +34,15 @@
"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",
"ready": "0.1.1",
"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",
Expand All @@ -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": {
Expand Down
32 changes: 32 additions & 0 deletions test/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**!
* cnpmjs.org - test/init.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (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);
});
27 changes: 16 additions & 11 deletions test/proxy/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -91,18 +95,19 @@ 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();
});
});
});

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();
Expand Down

0 comments on commit 1b266d5

Please sign in to comment.