UNPKG

3.87 kBJavaScriptView Raw
1import test from 'ava';
2
3import {preprocessArgs, parseConfigActions, parseConfig, collect} from './internals';
4
5test('preprocessArgs() with empty array', t => {
6 t.deepEqual(preprocessArgs(['node.exe', 'cli.js']), {
7 action: null,
8 args: [],
9 dockerProjectArgs: ['node.exe', 'cli.js']
10 });
11});
12
13test('preprocessArgs() with action only', t => {
14 const actual = preprocessArgs(['node.exe', 'cli.js', 'test2']);
15 const exp = {
16 action: 'test2',
17 args: [],
18 dockerProjectArgs: ['node.exe', 'cli.js']
19 };
20 t.deepEqual(actual, exp);
21});
22
23test('preprocessArgs() with pre arguments only', t => {
24 t.deepEqual(preprocessArgs(['node.exe', 'cli.js', '-f', 'bar', '--alice', 'bob']), {
25 action: null,
26 args: [],
27 dockerProjectArgs: ['node.exe', 'cli.js', '-f', 'bar', '--alice', 'bob']
28 });
29});
30
31test('preprocessArgs() with action and post arguments', t => {
32 const actual = preprocessArgs(['node.exe', 'cli.js', 'test4', '--foo', 'bar']);
33 t.deepEqual(actual, {
34 action: 'test4',
35 args: ['--foo', 'bar'],
36 dockerProjectArgs: ['node.exe', 'cli.js']
37 });
38});
39
40test('preprocessArgs() with action, pre and post arguments', t => {
41 const actual = preprocessArgs(['node.exe', 'cli.js', '--apple', '-a', 'b', 'test5', '--foo', 'bar', '-b']);
42 t.deepEqual(actual, {
43 action: 'test5',
44 args: ['--foo', 'bar', '-b'],
45 dockerProjectArgs: ['node.exe', 'cli.js', '--apple', '-a', 'b']
46 });
47});
48
49test('preprocessARgs() with real life case', t => {
50 const actual = preprocessArgs([
51 'C:\\Program Files\\nodejs\\node.exe',
52 'C:\\Users\\Wolf\\AppData\\Roaming\\npm\\node_modules\\@crazyfactory\\docker-project-cli\\bin\\index.js',
53 '-v',
54 'up',
55 '-d'
56 ]);
57
58 t.deepEqual(actual, {
59 action: 'up',
60 dockerProjectArgs: [
61 'C:\\Program Files\\nodejs\\node.exe',
62 'C:\\Users\\Wolf\\AppData\\Roaming\\npm\\node_modules\\@crazyfactory\\docker-project-cli\\bin\\index.js',
63 '-v'
64 ],
65 args: [
66 '-d'
67 ]
68 });
69});
70
71test('parseConfigActions()', t => {
72 const actual = parseConfigActions({
73 a: true,
74 b: './bar',
75 c: {
76 command: './pie'
77 }
78 });
79
80 const exp = {
81 a: {},
82 b: {
83 command: './bar'
84 },
85 c: {
86 command: './pie'
87 }
88 };
89
90 t.deepEqual(actual, exp);
91});
92
93test('parseConfig() with empty values', t => {
94 t.deepEqual(parseConfig(undefined), {});
95 t.deepEqual(parseConfig(null), null);
96 t.deepEqual(parseConfig({}), {});
97});
98
99test('parseConfig()', t => {
100 const config = {
101 command: 'alice',
102 file: 'bob',
103 service: 'charlie',
104 actions: {
105 foo: './bar'
106 },
107 env: {
108 apple: {
109 actions: {
110 a: true,
111 b: 'apple',
112 c: {},
113 d: {
114 command: 'pie'
115 }
116 }
117 }
118 }
119 };
120
121 const expected = {
122 command: 'alice',
123 file: 'bob',
124 service: 'charlie',
125 actions: {
126 foo: {
127 command: './bar'
128 }
129 },
130 env: {
131 apple: {
132 actions: {
133 a: {},
134 b: {
135 command: 'apple'
136 },
137 c: {},
138 d: {
139 command: 'pie'
140 }
141 }
142 }
143 }
144 };
145
146 t.deepEqual(parseConfig(config), expected);
147});
148
149test('collect()', t => {
150 const memo = [];
151
152 t.deepEqual(collect(1, memo), [1]);
153 t.deepEqual(collect('a', memo), [1, 'a']);
154});