Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fool2fish committed Nov 6, 2014
1 parent 46f7ca5 commit b372c4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 46 deletions.
16 changes: 8 additions & 8 deletions tests/config-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
var path = require('path')
var expect = require('expect.js')
var rewire = require('rewire')
var common = require('totoro-common')
var utilx = require('utilx')

var config = rewire('../lib/config')

var globalCfgPath = path.join(common.home, '.totoro', 'config.json')
var globalCfg = common.readCfgFile(globalCfgPath)
var globalCfgPath = path.join(utilx.home, '.totoro', 'config.json')
var globalCfg = utilx.readJSON(globalCfgPath)

var logCache = ''
config.__set__({
Expand All @@ -26,7 +26,7 @@ config.__set__({
describe('config', function() {

it('list config', function() {
common.writeCfgFile(globalCfgPath, {
utilx.writeJSON(globalCfgPath, {
serverHost: '127.0.0.1'
})
config()
Expand All @@ -35,13 +35,13 @@ describe('config', function() {
})

it('list empty config', function() {
common.writeCfgFile(globalCfgPath, {})
utilx.writeJSON(globalCfgPath, {})
config()
expect(logCache).to.be('\n No global configuration.\n')
})

it('modify config', function() {
common.writeCfgFile(globalCfgPath, {
utilx.writeJSON(globalCfgPath, {
serverHost: '127.0.0.1'
})
config({serverHost: '0.0.0.0'})
Expand All @@ -50,7 +50,7 @@ describe('config', function() {
})

it('delete config', function() {
common.writeCfgFile(globalCfgPath, {
utilx.writeJSON(globalCfgPath, {
serverHost: '127.0.0.1'
})
config({serverHost: ''})
Expand All @@ -63,7 +63,7 @@ describe('config', function() {
})

after(function(){
common.writeCfgFile(globalCfgPath, globalCfg)
utilx.writeJSON(globalCfgPath, globalCfg)
})

})
55 changes: 17 additions & 38 deletions tests/handle-cfg-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var fs = require('fs')
var path = require('path')
var expect = require('expect.js')
var rewire = require('rewire')
//var common = require('totoro-common')

var handleCfg = rewire('../lib/handle-cfg')

Expand Down Expand Up @@ -45,14 +44,14 @@ describe('handle-cfg', function() {
var _handleClientRoot = handleCfg.__get__('handleClientRoot')

it('runner is file', function() {
var projDir = path.join(__dirname, '..', 'examples', 'simple')
var testDir = path.join(projDir, 'tests')
var root = path.join(__dirname, '..', 'examples')
var testDir = path.join(root, 'simple', 'tests')
var runner = path.join(testDir, 'runner.html')
var cfg = {
runner: runner
}
_handleClientRoot(cfg)
expect(cfg.root).to.be(projDir)
expect(cfg.root).to.be(root)
})

it('runner is url', function() {
Expand All @@ -62,7 +61,7 @@ describe('handle-cfg', function() {
_handleClientRoot(cfg)

expect(cfg.root).to.be(undefined)
expect(logCache).to.be('None of runner or adapter is existed file, not need root.')
expect(logCache).to.be('None of runner or adapter is file, not need root.')
})
})

Expand All @@ -71,11 +70,11 @@ describe('handle-cfg', function() {
var _findRunnerRoot = handleCfg.__get__('findRunnerRoot')

it('no relative link was out of project', function() {
var proj = path.join(__dirname, '..', 'examples', 'simple')
var runner = path.join(proj, 'tests', 'runner.html')
var root = path.join(__dirname, '..', 'examples')
var runner = path.join(root, 'simple', 'tests', 'runner.html')
var rt = _findRunnerRoot(runner)

expect(rt).to.be(proj)
expect(rt).to.be(root)
})

it.skip('relative link was out of project', function() {
Expand Down Expand Up @@ -133,8 +132,7 @@ describe('handle-cfg', function() {
var cfg = {runner: 'runner.html'}
_handleRunner(cfg)

expect(logCache).to.match(/Specified runner <runner\.html> is not available\./)

expect(cfg.runner).to.be('runner.html')
process.chdir(cwd)
})

Expand Down Expand Up @@ -269,42 +267,33 @@ describe('handle-cfg', function() {
it('runner is file but adapter is url', function() {
_handleAdapter({
runner: runnerPath,
adapter: adapterUrl
adapter: adapterUrl,
proxy: true
})

expect(logCache).to.be('Runner is file, can not specify a url adapter.')
expect(logCache).to.be('Runner is a file, the adapter cannot be a url.')
})

it('runner is url but adapter is file', function() {
_handleAdapter({
runner: runnerUrl,
adapter: adapterPath
adapter: adapterPath,
proxy: true
})

expect(logCache).to.match(/Runner is url, can not specify a file adapter\./)
expect(logCache).to.match(/Runner is a url, the adapter cannot be a file\.Specified adapter <.+> dose not exist\./)
})

it('adapter not exist', function() {
_handleAdapter({
runner: runnerPath,
adapter: adapterPath
adapter: adapterPath,
proxy: true
})

expect(logCache).to.match(/Specified adapter <.+> dose not exist\./)
})

it('adapter is not js file', function() {
fs.writeFileSync(invalidAdapterPath, '')
_handleAdapter({
runner: runnerPath,
adapter: invalidAdapterPath
})

expect(logCache).to.match(/Specified adapter <.+> is not a js file\./)

fs.unlinkSync(invalidAdapterPath)
})

it('adapter is valid', function() {
var cfg = {
runner: runnerPath,
Expand All @@ -320,7 +309,7 @@ describe('handle-cfg', function() {
})

it('not specified adapter', function() {
var cfg = {runner: runnerPath}
var cfg = {runner: runnerPath, proxy: true}
_handleAdapter(cfg)

expect(logCache).to.be('Not found adapter file, will decide automatically.')
Expand Down Expand Up @@ -351,16 +340,6 @@ describe('handle-cfg', function() {
})


it('_relative', function() {
var _relative = handleCfg.__get__('relative')

var dir = path.join('path', 'to','a')
var f = path.join('path', 'b.js')

expect(_relative(dir, f)).to.be('../../b.js')
})


afterEach(function(){
logCache = ''
})
Expand Down

0 comments on commit b372c4c

Please sign in to comment.