config.spec.ts 2.0 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
import { test }   from 'ava'
2 3

import Config from './config'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
4

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5
test('Config list vars', t => {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6 7 8
  t.truthy(Config.default   , 'should export default')
  t.truthy(Config.Config    , 'should export Config')

9 10
  t.true('head'     in Config, 'should exist `head` in Config')
  t.true('puppet'   in Config, 'should exist `puppet` in Config')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
11
  t.true('apihost'  in Config, 'should exist `apihost` in Config')
12 13 14
  t.true('port'     in Config, 'should exist `port` in Config')
  t.true('profile'  in Config, 'should exist `profile` in Config')
  t.true('token'    in Config, 'should exist `token` in Config')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
15

16 17 18 19 20
  t.truthy(Config.DEFAULT_PUPPET      , 'should export DEFAULT_PUPPET')
  t.truthy(Config.DEFAULT_PORT        , 'should export DEFAULT_PORT')
  t.truthy(Config.DEFAULT_PROFILE     , 'should export DEFAULT_PROFILE')
  t.truthy(Config.DEFAULT_HEAD        , 'should export DEFAULT_HEAD')
  t.truthy(Config.DEFAULT_PROTOCOL    , 'should export DEFAULT_PROTOCOL')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21
  t.truthy(Config.DEFAULT_APIHOST     , 'should export DEFAULT_APIHOST')
22
  t.truthy(Config.CMD_CHROMIUM        , 'should export CMD_CHROMIUM')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
23 24
})

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38
test('Config methods', t => {
  const OK_APIHOSTS = [
    'api.wechaty.io'
    , 'wechaty.io:8080'
  ]
  const ERR_APIHOSTS = [
    'https://api.wechaty.io'
    , 'wechaty.io/'
  ]
  OK_APIHOSTS.forEach(apihost => {
    t.notThrows(_ => {
      Config.validApiHost(apihost)
    })
  }, 'should not row for right apihost')
39
  ERR_APIHOSTS.forEach(apihost => {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
40 41 42 43 44 45
    t.throws(_ => {
      Config.validApiHost(apihost)
    })
  }, 'should throw for error apihost')

  t.true('isDocker' in Config, 'should identify docker env by `isDocker`')
46
})
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
47

48 49 50 51 52 53 54 55
test('Config puppetInstance', t => {
  let instance = Config.puppetInstance()
  t.falsy(instance, 'should empty initialy')
  t.truthy(Config.puppetInstance({}), 'should return instance in arg')
  t.truthy(Config.puppetInstance(), 'should return instance after set')
  t.falsy(Config.puppetInstance(null), 'should return null after set to null')
  t.falsy(instance, 'should empty after set to null')
})