Skip to content

Commit ba93a87

Browse files
committed
test(before) config, plugin -> options
1 parent 4d14071 commit ba93a87

5 files changed

Lines changed: 38 additions & 50 deletions

File tree

test/before.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ const {assign} = Object;
1414
const pathConfig = os.homedir() + '/.cloudcmd.json';
1515
const currentConfig = readjson.sync.try(pathConfig);
1616

17-
module.exports = (_config, _plugins, _fn) => {
18-
const {config, plugins, fn} = parse(_config, _plugins, _fn);
17+
module.exports = (options, fn = options) => {
18+
if (fn === options) {
19+
options = {};
20+
}
21+
22+
const {config, plugins} = options;
1923

2024
const app = express();
2125
const server = http.createServer(app);
@@ -46,25 +50,3 @@ function defaultConfig() {
4650
};
4751
}
4852

49-
function parse(config, plugins, fn) {
50-
if (typeof plugins === 'undefined')
51-
return {
52-
fn: config,
53-
config: undefined,
54-
plugins: undefined
55-
}
56-
57-
if (typeof fn === 'undefined')
58-
return {
59-
config,
60-
fn: plugins,
61-
plugins: undefined
62-
}
63-
64-
return {
65-
config,
66-
plugins,
67-
fn
68-
};
69-
}
70-

test/console.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('cloudcmd: console: enabled by default', (t) => {
2121
test('cloudcmd: console: enabled', (t) => {
2222
const config = {console: true};
2323

24-
before(config, (port, after) => {
24+
before({config}, (port, after) => {
2525
const socket = io(`http://localhost:${port}/console`)
2626

2727
socket.once('data', (data) => {
@@ -36,7 +36,7 @@ test('cloudcmd: console: enabled', (t) => {
3636
test('cloudcmd: console: disabled', (t) => {
3737
const config = {console: false};
3838

39-
before(config, (port, after) => {
39+
before({config}, (port, after) => {
4040
const socket = io(`http://localhost:${port}/console`);
4141

4242
socket.on('error', (error) => {

test/plugins.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ const get = promisify((url, fn) => {
1717
});
1818

1919
test('cloudcmd: plugins', (t) => {
20-
const config = {};
2120
const plugins = [];
2221

23-
before(config, plugins, (port, after) => {
22+
before({plugins}, (port, after) => {
2423
get(`http://localhost:${port}/plugins.js`)
2524
.then(warp(_pullout, 'string'))
2625
.then((content) => {
@@ -35,12 +34,11 @@ test('cloudcmd: plugins', (t) => {
3534
});
3635

3736
test('cloudcmd: plugins', (t) => {
38-
const config = {};
3937
const plugins = [
4038
__filename
4139
];
4240

43-
before(config, plugins, (port, after) => {
41+
before({plugins}, (port, after) => {
4442
get(`http://localhost:${port}/plugins.js`)
4543
.then(warp(_pullout, 'string'))
4644
.then((content) => {
@@ -56,7 +54,6 @@ test('cloudcmd: plugins', (t) => {
5654
});
5755

5856
test('cloudcmd: plugins: load error', (t) => {
59-
const config = {};
6057
const noEntry = __filename + Math.random();
6158
const plugins = [
6259
__filename,
@@ -65,7 +62,7 @@ test('cloudcmd: plugins: load error', (t) => {
6562

6663
const msg = `ENOENT: no such file or directory, open '${noEntry}'`;
6764

68-
before(config, plugins, (port, after) => {
65+
before({plugins}, (port, after) => {
6966
get(`http://localhost:${port}/plugins.js`)
7067
.then(warp(_pullout, 'string'))
7168
.then((content) => {

test/rest/config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ test('cloudcmd: rest: config: patch', (t) => {
5757
});
5858

5959
test('cloudcmd: rest: config: patch: no configDialog', (t) => {
60-
const configDialog = false;
60+
const config = {
61+
configDialog: false
62+
};
6163

62-
before({configDialog}, (port, after) => {
64+
before({config}, (port, after) => {
6365
const json = {
6466
ip: null
6567
};
@@ -78,9 +80,11 @@ test('cloudcmd: rest: config: patch: no configDialog', (t) => {
7880
});
7981

8082
test('cloudcmd: rest: config: patch: no configDialog: statusCode', (t) => {
81-
const configDialog = false;
83+
const config = {
84+
configDialog: false
85+
};
8286

83-
before({configDialog}, (port, after) => {
87+
before({config}, (port, after) => {
8488
const json = {
8589
ip: null
8690
};

test/rest/pack.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ const put = promisify((options, fn) => {
3333
});
3434

3535
test('cloudcmd: rest: pack: tar: get', (t) => {
36-
const options = {packer: 'tar'};
37-
before(options, (port, after) => {
36+
const config = {packer: 'tar'};
37+
38+
before({config}, (port, after) => {
3839
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
3940
.then((pack) => {
4041
const extract = tar.extract();
@@ -57,8 +58,9 @@ test('cloudcmd: rest: pack: tar: get', (t) => {
5758
});
5859

5960
test('cloudcmd: rest: pack: tar: put: file', (t) => {
60-
const options = {packer: 'tar'};
61-
before(options, (port, after) => {
61+
const config = {packer: 'tar'};
62+
63+
before({config}, (port, after) => {
6264
const name = String(Math.random()) + '.tar.gz';
6365
const options = getPackOptions(port, name);
6466

@@ -110,8 +112,9 @@ test('cloudcmd: rest: pack: tar: put: response', (t) => {
110112
});
111113

112114
test('cloudcmd: rest: pack: tar: put: error', (t) => {
113-
const options = {packer: 'tar'};
114-
before(options, (port, after) => {
115+
const config = {packer: 'tar'};
116+
117+
before({config}, (port, after) => {
115118
const options = getPackOptions(port, 'name', [
116119
'not found'
117120
]);
@@ -131,8 +134,8 @@ test('cloudcmd: rest: pack: tar: put: error', (t) => {
131134
});
132135

133136
test('cloudcmd: rest: pack: zip: get', (t) => {
134-
const options = {packer: 'zip'};
135-
before(options, (port, after) => {
137+
const config = {packer: 'zip'};
138+
before({config}, (port, after) => {
136139
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
137140
.then(_pullout)
138141
.then((pack) => {
@@ -147,8 +150,9 @@ test('cloudcmd: rest: pack: zip: get', (t) => {
147150
});
148151

149152
test('cloudcmd: rest: pack: zip: put: file', (t) => {
150-
const options = {packer: 'zip'};
151-
before(options, (port, after) => {
153+
const config = {packer: 'zip'};
154+
155+
before({config}, (port, after) => {
152156
const name = String(Math.random()) + '.zip';
153157
const options = getPackOptions(port, name);
154158

@@ -170,8 +174,9 @@ test('cloudcmd: rest: pack: zip: put: file', (t) => {
170174
});
171175

172176
test('cloudcmd: rest: pack: zip: put: response', (t) => {
173-
const options = {packer: 'zip'};
174-
before(options, (port, after) => {
177+
const config = {packer: 'zip'};
178+
179+
before({config}, (port, after) => {
175180
const name = String(Math.random()) + '.zip';
176181
const options = getPackOptions(port, name);
177182

@@ -192,8 +197,8 @@ test('cloudcmd: rest: pack: zip: put: response', (t) => {
192197
});
193198

194199
test('cloudcmd: rest: pack: zip: put: error', (t) => {
195-
const options = {packer: 'zip'};
196-
before(options, (port, after) => {
200+
const config = {packer: 'zip'};
201+
before({config}, (port, after) => {
197202
const options = getPackOptions(port, 'name', [
198203
'not found'
199204
]);

0 commit comments

Comments
 (0)