From 46c6ca51cf1dbd4fc21122a06fb3523ba49bb463 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 19 Aug 2018 18:08:57 +0300 Subject: [PATCH] test(config) test/config -> server/config.spec --- {test/server => server}/config.fixture.json | 0 .../server/config.js => server/config.spec.js | 52 +++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) rename {test/server => server}/config.fixture.json (100%) rename test/server/config.js => server/config.spec.js (68%) diff --git a/test/server/config.fixture.json b/server/config.fixture.json similarity index 100% rename from test/server/config.fixture.json rename to server/config.fixture.json diff --git a/test/server/config.js b/server/config.spec.js similarity index 68% rename from test/server/config.js rename to server/config.spec.js index 12b0d577..bf5343b7 100644 --- a/test/server/config.js +++ b/server/config.spec.js @@ -8,62 +8,58 @@ const readjson = require('readjson'); const diff = require('sinon-called-with-diff'); const sinon = diff(require('sinon')); -const root = '../../'; -const dir = root + 'server/'; -const configPath = dir + 'config'; +const root = '../'; +const dir = './'; +const configPath = './config'; const config = require(configPath); const {_cryptoPass} = config; const {apiURL} = require(root + 'common/cloudfunc'); -const clean = require('clear-module'); const pathHomeConfig = path.join(os.homedir(), '.cloudcmd.json'); -const pathConfig = path.join(__dirname, '..', '..', 'json', 'config.json'); +const pathConfig = path.join(__dirname, '..', 'json', 'config.json'); + const fixture = require('./config.fixture'); - -function readConfig() { - return readjson.sync.try(pathHomeConfig) || require(pathConfig); -} - -const before = require('../before'); +const {connect} = require('../test/before'); test('config: manage', (t) => { t.equal(undefined, config(), 'should return "undefined"'); t.end(); }); -test('config: manage: get', (t) => { +test('config: manage: get', async (t) => { const editor = 'deepword'; - before({config: {editor}}, (port, after) => { - t.equal(config('editor'), editor, 'should get config'); - t.end(); - after(); + const {done} = await connect({ + config: {editor} }); + + done(); + + t.equal(config('editor'), editor, 'should get config'); + t.end(); }); -test('config: manage: get', (t) => { +test('config: manage: get', async (t) => { const editor = 'deepword'; const conf = { editor }; - before({config: conf}, (port, after) => { - config('editor', 'dword'); - t.equal('dword', config('editor'), 'should set config'); - t.end(); - after(); - }); + const {done} = await connect({config: conf}); + + config('editor', 'dword'); + done(); + + t.equal('dword', config('editor'), 'should set config'); + t.end(); }); test('config: manage: get: *', (t) => { - clean(configPath); - - const config = require(configPath); const data = config('*'); - const expected = readConfig(); + const keys = Object.keys(data); - t.deepEqual(data, expected, 'should return config data'); + t.ok(keys.length > 1, 'should return config data'); t.end(); });