From ed17eeb2322c748e337bf4a91b511eaa92c86c6e Mon Sep 17 00:00:00 2001 From: jysperm Date: Sat, 1 Nov 2014 00:32:31 +0800 Subject: [PATCH] full test script --- .travis.yml | 2 + app.coffee | 13 +--- core/test/billing.test.coffee | 2 +- package.json | 7 ++- sample/rpvhost.config.coffee | 4 +- sample/travis-ci.config.coffee | 69 ---------------------- test/{support => }/env.coffee | 9 +++ test/full-test.coffee | 27 +++++++++ test/{support => }/reporter-cov-summary.js | 0 9 files changed, 47 insertions(+), 86 deletions(-) delete mode 100644 sample/travis-ci.config.coffee rename test/{support => }/env.coffee (77%) create mode 100644 test/full-test.coffee rename test/{support => }/reporter-cov-summary.js (100%) diff --git a/.travis.yml b/.travis.yml index d02550c..4833bc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ node_js: - 0.11 - 0.10 +script: npm run test-full + services: - mongodb - redis-server diff --git a/app.coffee b/app.coffee index 6810d78..d0b5d45 100755 --- a/app.coffee +++ b/app.coffee @@ -48,22 +48,13 @@ do -> config_path = path.join __dirname, 'config.coffee' unless fs.existsSync config_path - unless process.env.TRAVIS == 'true' - app.deprecate 'config.coffee not found, copy sample config to ./config.coffee' - - default_config = 'core' - else - default_config = 'travis-ci' - - fs.writeFileSync config_path, fs.readFileSync path.join __dirname, "./sample/#{default_config}.config.coffee" + app.deprecate 'config.coffee not found, copy sample config to ./config.coffee' + fs.writeFileSync config_path, fs.readFileSync path.join __dirname, "./sample/core.config.coffee" fs.chmodSync config_path, 0o750 config = require './config' -if process.env.NODE_ENV == 'test' - config.web.listen = require('./sample/travis-ci.config').web.listen - do -> if fs.existsSync config.web.listen fs.unlinkSync config.web.listen diff --git a/core/test/billing.test.coffee b/core/test/billing.test.coffee index 149ea42..0999fc3 100644 --- a/core/test/billing.test.coffee +++ b/core/test/billing.test.coffee @@ -48,7 +48,7 @@ describe 'billing', -> expect(billing.isForceFreeze(account)).to.not.ok it 'should be true when balance below then 0', -> - account.billing.plans = ['sample'] + account.billing.plans = ['billing_test'] account.billing.balance = -5 expect(billing.isForceFreeze(account)).to.be.ok diff --git a/package.json b/package.json index 29bcd3a..8a464d2 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,10 @@ "scripts": { "start": "./node_modules/.bin/coffee app.coffee", "migrate": "./node_modules/.bin/coffee migration/migrate.coffee", - "test": "COV_TEST=true ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/support/env --reporter test/support/reporter-cov-summary.js -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test", - "test-only": "./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/support/env -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test", - "test-cov-html": "COV_TEST=true ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/support/env --reporter html-cov -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test > coverage-reporter.html" + "test": "COV_TEST=true ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/env --reporter test/reporter-cov-summary.js -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test", + "test-only": "./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/env -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test", + "test-full": "./node_modules/.bin/coffee test/full-test.coffee", + "test-cov-html": "COV_TEST=true ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/env --reporter html-cov -- core/test/*.test.coffee core/test/*/*.test.coffee plugin/*/test > coverage-reporter.html" }, "bin": { "rp-fix-permissions": "./bin/rp-fix-permissions.coffee", diff --git a/sample/rpvhost.config.coffee b/sample/rpvhost.config.coffee index fd64c00..28f3251 100644 --- a/sample/rpvhost.config.coffee +++ b/sample/rpvhost.config.coffee @@ -14,8 +14,8 @@ module.exports = default_timezone: 'Asia/Shanghai' plugin: - available_extensions: ['rpvhost', 'bitcoin', 'wiki'] - available_services: ['ssh', 'linux'] + available_extensions: [] + available_services: [] billing: currency: 'CNY' diff --git a/sample/travis-ci.config.coffee b/sample/travis-ci.config.coffee deleted file mode 100644 index 59bf37f..0000000 --- a/sample/travis-ci.config.coffee +++ /dev/null @@ -1,69 +0,0 @@ -module.exports = - web: - t_name: 'plugins.rpvhost.site_name' - url: 'http://rp.rpvhost.net' - listen: 12558 - google_analytics_id: '' - - account: - cookie_time: 30 * 24 * 3600 * 1000 - - i18n: - available_language: ['zh_CN', 'en'] - default_language: 'zh_CN' - default_timezone: 'Asia/Shanghai' - - plugin: - available_extensions: [] - available_services: [] - - billing: - currency: 'CNY' - - force_freeze: - when_balance_below: 0 - when_arrears_above: 0 - - billing_cycle: 10 * 60 * 1000 - - plans: - sample: - t_name: 'plans.sample.name' - t_description: 'plans.sample.name.description' - - billing_by_time: - unit: 24 * 3600 * 1000 - price: 10 / 30 - - services: [] - resources: {} - - test: - t_name: 'plans.test.name' - t_description: 'plans.test.name.description' - - billing_by_usage: - auto_leave: 7 * 24 * 3600 * 1000 - - services: [] - resources: {} - - mongodb: - host: 'localhost' - name: 'RootPanel' - - redis: - host: '127.0.0.1' - port: 6379 - prefix: 'RP' - - email: - send_from: 'robot@rpvhost.net' - - account: - service: 'Postmark' - auth: - user: 'postmark-api-token' - pass: 'postmark-api-token' - - plugins: {} diff --git a/test/support/env.coffee b/test/env.coffee similarity index 77% rename from test/support/env.coffee rename to test/env.coffee index 506f3be..c789b33 100644 --- a/test/support/env.coffee +++ b/test/env.coffee @@ -25,3 +25,12 @@ global.namespace = {} chai.should() chai.config.includeStack = true + +config = require '../config' +config.web.listen = 12558 + +if process.env.TRAVIS == 'true' + config.mongodb.user = undefined + config.mongodb.password = undefined + + config.redis.password = undefined diff --git a/test/full-test.coffee b/test/full-test.coffee new file mode 100644 index 0000000..838945b --- /dev/null +++ b/test/full-test.coffee @@ -0,0 +1,27 @@ +child_process = require 'child_process' +async = require 'async' +fs = require 'fs' +_ = require 'underscore' + +async.eachSeries fs.readdirSync("#{__dirname}/../sample"), (filename, callback) -> + fs.writeFileSync "#{__dirname}/../config.coffee", fs.readFileSync "#{__dirname}/../sample/#{filename}" + + console.log "Config: #{filename}" + + proc = child_process.spawn "#{__dirname}/../node_modules/.bin/mocha", '--compilers coffee:coffee-script/register + --require test/env --reporter test/reporter-cov-summary.js -- + core/test/*.test.coffee core/test/*/*.test.coffee'.split(' '), + env: _.extend process.env, + COV_TEST: 'true' + + proc.stdout.pipe process.stdout + proc.stderr.pipe process.stderr + + proc.on 'close', (code) -> + if code + process.exit code + else + callback() + +, -> + process.exit 0 diff --git a/test/support/reporter-cov-summary.js b/test/reporter-cov-summary.js similarity index 100% rename from test/support/reporter-cov-summary.js rename to test/reporter-cov-summary.js